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#ifndef _METRICLIST_H 22#define _METRICLIST_H 23 24#include "dbe_structs.h" 25#include "vec.h" 26#include "enums.h" 27#include "Metric.h" 28#include "DerivedMetrics.h" 29#include <stdio.h> 30 31// 32// The MetricList class is used to manage a list of metrics 33 34class MetricList 35{ 36public: 37 38 MetricList (Vector<BaseMetric*> *base_metrics, MetricType type); 39 MetricList (MetricList *old); 40 MetricList (MetricType _mtype); 41 ~MetricList (); 42 43 // Methods concerning a list of metrics 44 // set metrics -- text, caller-callee, data, and index flavors 45 // flavor depends on mtype in the list 46 // returns NULL if OK, or an error string if not 47 // always returns NULL if fromRcFile is TRUE 48 char *set_metrics (const char *metric_cmd, bool fromRcFile, DerivedMetrics *derived_metrics); 49 50 // update the caller-callee or dataspace metrics to match normal metrics 51 // It is assumed that this->mtype is MET_CALL, MET_DATA, or MET_INDX and 52 // that metrics_list->mtype is MET_NORMAL 53 void set_metrics (MetricList *metrics_list); 54 55 // produce a string for the metrics from a vector 56 char *get_metrics (); 57 58 // set the sort metric for a list from a metric string 59 // returns NULL if OK, or an error string if not 60 char *set_sort (const char *metric_cmd, bool fromRcFile); 61 62 // set the sort metric for a list from the first visible index 63 void set_fallback_sort (); 64 65 // set the sort metric for a list from a visible index 66 void set_sort (int visindex, bool reverse); 67 68 char *get_sort_name (); // get the name of the sort metric from a vector 69 70 bool 71 get_sort_rev () // get the boolean reverse for the sort metric 72 { 73 return sort_reverse; 74 } 75 76 void 77 set_sort_rev (bool v) 78 { 79 sort_reverse = v; 80 } 81 82 int 83 get_sort_ref_index () 84 { 85 return sort_ref_index; 86 } 87 88 void 89 set_sort_ref_index (int ind) 90 { 91 sort_ref_index = ind; 92 } 93 94 bool set_sort_metric (char *metric_cmd, BaseMetric::SubType mst, bool reverse); 95 Metric *find_metric (char *cmd, BaseMetric::SubType st); 96 Metric *find_metric_by_name (char *cmd); 97 int get_listorder (char *cmd, BaseMetric::SubType st, const char *expr = NULL); 98 int get_listorder (Metric *mtr); 99 Metric *get_sort_metric (); // get the sort metric from a vector 100 char *get_sort_cmd (); // get the command name of the sort metric 101 102 MetricType 103 get_type () 104 { 105 return mtype; 106 } 107 108 Vector<Metric*> * 109 get_items () // get the vector of metrics from the list 110 { 111 return items; 112 } 113 114 Metric * 115 get (long i) 116 { 117 return items->get (i); 118 } 119 120 void 121 put (long i, Metric *m) 122 { 123 items->put (i, m); 124 } 125 126 void 127 append (Metric *m) 128 { 129 items->append (m); 130 } 131 132 long 133 size () 134 { 135 return items ? items->size () : 0; 136 } 137 138 Metric *append (BaseMetric *bm, BaseMetric::SubType st, int visbits); 139 140 // produce a list of all metrics from a vector 141 void print_metric_list (FILE *dis_file, char *leader, int debug); 142 143 // Add any and all matching metrics to the growing list 144 // return value is zero for OK, 1 for no match 145 int add_matching_dmetrics (Vector<BaseMetric*> *base_items, char *cmd, 146 BaseMetric::SubType *subtypes, int nsubtypes, 147 int dmetrics_vis, // literal translation of dmetrics +. etc. 148 bool fromRcFile); 149 150private: 151 // parse a metric specification substring, based on type of list 152 char *parse_metric_spec (char *cmd, BaseMetric::SubType *subtypes, 153 int *nsubtypes, int *dmetrics_visb, bool *isOK); 154 155 Vector<Metric*> *items; 156 MetricType mtype; 157 158 // the sort reference index 159 int sort_ref_index; 160 bool sort_reverse; 161}; 162 163#endif /* _METRICLIST_H */ 164