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 /* 22 * The DbeView class represents a window into the data managed by a DbeSession 23 * 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 27 * 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. 31 * 32 * A DbeView has three vectors of Metrics, one for functions, etc., 33 * a second for callers/callees, and a third for dataspace/memoryspace. 34 * 35 * A DbeView has a vector of FilterSet's (q.v.), one for each Experiment, 36 * used to determine how the data is filtered. 37 * 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. 43 */ 44 45 #ifndef _DBEVIEW_H 46 #define _DBEVIEW_H 47 48 #include <stdio.h> 49 #include "dbe_structs.h" 50 #include "vec.h" 51 #include "enums.h" 52 #include "util.h" 53 #include "DerivedMetrics.h" 54 #include "Histable.h" 55 #include "Hist_data.h" 56 #include "Settings.h" 57 #include "Metric.h" 58 #include "Table.h" 59 #include "PathTree.h" 60 61 class Application; 62 class DataView; 63 class Experiment; 64 class Expression; 65 class FilterSet; 66 class FilterNumeric; 67 class FilterExp; 68 class Function; 69 class Histable; 70 class MetricList; 71 class Module; 72 class Ovw_data; 73 class PathTree; 74 class DataSpace; 75 class MemorySpace; 76 class Stats_data; 77 class LoadObject; 78 class IOActivity; 79 class HeapActivity; 80 81 class DbeView 82 { 83 public: 84 DbeView (Application *app, Settings *_settings, int _vindex); 85 DbeView (DbeView *dbev, int _vindex); 86 ~DbeView (); 87 88 // Access functions for settings in the view 89 Settings * get_settings()90 get_settings () 91 { 92 return settings; 93 }; 94 95 // Get the list of tabs for this view 96 Vector<DispTab*> * get_TabList()97 get_TabList () 98 { 99 return settings->get_TabList (); 100 }; 101 102 // Get the list of memory tabs for this view 103 Vector<bool> * get_MemTabState()104 get_MemTabState () 105 { 106 return settings->get_MemTabState (); 107 }; 108 109 // Set the list of memory tabs for this view 110 void set_MemTabState(Vector<bool> * sel)111 set_MemTabState (Vector<bool>*sel) 112 { 113 settings->set_MemTabState (sel); 114 }; 115 116 // Get the list of index tabs for this view 117 Vector<bool> * get_IndxTabState()118 get_IndxTabState () 119 { 120 return settings->get_IndxTabState (); 121 }; 122 123 // Set the list of memory tabs for this view 124 void set_IndxTabState(Vector<bool> * sel)125 set_IndxTabState (Vector<bool>*sel) 126 { 127 settings->set_IndxTabState (sel); 128 }; 129 130 // controlling the name format 131 Cmd_status set_name_format(char * str)132 set_name_format (char *str) 133 { 134 return settings->set_name_format (str); 135 }; 136 137 void set_name_format(int fname_format,bool soname)138 set_name_format (int fname_format, bool soname) 139 { 140 settings->set_name_format (fname_format, soname); 141 }; 142 143 Histable::NameFormat get_name_format()144 get_name_format () 145 { 146 return settings->name_format; 147 } 148 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 152 153 VMode get_view_mode()154 get_view_mode () 155 { 156 return settings->get_view_mode (); 157 }; 158 159 // handling of descendant processes 160 Cmd_status set_en_desc (char *str, bool rc); // from a string 161 162 bool 163 check_en_desc (const char * lineage_name = NULL, const char *targname = NULL) 164 { 165 return settings->check_en_desc (lineage_name, targname); 166 }; 167 168 // Controlling the print line-limit 169 char * set_limit(char * str,bool rc)170 set_limit (char *str, bool rc) // from a string 171 { 172 settings->set_limit (str, rc); 173 return NULL; 174 }; 175 176 char * set_limit(int _limit)177 set_limit (int _limit) 178 { 179 settings->limit = _limit; 180 return NULL; 181 }; 182 183 int get_limit()184 get_limit () 185 { 186 return settings->limit; 187 }; 188 189 // Controlling the print format mode 190 char * set_printmode(char * str)191 set_printmode (char *str) 192 { 193 return settings->set_printmode (str); 194 }; 195 196 enum PrintMode get_printmode()197 get_printmode () 198 { 199 return settings->print_mode; 200 }; 201 202 char get_printdelimiter()203 get_printdelimiter () 204 { 205 return settings->print_delim; 206 }; 207 208 char * get_printmode_str()209 get_printmode_str () 210 { 211 return dbe_strdup (settings->str_printmode); 212 }; 213 214 // processing compiler commentary visibility bits, and other source annotation 215 // controls 216 Cmd_status proc_compcom(const char * cmd,bool isSrc,bool rc)217 proc_compcom (const char *cmd, bool isSrc, bool rc) 218 { 219 return settings->proc_compcom (cmd, isSrc, rc); 220 }; 221 222 char * get_str_scompcom()223 get_str_scompcom () 224 { 225 return settings->str_scompcom; 226 }; 227 228 char * get_str_dcompcom()229 get_str_dcompcom () 230 { 231 return settings->str_dcompcom; 232 }; 233 234 void set_src_compcom(int v)235 set_src_compcom (int v) 236 { 237 settings->src_compcom = v; 238 }; 239 240 int get_src_compcom()241 get_src_compcom () 242 { 243 return settings->src_compcom; 244 }; 245 246 void set_dis_compcom(int v)247 set_dis_compcom (int v) 248 { 249 settings->dis_compcom = v; 250 }; 251 252 int get_dis_compcom()253 get_dis_compcom () 254 { 255 return settings->dis_compcom; 256 }; 257 258 void set_cmpline_visible(bool vis)259 set_cmpline_visible (bool vis) 260 { 261 settings->set_cmpline_visible (vis); 262 } 263 264 int get_cmpline_visible()265 get_cmpline_visible () 266 { 267 return settings->cmpline_visible; 268 } 269 270 void set_funcline_visible(bool vis)271 set_funcline_visible (bool vis) 272 { 273 settings->set_funcline_visible (vis); 274 } 275 276 int get_funcline_visible()277 get_funcline_visible () 278 { 279 return settings->funcline_visible; 280 } 281 282 // controls for disassembly presentation 283 void set_src_visible(int vis)284 set_src_visible (int vis) 285 { 286 settings->set_src_visible (vis); 287 } 288 289 int get_src_visible()290 get_src_visible () 291 { 292 return settings->src_visible; 293 } 294 295 void set_srcmetric_visible(bool vis)296 set_srcmetric_visible (bool vis) 297 { 298 settings->set_srcmetric_visible (vis); 299 } 300 301 bool get_srcmetric_visible()302 get_srcmetric_visible () 303 { 304 return settings->srcmetric_visible; 305 } 306 307 void set_hex_visible(bool vis)308 set_hex_visible (bool vis) 309 { 310 settings->set_hex_visible (vis); 311 } 312 313 bool get_hex_visible()314 get_hex_visible () 315 { 316 return settings->hex_visible; 317 } 318 319 // processing and accessing the threshold settings 320 Cmd_status proc_thresh(char * cmd,bool isSrc,bool rc)321 proc_thresh (char *cmd, bool isSrc, bool rc) 322 { 323 return settings->proc_thresh (cmd, isSrc, rc); 324 }; 325 326 void set_thresh_src(int v)327 set_thresh_src (int v) 328 { 329 settings->threshold_src = v; 330 }; 331 332 int get_thresh_src()333 get_thresh_src () 334 { 335 return settings->threshold_src; 336 }; 337 338 void set_thresh_dis(int v)339 set_thresh_dis (int v) 340 { 341 settings->threshold_dis = v; 342 }; 343 344 int get_thresh_dis()345 get_thresh_dis () 346 { 347 return settings->threshold_dis; 348 }; 349 350 // controls for the Timeline mode, stack presentation 351 Cmd_status proc_tlmode(char * cmd,bool rc)352 proc_tlmode (char *cmd, bool rc) 353 { 354 return settings->proc_tlmode (cmd, rc); 355 }; 356 357 void set_tlmode(int _tlmode)358 set_tlmode (int _tlmode) 359 { 360 settings->tlmode = _tlmode; 361 }; 362 363 int get_tlmode()364 get_tlmode () 365 { 366 return settings->tlmode; 367 }; 368 369 void set_stack_align(int _stack_align)370 set_stack_align (int _stack_align) 371 { 372 settings->stack_align = _stack_align; 373 }; 374 375 int get_stack_align()376 get_stack_align () 377 { 378 return settings->stack_align; 379 }; 380 381 void set_stack_depth(int _stack_depth)382 set_stack_depth (int _stack_depth) 383 { 384 settings->stack_depth = _stack_depth; 385 }; 386 387 int get_stack_depth()388 get_stack_depth () 389 { 390 return settings->stack_depth; 391 }; 392 393 // Controls for which data is shown in Timeline 394 Cmd_status proc_tldata(char * cmd,bool rc)395 proc_tldata (char *cmd, bool rc) 396 { 397 return settings->proc_tldata (cmd, rc); 398 }; 399 400 void set_tldata(const char * tldata_cmd)401 set_tldata (const char* tldata_cmd) 402 { 403 settings->set_tldata (tldata_cmd); 404 }; 405 406 char* get_tldata()407 get_tldata () 408 { 409 return settings->get_tldata (); 410 }; 411 412 // settings controlling the expand/collapse of functions within each LoadObject 413 enum LibExpand get_lo_expand (int idx); 414 415 // set_lo_expand -- returns true if any change 416 bool set_lo_expand (int idx, enum LibExpand how); 417 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 (); 422 void reset (); 423 void reset_data (bool all); 424 425 char * get_error_msg()426 get_error_msg () 427 { 428 return error_msg; 429 }; 430 431 void clear_error_msg()432 clear_error_msg () 433 { 434 error_msg = NULL; 435 }; 436 437 char * get_warning_msg()438 get_warning_msg () 439 { 440 return warning_msg; 441 }; 442 443 void clear_warning_msg()444 clear_warning_msg () 445 { 446 warning_msg = NULL; 447 }; 448 char *get_processor_msg (int type); 449 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); 454 455 // Get the various metric master lists 456 MetricList *get_metric_ref (MetricType mtype); 457 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); 463 464 // Set the metric list, from a string specification 465 char *setMetrics (char *metricspec, bool fromRcFile); 466 467 // Set the sort metric, from its name 468 char *setSort (char *sortname, MetricType mtype, bool fromRcFile); 469 470 // Set the sort metric, from its visible index (Analyzer) 471 void setSort (int visindex, MetricType mtype, bool reverse); 472 473 // Resort any cached data, after changing sort 474 void resortData (MetricType mtype); 475 476 // Get the sort metric 477 char *getSort (MetricType mtype); 478 char *getSortCmd (MetricType mtype); 479 480 // reset the metrics 481 void reset_metrics (); 482 bool comparingExperiments (); 483 484 int get_compare_mode()485 get_compare_mode () 486 { 487 return settings->compare_mode; 488 }; 489 490 void reset_compare_mode(int mode)491 reset_compare_mode (int mode) 492 { 493 settings->compare_mode = mode; 494 }; 495 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); 500 501 // method for printing the instruction-frequency report 502 void ifreq (FILE *); 503 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); 511 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); 519 520 Expression * get_filter_expr()521 get_filter_expr () 522 { 523 return cur_filter_expr; 524 }; 525 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); 531 532 // Data processing objects 533 PathTree * get_path_tree()534 get_path_tree () 535 { 536 return ptree; 537 }; 538 539 DataSpace * get_data_space()540 get_data_space () 541 { 542 return dspace; 543 }; 544 545 IOActivity * get_io_space()546 get_io_space () 547 { 548 return iospace; 549 }; 550 551 HeapActivity * get_heap_space()552 get_heap_space () 553 { 554 return heapspace; 555 }; 556 Hist_data *get_data (MetricList *mlist, Histable *selObj, int type, int subtype); 557 int get_sel_ind (Histable *selObj, int type, int subtype); 558 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 567 ); 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 574 ); 575 CStack_data *get_cstack_data (MetricList *); 576 Stats_data *get_stats_data (int index); 577 Ovw_data *get_ovw_data (int index); 578 579 char *names_src[3]; // names for anno-src 580 char *names_dis[3]; // names for anno-dis 581 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); 589 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. 594 // 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); 600 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 618 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; 642 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 650 651 int vindex; // index of this view -- set by Analyzer 652 bool func_scope; 653 654 bool get_func_scope()655 get_func_scope () 656 { 657 return func_scope; 658 }; 659 660 void set_func_scope(bool scope_only)661 set_func_scope (bool scope_only) 662 { 663 func_scope = scope_only; 664 }; 665 666 // value set T if filtering is active, i.e., some packets were dropped 667 bool filter_active; 668 669 bool get_filter_active()670 get_filter_active () 671 { 672 return filter_active; 673 }; 674 675 DerivedMetrics * get_derived_metrics()676 get_derived_metrics () 677 { 678 return derived_metrics; 679 } 680 681 // Internal time (time means change) 682 int getPhaseIdx()683 getPhaseIdx () 684 { 685 return phaseIdx; 686 } 687 688 enum DbeView_status 689 { 690 DBEVIEW_SUCCESS = 0, 691 DBEVIEW_NO_DATA, 692 DBEVIEW_IO_ERROR, 693 DBEVIEW_BAD_DATA, 694 DBEVIEW_BAD_SYMBOL_DATA, 695 DBEVIEW_NO_SEL_OBJ 696 }; 697 static char *status_str (DbeView_status status); 698 699 bool isOmpDisMode()700 isOmpDisMode () 701 { 702 return ompDisMode; 703 } 704 705 void setOmpDisMode()706 setOmpDisMode () 707 { 708 ompDisMode = true; 709 } 710 711 void resetOmpDisMode()712 resetOmpDisMode () 713 { 714 ompDisMode = false; 715 } 716 717 bool isShowHideChanged()718 isShowHideChanged () 719 { 720 return showHideChanged; 721 } 722 723 void setShowHideChanged()724 setShowHideChanged () 725 { 726 showHideChanged = true; 727 } 728 729 void resetShowHideChanged()730 resetShowHideChanged () 731 { 732 showHideChanged = false; 733 } 734 735 bool isNewViewMode()736 isNewViewMode () 737 { 738 return newViewMode; 739 } 740 741 void setNewViewMode()742 setNewViewMode () 743 { 744 newViewMode = true; 745 } 746 747 void resetNewViewMode()748 resetNewViewMode () 749 { 750 newViewMode = false; 751 } 752 753 bool isFilterHideMode()754 isFilterHideMode () 755 { 756 return filterHideMode; 757 } 758 759 void setFilterHideMode()760 setFilterHideMode () 761 { 762 filterHideMode = true; 763 } 764 765 void resetFilterHideMode()766 resetFilterHideMode () 767 { 768 filterHideMode = false; 769 } 770 771 bool isShowAll()772 isShowAll () 773 { 774 return showAll; 775 } 776 777 void setShowAll()778 setShowAll () 779 { 780 showAll = true; 781 } 782 783 void resetShowAll()784 resetShowAll () 785 { 786 showAll = false; 787 } 788 void resetAndConstructShowHideStacks (); 789 790 private: 791 void init (); 792 Metric *get_compare_metric (Metric *mtr, int groupNum); 793 794 // methods controlling old-style filtering 795 FilterSet *get_filter_set (int n); 796 797 void purge_events (int n = -1); 798 799 char *cur_filter_str; 800 char *prev_filter_str; 801 Expression *cur_filter_expr; 802 bool noParFilter; 803 804 // MemorySpace's -- added when a request is made; for now, never dropped 805 Vector<MemorySpace*> *memspaces; 806 MemorySpace *addMemorySpace (int mtype); 807 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 815 816 DataSpace *dspace; 817 PathTree *ptree; 818 Vector<PathTree *> *indxspaces; 819 IOActivity *iospace; 820 HeapActivity *heapspace; 821 int phaseIdx; 822 bool ompDisMode; 823 bool filterHideMode; 824 bool showAll; 825 bool showHideChanged; 826 bool newViewMode; 827 828 // Filtered events 829 Vector<Vector<DataView*>*> *dataViews; //outer idx is exp_id, inner is data_id 830 Settings *settings; 831 832 Application *app; 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); 840 }; 841 842 #endif /* _DBEVIEW_H */ 843