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. */
27 #include "dbe_structs.h"
28 #include "Hist_data.h"
41 PathTree (DbeView *_dbev, int _indxtype = -1)
43 construct (_dbev, _indxtype, PATHTREE_MAIN);
48 static void make_deltas (int vtype, TValue *v1, TValue *v2);
49 static void make_ratios (int vtype, TValue *v1, TValue *v2);
57 Hist_data *compute_metrics (MetricList *, Histable::Type,
58 Hist_data::Mode, Vector<Histable*>*,
59 Histable*, Vector<Histable*>* sel_objs = NULL,
60 PtreeComputeOption flag = COMPUTEOPT_NONE);
61 // Get aggregated callstack data
62 CStack_data *get_cstack_data (MetricList *);
64 Vector<Histable*> *get_clr_instr (Histable *);
65 Vector<void*> *get_cle_instr (Histable *, Vector<Histable*>*&);
99 Vector<NodeIdx> *descendants;
104 static const int CHUNKSZ = 16384;
107 NODE_IDX (NodeIdx idx)
109 return idx ? &chunks[idx / CHUNKSZ][idx % CHUNKSZ] : NULL;
112 // queue for messages (statistics for pathtree processing)
113 Emsg *fetch_stats (void); // fetch the queue of comment messages
114 void delete_stats (void); // delete the queue of stats messages
115 Emsg *fetch_warnings (void); // fetch the queue of warnings messages
116 void delete_warnings (void); // delete the queue of warnings messages
119 get_func_nodeidx (Function * func)
121 return fn_map == NULL ? (NodeIdx) 0 : fn_map->get (func);
125 void dumpNodes (FILE *, Histable *);
127 // flame charts functions - get values from ftree_internal
128 int get_ftree_depth (); // Depth of tree
129 Vector<void*>* get_ftree_level (BaseMetric *bm, int dpth);
130 Vector<void*>* get_ftree_node_children (BaseMetric *bm, NodeIdx node_idx);
131 Vector<Function*>* get_ftree_funcs ();
132 Vector<Function*>* get_funcs (); // Unique functions in tree
138 MAX_DESC_HTABLE_SZ = 65535
141 typedef struct hash_node
144 struct hash_node *next;
147 int desc_htable_size;
148 int desc_htable_nelem;
149 hash_node_t **descHT;
165 PATHTREE_INTERNAL_OMP,
166 PATHTREE_INTERNAL_FUNCTREE
172 Expression *indx_expr;
174 Map<Function*, NodeIdx> *fn_map;
175 Map<uint64_t, NodeIdx> *pathMap;
176 Map<uint64_t, uint64_t> *hideMap;
191 Hist_data *hist_data;
198 PathTreeType pathTreeType;
199 PathTree *ptree_internal;
200 PathTree *ftree_internal; // function-based pathtree
201 bool ftree_needs_update;
202 Vector<Vector<NodeIdx>*> *depth_map; // for each depth level, list of nodes
206 PtreePhaseStatus reset ();
207 PtreePhaseStatus add_experiment (int);
208 PtreePhaseStatus process_packets (Experiment*, DataView*, int);
209 DataView *get_filtered_events (int exp_index, int data_type);
210 void construct (DbeView *_dbev, int _indxtype, PathTreeType _pathTreeType);
212 PathTree (DbeView *_dbev, int _indxtype, PathTreeType _pathTreeType)
214 construct (_dbev, _indxtype, _pathTreeType);
218 allocate_chunk (int **p, NodeIdx idx)
220 int *res = new int[CHUNKSZ];
221 for (int i = 0; i < CHUNKSZ; i++)
228 allocate_chunk (int64_t **p, NodeIdx idx)
230 int64_t *res = new int64_t[CHUNKSZ];
231 for (int i = 0; i < CHUNKSZ; i++)
238 allocate_chunk (Node **p, NodeIdx idx)
240 Node *res = new Node[CHUNKSZ];
241 for (int i = 0; i < CHUNKSZ; i++)
248 IS_MVAL_ZERO (Slot& slot, NodeIdx idx)
250 if (slot.vtype == VT_LLONG || slot.vtype == VT_ULLONG)
252 int64_t *tmp = slot.mvals64[idx / CHUNKSZ];
253 return tmp ? tmp[idx % CHUNKSZ] == 0 : true;
257 int *tmp = slot.mvals[idx / CHUNKSZ];
258 return tmp ? tmp[idx % CHUNKSZ] == 0 : true;
263 ASN_METRIC_VAL (TValue& v, Slot& slot, NodeIdx idx)
265 if (slot.vtype == VT_LLONG)
267 int64_t *tmp = slot.mvals64[idx / CHUNKSZ];
269 v.ll = tmp[idx % CHUNKSZ];
271 else if (slot.vtype == VT_ULLONG)
273 uint64_t *tmp = (uint64_t *) slot.mvals64[idx / CHUNKSZ];
275 v.ull = tmp[idx % CHUNKSZ];
279 int *tmp = slot.mvals[idx / CHUNKSZ];
281 v.i = tmp[idx % CHUNKSZ];
286 ADD_METRIC_VAL (TValue& v, Slot& slot, NodeIdx idx)
288 if (slot.vtype == VT_LLONG)
290 int64_t *tmp = slot.mvals64[idx / CHUNKSZ];
292 v.ll += tmp[idx % CHUNKSZ];
294 else if (slot.vtype == VT_ULLONG)
296 uint64_t *tmp = (uint64_t *) slot.mvals64[idx / CHUNKSZ];
298 v.ull += tmp[idx % CHUNKSZ];
302 int *tmp = slot.mvals[idx / CHUNKSZ];
303 if (tmp) v.i += tmp[idx % CHUNKSZ];
308 SUB_METRIC_VAL (TValue& v, Slot& slot, NodeIdx idx)
310 if (slot.vtype == VT_LLONG)
312 int64_t *tmp = slot.mvals64[idx / CHUNKSZ];
314 v.ll -= tmp[idx % CHUNKSZ];
316 else if (slot.vtype == VT_ULLONG)
318 uint64_t *tmp = (uint64_t *) slot.mvals64[idx / CHUNKSZ];
320 v.ull -= tmp[idx % CHUNKSZ];
324 int *tmp = slot.mvals[idx / CHUNKSZ];
326 v.i -= tmp[idx % CHUNKSZ];
331 INCREMENT_METRIC (Slot *slot, NodeIdx idx, int64_t val)
333 if (slot->vtype == VT_LLONG)
335 int64_t *tmp = slot->mvals64[idx / CHUNKSZ];
337 tmp = allocate_chunk (slot->mvals64, idx / CHUNKSZ);
338 tmp[idx % CHUNKSZ] += val;
340 else if (slot->vtype == VT_ULLONG)
342 uint64_t *tmp = (uint64_t *) slot->mvals64[idx / CHUNKSZ];
344 tmp = (uint64_t *) allocate_chunk (slot->mvals64, idx / CHUNKSZ);
345 tmp[idx % CHUNKSZ] += val;
349 int *tmp = slot->mvals[idx / CHUNKSZ];
351 tmp = allocate_chunk (slot->mvals, idx / CHUNKSZ);
352 tmp[idx % CHUNKSZ] += (int) val;
359 if (idx < 0 || idx >= nslots)
364 int allocate_slot (int id, ValueTag vtype);
365 void allocate_slots (Slot *slots, int nslots);
367 NodeIdx new_Node (NodeIdx, Histable*, bool);
368 NodeIdx find_path (Experiment*, DataView*, long);
369 NodeIdx find_desc_node (NodeIdx, Histable*, bool);
370 NodeIdx find_in_desc_htable (NodeIdx, Histable*, bool);
371 Histable *get_hist_obj (Node *, Histable* = NULL);
372 Histable *get_hist_func_obj (Node *);
373 Histable *get_compare_obj (Histable *obj);
374 void get_metrics (NodeIdx, int);
375 void get_metrics (Vector<Function*> *, Histable *);
376 void get_clr_metrics (Vector<Histable*>*, NodeIdx, int, int);
377 void get_clr_metrics (Vector<Histable*>*);
378 void get_cle_metrics (Vector<Histable*>*, NodeIdx, int, int, int);
379 void get_cle_metrics (Vector<Histable*>*, NodeIdx, int);
380 void get_cle_metrics (Vector<Histable*>*);
381 void get_self_metrics (Vector<Histable*>*, NodeIdx, bool, int);
382 void get_self_metrics (Vector<Histable*>*);
383 void get_self_metrics (Histable *, Vector<Function*> *funclist,
384 Vector<Histable*>* sel_objs = NULL);
385 void get_cstack_list (CStack_data *, NodeIdx, int);
387 // Generate PathTree based on Functions instead of Instructions // Used for flame chart
389 void ftree_build (PathTree *mstr);
390 void ftree_build (PathTree *mstr, NodeIdx mstr_node_idx, NodeIdx local_node_idx);
391 void depth_map_build ();
392 void depth_map_build (NodeIdx node_idx, int depth);
393 Vector<void*>* get_level (BaseMetric *bm, int dpth);
394 Vector<void*>* get_nodes (BaseMetric *bm, Vector<NodeIdx> *node_idxs);
395 Vector<void*>* get_node_children (BaseMetric *bm, NodeIdx node_idx);
396 bool ftree_debug_match_hist_data (Hist_data *data, Hist_data *data_tmp);
399 // Debugging functions
400 void print (FILE *, PathTree::Node*, int);
401 void printn (FILE *);
402 int dbg_nodes (PathTree::Node*);
405 #endif /* _PATH_TREE_H */