]> Git Repo - binutils.git/blob - gprofng/src/FilterSet.cc
Automatic date update in version.in
[binutils.git] / gprofng / src / FilterSet.cc
1 /* Copyright (C) 2021 Free Software Foundation, Inc.
2    Contributed by Oracle.
3
4    This file is part of GNU Binutils.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20
21 #include "config.h"
22 #include "Experiment.h"
23 #include "StringBuilder.h"
24 #include "FilterSet.h"
25 #include "Filter.h"
26 #include "i18n.h"
27
28 FilterSet::FilterSet (DbeView *_dbev, Experiment *_exp)
29 {
30   dbev = _dbev;
31   exp = _exp;
32   enbl = false;
33   dfilter = new Vector<FilterNumeric *>;
34   FilterNumeric *f;
35   f = new FilterNumeric (exp, "sample", GTXT ("Samples"));
36   f->prop_name = NTXT ("SAMPLE_MAP");
37   dfilter->append (f);
38   f = new FilterNumeric (exp, "thread", GTXT ("Threads"));
39   f->prop_name = NTXT ("THRID");
40   dfilter->append (f);
41   f = new FilterNumeric (exp, "LWP", GTXT ("LWPs"));
42   f->prop_name = NTXT ("LWPID");
43   dfilter->append (f);
44   f = new FilterNumeric (exp, "cpu", GTXT ("CPUs"));
45   f->prop_name = NTXT ("CPUID");
46   dfilter->append (f);
47   f = new FilterNumeric (exp, "gcevent", GTXT ("GCEvents"));
48   f->prop_name = NTXT ("GCEVENT_MAP");
49   dfilter->append (f); // must add new numeric below
50 }
51
52 FilterSet::~FilterSet ()
53 {
54   dfilter->destroy ();
55   delete dfilter;
56 }
57
58 FilterNumeric *
59 FilterSet::get_filter (int index)
60 {
61   if (index < dfilter->size () && index >= 0)
62     return dfilter->fetch (index);
63   return NULL;
64 }
65
66 char *
67 FilterSet::get_advanced_filter ()
68 {
69   StringBuilder sb;
70   bool filtrIsFalse = false;
71
72   if (get_enabled ())
73     {
74       Vector<FilterNumeric*> *filts = get_all_filters ();
75       if (filts == NULL)
76         return NULL;
77       for (int i = 0; i < filts->size (); i++)
78         {
79           FilterNumeric *f = filts->fetch (i);
80           if (f == NULL)
81             continue;
82           char *s = f->get_advanced_filter ();
83           if (s == NULL)
84             continue;
85           if (streq (s, NTXT ("0")))
86             {
87               free (s);
88               sb.setLength (0);
89               filtrIsFalse = true;
90               break;
91             }
92           if (sb.length () != 0)
93             sb.append (NTXT (" && "));
94           sb.append (s);
95           free (s);
96         }
97     }
98   else
99     filtrIsFalse = true;
100   if (filtrIsFalse)
101     sb.append ('0');
102   else if (sb.length () == 0)
103     return NULL;
104   return sb.toString ();
105 }
106
This page took 0.033256 seconds and 4 git commands to generate.