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. */
22 * The DbeView class represents a window into the data managed by a DbeSession
24 * A DbeView has a Settings class that determines the user preferences,
25 * instantiated initially as a copy of the one in the DbeSession
26 * that created it, or in the DbeView being cloned by the DbeSession
28 * A DbeView has a vector of Experiment pointers, matching the one in the
29 * DbeSession, and a vector of enable bits governing which of the
30 * Experiments are currently being used to process the data.
32 * A DbeView has three vectors of Metrics, one for functions, etc.,
33 * a second for callers/callees, and a third for dataspace/memoryspace.
35 * A DbeView has a vector of FilterSet's (q.v.), one for each Experiment,
36 * used to determine how the data is filtered.
38 * Each DbeView has its own instantiation of the objects representing
39 * the processed, filtered data. Currently these are a PathTree
40 * for computing text-based metrics, a DataSpace for computing
41 * data-based metrics, and a MemorySpace used for computing
42 * memory-object-based metrics.
49 #include "dbe_structs.h"
53 #include "DerivedMetrics.h"
55 #include "Hist_data.h"
84 DbeView (Application *app, Settings *_settings, int _vindex);
85 DbeView (DbeView *dbev, int _vindex);
88 // Access functions for settings in the view
95 // Get the list of tabs for this view
99 return settings->get_TabList ();
102 // Get the list of memory tabs for this view
106 return settings->get_MemTabState ();
109 // Set the list of memory tabs for this view
111 set_MemTabState (Vector<bool>*sel)
113 settings->set_MemTabState (sel);
116 // Get the list of index tabs for this view
120 return settings->get_IndxTabState ();
123 // Set the list of memory tabs for this view
125 set_IndxTabState (Vector<bool>*sel)
127 settings->set_IndxTabState (sel);
130 // controlling the name format
132 set_name_format (char *str)
134 return settings->set_name_format (str);
138 set_name_format (int fname_format, bool soname)
140 settings->set_name_format (fname_format, soname);
146 return settings->name_format;
149 // processing modes: view_mode
150 Cmd_status set_view_mode (char *str, bool fromRC); // from a string
151 void set_view_mode (VMode mode); // from the analyzer
156 return settings->get_view_mode ();
159 // handling of descendant processes
160 Cmd_status set_en_desc (char *str, bool rc); // from a string
163 check_en_desc (const char * lineage_name = NULL, const char *targname = NULL)
165 return settings->check_en_desc (lineage_name, targname);
168 // Controlling the print line-limit
170 set_limit (char *str, bool rc) // from a string
172 settings->set_limit (str, rc);
177 set_limit (int _limit)
179 settings->limit = _limit;
186 return settings->limit;
189 // Controlling the print format mode
191 set_printmode (char *str)
193 return settings->set_printmode (str);
199 return settings->print_mode;
203 get_printdelimiter ()
205 return settings->print_delim;
211 return dbe_strdup (settings->str_printmode);
214 // processing compiler commentary visibility bits, and other source annotation
217 proc_compcom (const char *cmd, bool isSrc, bool rc)
219 return settings->proc_compcom (cmd, isSrc, rc);
225 return settings->str_scompcom;
231 return settings->str_dcompcom;
235 set_src_compcom (int v)
237 settings->src_compcom = v;
243 return settings->src_compcom;
247 set_dis_compcom (int v)
249 settings->dis_compcom = v;
255 return settings->dis_compcom;
259 set_cmpline_visible (bool vis)
261 settings->set_cmpline_visible (vis);
265 get_cmpline_visible ()
267 return settings->cmpline_visible;
271 set_funcline_visible (bool vis)
273 settings->set_funcline_visible (vis);
277 get_funcline_visible ()
279 return settings->funcline_visible;
282 // controls for disassembly presentation
284 set_src_visible (int vis)
286 settings->set_src_visible (vis);
292 return settings->src_visible;
296 set_srcmetric_visible (bool vis)
298 settings->set_srcmetric_visible (vis);
302 get_srcmetric_visible ()
304 return settings->srcmetric_visible;
308 set_hex_visible (bool vis)
310 settings->set_hex_visible (vis);
316 return settings->hex_visible;
319 // processing and accessing the threshold settings
321 proc_thresh (char *cmd, bool isSrc, bool rc)
323 return settings->proc_thresh (cmd, isSrc, rc);
327 set_thresh_src (int v)
329 settings->threshold_src = v;
335 return settings->threshold_src;
339 set_thresh_dis (int v)
341 settings->threshold_dis = v;
347 return settings->threshold_dis;
350 // controls for the Timeline mode, stack presentation
352 proc_tlmode (char *cmd, bool rc)
354 return settings->proc_tlmode (cmd, rc);
358 set_tlmode (int _tlmode)
360 settings->tlmode = _tlmode;
366 return settings->tlmode;
370 set_stack_align (int _stack_align)
372 settings->stack_align = _stack_align;
378 return settings->stack_align;
382 set_stack_depth (int _stack_depth)
384 settings->stack_depth = _stack_depth;
390 return settings->stack_depth;
393 // Controls for which data is shown in Timeline
395 proc_tldata (char *cmd, bool rc)
397 return settings->proc_tldata (cmd, rc);
401 set_tldata (const char* tldata_cmd)
403 settings->set_tldata (tldata_cmd);
409 return settings->get_tldata ();
412 // settings controlling the expand/collapse of functions within each LoadObject
413 enum LibExpand get_lo_expand (int idx);
415 // set_lo_expand -- returns true if any change
416 bool set_lo_expand (int idx, enum LibExpand how);
418 // set_libexpand -- returns true if any change
419 bool set_libexpand (char *liblist, enum LibExpand flag);
420 void update_lo_expands ();
421 bool set_libdefaults ();
423 void reset_data (bool all);
448 char *get_processor_msg (int type);
450 // methods controlling the metric list
451 BaseMetric *register_metric_expr (BaseMetric::Type type, char *aux, char *expr_spec);
452 Vector<BaseMetric*> *get_all_reg_metrics ();
453 void reset_metric_list (MetricList *mlist, int cmp_mode);
455 // Get the various metric master lists
456 MetricList *get_metric_ref (MetricType mtype);
458 // Get the various current metric lists
459 MetricList *get_metric_list (int dsptype, int subtype);
460 MetricList *get_metric_list (MetricType mtype);
461 MetricList *get_metric_list (MetricType mtype, bool compare, int gr_num);
462 MetricList *get_compare_mlist (MetricList *met_list, int grInd);
464 // Set the metric list, from a string specification
465 char *setMetrics (char *metricspec, bool fromRcFile);
467 // Set the sort metric, from its name
468 char *setSort (char *sortname, MetricType mtype, bool fromRcFile);
470 // Set the sort metric, from its visible index (Analyzer)
471 void setSort (int visindex, MetricType mtype, bool reverse);
473 // Resort any cached data, after changing sort
474 void resortData (MetricType mtype);
476 // Get the sort metric
477 char *getSort (MetricType mtype);
478 char *getSortCmd (MetricType mtype);
481 void reset_metrics ();
482 bool comparingExperiments ();
487 return settings->compare_mode;
491 reset_compare_mode (int mode)
493 settings->compare_mode = mode;
496 void set_compare_mode (int mode); // modifies the global MET_* arrays
497 void add_compare_metrics (MetricList *mlist);
498 void remove_compare_metrics (MetricList *mlist);
499 Histable *get_compare_obj (Histable *obj);
501 // method for printing the instruction-frequency report
504 // methods controlling the experiment list
505 void add_experiment (int index, bool enabled);
506 void add_subexperiment (int index, bool enabled);
507 void add_experiment_epilogue ();
508 void drop_experiment (int index);
509 bool get_exp_enable (int n);
510 void set_exp_enable (int n, bool e);
512 // method for new-style filtering
513 char *set_filter (const char *filter_spec);
514 char *get_filter (void);
515 char *get_advanced_filter ();
516 void backtrack_filter ();
517 void update_advanced_filter ();
518 FilterExp *get_FilterExp (Experiment *exp);
523 return cur_filter_expr;
526 // methods controlling old-style filtering
527 Vector<FilterNumeric*> *get_all_filters (int nexp);
528 FilterNumeric *get_FilterNumeric (int nexp, int idx);
529 bool set_pattern (int n, Vector<char *> *pattern_str, bool *error);
530 bool set_pattern (int m, char *pattern);
532 // Data processing objects
556 Hist_data *get_data (MetricList *mlist, Histable *selObj, int type, int subtype);
557 int get_sel_ind (Histable *selObj, int type, int subtype);
559 // Return histogram data for the specified arguments.
560 Hist_data *get_hist_data (MetricList *mlist, Histable::Type type,
561 int subtype, // used for memory objects only
562 Hist_data::Mode mode,
563 Vector<Histable*> *objs = NULL,
564 Histable *context = NULL,
565 Vector<Histable*> *sel_objs = NULL,
566 PathTree::PtreeComputeOption flag = PathTree::COMPUTEOPT_NONE
568 Hist_data *get_hist_data (MetricList *mlist, Histable::Type type,
569 int subtype, // used for memory objects only
570 Hist_data::Mode mode, Histable *obj,
571 Histable *context = NULL,
572 Vector<Histable*> *sel_objs = NULL,
573 PathTree::PtreeComputeOption flag = PathTree::COMPUTEOPT_NONE
575 CStack_data *get_cstack_data (MetricList *);
576 Stats_data *get_stats_data (int index);
577 Ovw_data *get_ovw_data (int index);
579 char *names_src[3]; // names for anno-src
580 char *names_dis[3]; // names for anno-dis
582 // Get filtered packets. Ordering is NOT guaranteed to be
583 // stable between calls; DataView indexes are not persistent -
584 // use underlying DataDescriptor ids if you don't consume data right away.
585 // Parameters: idx==exp_id, data_id==kind==ProfData_type
586 DataView *get_filtered_events (int idx, int data_id);
587 DataView *get_filtered_events (int idx, int data_id,
588 const int sortprops[], int sortprop_count);
590 // SORT is not used for PathTree.
591 // PathTree reads data once and discards. It doesn't
592 // depend on the indices so sort can be performed w/o recomputing pathtree.
593 // Timeline is the primary consumer of sort(), however Races also need to sort.
595 // YM: I can't remember the context for the following note, but
596 // In case I need it when we refactor more TBR stuff, here it is:
597 // base metrics like USER_CPU are known,(but we should/should not?)
598 // explicitly set DATA_CLOCK as a property/attribute?
599 bool adjust_filter (Experiment *exp);
601 // Generated report data
602 Hist_data *func_data; // function list data
603 Hist_data *line_data; // hot line list data
604 Hist_data *pc_data; // hot PC list data
605 Hist_data *src_data; // annotated source data
606 Hist_data *dis_data; // annotated disasm data
607 Hist_data *fitem_data; // func item for callers/callees
608 Hist_data *callers; // callers data
609 Hist_data *callees; // callees data
610 Hist_data *dobj_data; // data object list data
611 Hist_data *dlay_data; // data layout data
612 Hist_data *iofile_data; // io data aggregated by file name
613 Hist_data *iovfd_data; // io data aggregated by virtual fd
614 Hist_data *iocs_data; // io data aggregated by call stack
615 Hist_data *heapcs_data; // heap data aggregated by call stack
616 Vector<Hist_data*> *indx_data; // index object data
617 Vector<int> *lobjectsNoJava; // List of indices into LoadObjects excluding java classes
619 // memory object data -- create MemorySpace, if needed
620 MemorySpace *getMemorySpace (int subtype);
621 char *get_mobj_name (int subtype);
622 void addIndexSpace (int type);
623 Hist_data *get_indxobj_data (int subtype);
624 void set_indxobj_sel (int subtype, int sel_ind);
625 Histable *get_indxobj_sel (int subtype);
626 void set_obj_sel_io (int type, long sel_ind);
627 Histable *set_sel_obj (Histable *obj);
628 Histable *get_sel_obj (Histable::Type type);
629 Histable *get_sel_obj_io (uint64_t id, Histable::Type type);
630 Histable *get_sel_obj_heap (uint64_t id);
631 Histable *sel_obj; // current selected obj
632 Histable *sel_dobj; // current selected data obj
633 Histable *sel_binctx; // current binary context
634 Vector<Histable*> *sel_idxobj; // selected index objects
635 char *error_msg; // error message
636 char *warning_msg; // warning message
637 Vector<int> *marks; // flagged as important for anno src/dis
638 Vector<int_pair_t> *marks2dsrc;
639 Vector<int_pair_t> *marks2dsrc_inc;
640 Vector<int_pair_t> *marks2ddis;
641 Vector<int_pair_t> *marks2ddis_inc;
643 void dump_nodes (FILE *); // dump out the pathtree nodes
644 void dump_profile (FILE *); // dump out the clock profiling events
645 void dump_sync (FILE *); // dump out the synctrace events
646 void dump_iotrace (FILE *); // dump out the IO trace events
647 void dump_hwc (FILE *); // dump out the HWC Profiling events
648 void dump_heap (FILE *); // dump out the heap trace events
649 void dump_gc_events (FILE *); // dump out the Java garbage collector events
651 int vindex; // index of this view -- set by Analyzer
661 set_func_scope (bool scope_only)
663 func_scope = scope_only;
666 // value set T if filtering is active, i.e., some packets were dropped
672 return filter_active;
676 get_derived_metrics ()
678 return derived_metrics;
681 // Internal time (time means change)
694 DBEVIEW_BAD_SYMBOL_DATA,
697 static char *status_str (DbeView_status status);
720 return showHideChanged;
724 setShowHideChanged ()
726 showHideChanged = true;
730 resetShowHideChanged ()
732 showHideChanged = false;
756 return filterHideMode;
762 filterHideMode = true;
766 resetFilterHideMode ()
768 filterHideMode = false;
788 void resetAndConstructShowHideStacks ();
792 Metric *get_compare_metric (Metric *mtr, int groupNum);
794 // methods controlling old-style filtering
795 FilterSet *get_filter_set (int n);
797 void purge_events (int n = -1);
799 char *cur_filter_str;
800 char *prev_filter_str;
801 Expression *cur_filter_expr;
804 // MemorySpace's -- added when a request is made; for now, never dropped
805 Vector<MemorySpace*> *memspaces;
806 MemorySpace *addMemorySpace (int mtype);
808 Vector<FilterSet*> *filters;
809 Vector<enum LibExpand> *lo_expands;
810 Vector<BaseMetric*> *reg_metrics; // vector of registered metrics
811 Vector<MetricList*> *metrics_lists; // metrics list of MET_NORMAL, MET_CALL...
812 // note: includes compare metrics
813 Vector<MetricList*> *metrics_ref_lists;
814 DerivedMetrics *derived_metrics; // vector of derived metrics
818 Vector<PathTree *> *indxspaces;
820 HeapActivity *heapspace;
825 bool showHideChanged;
829 Vector<Vector<DataView*>*> *dataViews; //outer idx is exp_id, inner is data_id
833 Function *convert_line_to_func (DbeLine *dbeLine);
834 DbeInstr *convert_line_to_instr (DbeLine *dbeLine);
835 DbeInstr *convert_func_to_instr (Function *func);
836 DbeInstr *lastSelInstr;
837 Function *lastSelFunc;
838 void constructShowHideStack (DataDescriptor* dDscr, Experiment *exp);
839 void resetAndConstructShowHideStack (Experiment *exp);
842 #endif /* _DBEVIEW_H */