summaryrefslogtreecommitdiff
path: root/gprofng/src/MetricList.h
blob: b8486c1eed5fc7a8d026a98a373252872045e843 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* Copyright (C) 2021 Free Software Foundation, Inc.
   Contributed by Oracle.

   This file is part of GNU Binutils.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */

#ifndef _METRICLIST_H
#define _METRICLIST_H

#include "dbe_structs.h"
#include "vec.h"
#include "enums.h"
#include "Metric.h"
#include "DerivedMetrics.h"
#include <stdio.h>

//
// The MetricList class is used to manage a list of metrics

class MetricList
{
public:

  MetricList (Vector<BaseMetric*> *base_metrics, MetricType type);
  MetricList (MetricList *old);
  MetricList (MetricType _mtype);
  ~MetricList ();

  // Methods concerning a list of metrics
  // set metrics -- text, caller-callee, data, and index flavors
  //    flavor depends on mtype in the list
  //    returns NULL if OK, or an error string if not
  //    always returns NULL if fromRcFile is TRUE
  char *set_metrics (const char *metric_cmd, bool fromRcFile, DerivedMetrics *derived_metrics);

  // update the caller-callee or dataspace metrics to match normal metrics
  //	It is assumed that this->mtype is MET_CALL, MET_DATA, or MET_INDX and
  //	that metrics_list->mtype is MET_NORMAL
  void set_metrics (MetricList *metrics_list);

  // produce a string for the metrics from a vector
  char *get_metrics ();

  // set the sort metric for a list from a metric string
  //	returns NULL if OK, or an error string if not
  char *set_sort (const char *metric_cmd, bool fromRcFile);

  // set the sort metric for a list from the first visible index
  void set_fallback_sort ();

  // set the sort metric for a list from a visible index
  void set_sort (int visindex, bool reverse);

  char *get_sort_name ();   // get the name of the sort metric from a vector

  bool
  get_sort_rev ()   // get the boolean reverse for the sort metric
  {
    return sort_reverse;
  }

  void
  set_sort_rev (bool v)
  {
    sort_reverse = v;
  }

  int
  get_sort_ref_index ()
  {
    return sort_ref_index;
  }

  void
  set_sort_ref_index (int ind)
  {
    sort_ref_index = ind;
  }

  bool set_sort_metric (char *metric_cmd, BaseMetric::SubType mst, bool reverse);
  Metric *find_metric (char *cmd, BaseMetric::SubType st);
  Metric *find_metric_by_name (char *cmd);
  int get_listorder (char *cmd, BaseMetric::SubType st, const char *expr = NULL);
  int get_listorder (Metric *mtr);
  Metric *get_sort_metric ();       // get the sort metric from a vector
  char *get_sort_cmd ();            // get the command name of the sort metric

  MetricType
  get_type ()
  {
    return mtype;
  }

  Vector<Metric*> *
  get_items ()          // get the vector of metrics from the list
  {
    return items;
  }

  Metric *
  get (long i)
  {
    return items->get (i);
  }

  void
  put (long i, Metric *m)
  {
    items->put (i, m);
  }

  void
  append (Metric *m)
  {
    items->append (m);
  }

  long
  size ()
  {
    return items ? items->size () : 0;
  }

  Metric *append (BaseMetric *bm, BaseMetric::SubType st, int visbits);

  // produce a list of all metrics from a vector
  void print_metric_list (FILE *dis_file, char *leader, int debug);

  // Add any and all matching metrics to the growing list
  // return value is zero for OK, 1 for no match
  int add_matching_dmetrics (Vector<BaseMetric*> *base_items, char *cmd,
		    BaseMetric::SubType *subtypes, int nsubtypes,
		    int dmetrics_vis, // literal translation of dmetrics +. etc.
		     bool fromRcFile);

private:
  // parse a metric specification substring, based on type of list
  char *parse_metric_spec (char *cmd, BaseMetric::SubType *subtypes,
			   int *nsubtypes, int *dmetrics_visb, bool *isOK);

  Vector<Metric*> *items;
  MetricType mtype;

  // the sort reference index
  int sort_ref_index;
  bool sort_reverse;
};

#endif  /* _METRICLIST_H */