1 /* Copyright (C) 2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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)
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.
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. */
24 // A Hist_data object is used to obtain data used for constructing
25 // a histogram display.
27 #include <sys/types.h>
33 #include "dbe_structs.h"
35 #include "DerivedMetrics.h"
44 friend class er_print_histogram;
45 friend class PathTree;
46 friend class DataSpace;
47 friend class MemorySpace;
48 friend class IOActivity;
49 friend class HeapActivity;
51 // HistItem contains all the data about a single histogram item.
56 Histable *obj; // info on the object
57 int type; // annotated src/dis: type
58 TValue *value; // numeric values
92 Hist_data (MetricList *, Histable::Type, Mode, bool _viewowned = false);
94 virtual ~Hist_data ();
95 void dump (char *msg, FILE *f);
103 // Return the view ownership flag
110 // Return the total number of items
113 // Append a new HistItem for the specified Histable
114 HistItem *append_hist_item (Histable *obj);
115 void append_hist_item (HistItem *hi);
116 TValue *get_real_value (TValue *res, int met_index, int row);
117 TValue *get_value (TValue *res, int met_index, int row);
118 TValue *get_value (TValue *res, int met_index, HistItem *hi);
119 void print_row(StringBuilder *sb, int row, Metric::HistMetric *hist_metric,
121 void print_content (FILE *out_file, Metric::HistMetric *hist_metric, int limit);
122 int print_label (FILE *out_file, Metric::HistMetric *hist_metric, int space);
123 void update_total (Hist_data::HistItem *new_total);
124 void update_max (Metric::HistMetric *hm_tmp);
125 void update_legend_width (Metric::HistMetric *hm_tmp);
127 // Find an existing HistItem
128 HistItem *find_hist_item (Histable *obj);
131 void sort (long ind, bool reverse);
133 // resort the data, if metric sort or direction has changed
134 void resort (MetricList *mlist);
136 // compute minima and maxima
137 void compute_minmax (void);
139 // fetch() takes a hist item index and returns a ptr to the item
140 HistItem *fetch (long index);
149 get_maximums_inc (void)
167 get_hist_items (void)
173 set_status (Hist_status st)
179 get_metric_list (void)
184 Map<Histable*, int> *
187 return callsite_mark;
190 Metric::HistMetric *get_histmetrics ();
191 void set_threshold (double proportion);
192 bool above_threshold (HistItem *hi);
193 double get_percentage (double value, int mindex);
194 size_t value_maxlen (int mindex); // Return the drawing length
195 size_t time_len (TValue *value, int clock);
196 size_t time_maxlen (int mindex, int clock);
197 size_t name_len (HistItem *item);
198 size_t name_maxlen ();
199 HistItem *new_hist_item (Histable *obj, int itype, TValue *value);
200 HistItem *update_hist_item (HistItem *hi, TValue *value);
201 Vector<uint64_t> *get_object_indices (Vector<int> *selections);
205 Metric::HistMetric *hist_metrics;
206 Vector<HistItem*> *hist_items; // Actual histogram values
207 HashMap<Histable*, HistItem*>*hi_map; // map: Histable -> HistItem
208 Map<Histable*, int>*callsite_mark;
210 int nmetrics; // number of metrics
213 Sort_order sort_order;
216 bool rev_sort; // true if sort is reversed
219 HistItem *gprof_item; // used for gprof-style info
220 Histable *spontaneous;
222 // Private state variables
225 HistItem *maximum_inc;
229 // Perform the sort operation with this function
230 static int sort_compare_all (const void *a, const void *b, const void *arg);
231 static int sort_compare_dlayout (const void *a, const void *b, const void *arg);
232 static int sort_compare (HistItem *hi_1, HistItem *hi_2, Sort_type stype,
233 long ind, Hist_data *hdata);
235 // Allocate a new structure of dynamic size
236 HistItem *new_hist_item (Histable *obj);
238 // Flag indicating whether or not the Hist_data structure
239 // is owned by a DbeView, which has responsibility for
240 // deleting it, or not, in which case the last user deletes it.
241 // XXX this is very ugly, and arises from the inconsistent handling
242 // XXX of the Hist_data structure in various bits of code.
246 // This structure is destined to merge with Hist_data.
247 // We currently use it to present callstack data such as
248 // leak and allocation lists.
257 CStack_item (long n);
261 Vector<DbeInstr*> *stack;
262 TValue *value; // numeric values
265 Vector<CStack_item*> *cstack_items;
268 CStack_item *new_cstack_item ();
269 CStack_data (MetricList *);
274 return cstack_items->size ();
280 return cstack_items->fetch (i);
285 cstack_items->destroy ();
293 #endif /* _HIST_DATA_H */