(root)/
binutils-2.41/
gprofng/
src/
DbeSession.h
       1  /* Copyright (C) 2021-2023 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  /* The DbeSession class is instantiated by a DbeApplication, and contains
      22   *	all the data referring to a set of loaded experiments
      23   *
      24   *	It manages a set of tables for the Experiments, for the LoadObjects
      25   *	referenced in them, and for the other objects representing the
      26   *	elements in the program hierarchy that can have metrics associated
      27   *	with them.  It also has a master list of all the metrics available
      28   *	from all the loaded experiments.
      29   *
      30   *	It gets an instance of the Settings class, instantiated as a copy
      31   *	of the one in the DbeApplication that instantiated the DbeSession.
      32   *
      33   *	In addition, it manages a vector of DbeView's (q.v.); each DbeView
      34   *	represents a window into the DbeSession, and has its own set of
      35   *	Settings, and FilterSets for the Experiments, and is the access point
      36   *	for all processed data.
      37   */
      38  
      39  #ifndef _DBESESSION_H
      40  #define _DBESESSION_H
      41  
      42  
      43  #include <stdio.h>
      44  #include "dbe_structs.h"
      45  #include "vec.h"
      46  #include "Hist_data.h"
      47  #include "Histable.h"
      48  #include "BaseMetric.h"
      49  #include "BaseMetricTreeNode.h"
      50  #include "MemorySpace.h"
      51  #include "hwcentry.h"
      52  #include "dbe_types.h"
      53  #include "Settings.h"
      54  #include "HashMap.h"
      55  #include "Table.h"
      56  #include "Experiment.h"
      57  
      58  class DbeSession;
      59  class Experiment;
      60  class Expression;
      61  class ExpGroup;
      62  class Function;
      63  class JMethod;
      64  class Histable;
      65  class DbeView;
      66  class Module;
      67  class LoadObject;
      68  class DataObject;
      69  class SourceFile;
      70  class Settings;
      71  class StringBuilder;
      72  class UserLabel;
      73  class DbeFile;
      74  class DbeJarFile;
      75  class FileData;
      76  class HeapData;
      77  template <typename ITEM> class DbeSyncMap;
      78  template <class ITEM> class Vector;
      79  
      80  struct DispTab;
      81  struct List;
      82  struct Countable;
      83  class IndexObjType_t;
      84  
      85  typedef struct
      86  {
      87    char *path;
      88    Experiment *exp;
      89    DbeSession *ds;
      90    bool read_ahead;
      91  } exp_ctx;
      92  
      93  class DbeSession
      94  {
      95  public:
      96    DbeSession (Settings *_settings, bool _ipc_mode, bool _rdt_mode);
      97    ~DbeSession ();
      98  
      99    void reset ();
     100    void reset_data ();
     101  
     102    void
     103    set_interactive (bool _interactive)
     104    {
     105      interactive = _interactive;
     106    }
     107  
     108    bool
     109    is_interactive ()
     110    {
     111      return interactive;
     112    }
     113  
     114    bool is_datamode_available ();
     115    bool is_leaklist_available ();
     116    bool is_heapdata_available ();
     117    bool is_iodata_available ();
     118    bool is_racelist_available ();
     119    bool is_deadlocklist_available ();
     120    bool is_timeline_available ();
     121    bool is_ifreq_available ();
     122    bool is_omp_available ();
     123    bool has_java ();
     124    bool has_ompavail ();
     125  
     126    // XXX  get_clock should be removed, to support cpus with different clocks
     127    // XXX    means reworking time-convertible HWC code
     128    int get_clock (int id);
     129  
     130    // Access functions for DbeView's
     131    int createView ();
     132    int createView (int index, int cloneindex);
     133    DbeView *getView (int index);
     134    void dropView (int index);
     135  
     136    // Access functions controlling the experiment list
     137    Vector<char*> *get_group_or_expt (char *path); // load an experiment or group
     138  
     139    void open_experiment (Experiment *exp, char *path);
     140    Experiment *get_exp (int exp_ind);
     141    Vector<Vector<char*>*> *getExperimensGroups ();
     142    char *setExperimentsGroups (Vector<Vector<char*>*> *groups);
     143    char *drop_experiment (int exp_ind);
     144    int find_experiment (char *path);
     145  
     146    int
     147    nexps ()
     148    {
     149      return exps->size ();
     150    }
     151    int ngoodexps ();
     152  
     153    // Access functions controlling the DataObject list
     154    DataObject *createDataObject ();
     155    DataObject *createDataObject (DataObject *d, DataObject *p = NULL);
     156    DataObject *createMasterDataObject (DataObject *);
     157    Vector<DataObject*> *get_dobj_elements (DataObject *);
     158  
     159    DataObject *
     160    get_Total_DataObject ()
     161    {
     162      return d_total;
     163    };
     164  
     165    DataObject *
     166    get_Unknown_DataObject ()
     167    {
     168      return d_unknown;
     169    };
     170  
     171    DataObject *
     172    get_Scalars_DataObject ()
     173    {
     174      return d_scalars;
     175    };
     176  
     177    DataObject *find_dobj_by_name (char *dobj_name);
     178    DataObject *find_dobj_match (DataObject *dobj);
     179    DataObject *find_dobj_master (DataObject *dobj);
     180  
     181    int
     182    ndobjs ()
     183    {
     184      return dobjs->size ();
     185    }
     186  
     187    // check if no -xhwcprof should be ignored
     188    bool
     189    check_ignore_no_xhwcprof ()
     190    {
     191      return settings->get_ignore_no_xhwcprof ();
     192    };
     193  
     194    // check if FS warning should be comment, or real warning
     195    bool
     196    check_ignore_fs_warn ()
     197    {
     198      return settings->get_ignore_fs_warn ();
     199    };
     200  
     201    // Access functions controlling the LoadObject list
     202    DbeSyncMap<LoadObject> *loadObjMap;
     203    void append (LoadObject *lobj);
     204    LoadObject *createLoadObject (const char *nm, int64_t cksum = 0);
     205    LoadObject *createLoadObject (const char *nm, const char *runTimePath, DbeFile *df);
     206  
     207    Vector<LoadObject *> *
     208    get_LoadObjects ()
     209    {
     210      return lobjs;
     211    };
     212  
     213    void dobj_updateHT (DataObject *dobj);
     214    LoadObject *get_Total_LoadObject ();
     215    Vector<LoadObject*> *get_text_segments ();
     216    LoadObject *get_Unknown_LoadObject ();
     217    LoadObject *find_lobj_by_name (const char *lobj_name, int64_t cksum = 0);
     218  
     219    // Access functions controlling the Tab list
     220    Vector<DispTab*> *
     221    get_TabList ()
     222    {
     223      return settings->get_TabList ();
     224    };
     225  
     226    Vector<bool> *
     227    get_MemTabList ()
     228    {
     229      return settings->get_MemTabState ();
     230    };
     231  
     232    void mobj_define (MemObjType_t *);
     233  
     234    // Access functions controlling metrics
     235    BaseMetric *find_base_reg_metric (char *mcmd);
     236    Vector<BaseMetric*> *get_base_reg_metrics (); // excludes comparison (expr) variants
     237  
     238    Vector<BaseMetric*> *
     239    get_all_reg_metrics ()
     240    {
     241      return reg_metrics;     // includes comparison (expr) variants
     242    };
     243  
     244    BaseMetricTreeNode *get_reg_metrics_tree ();
     245    BaseMetric *register_metric_expr (BaseMetric::Type type, char *aux, char *expr_spec);
     246    BaseMetric *register_metric (BaseMetric::Type type);
     247    BaseMetric *register_metric (char *name, char *username, char *_def);
     248    BaseMetric *register_metric (Hwcentry *ctr, const char* cmdname, const char* username);
     249    void drop_metric (BaseMetric *);
     250    Module *createModule (LoadObject *lo, const char *nm);
     251    Module *createUnknownModule (LoadObject *lo);
     252    Module *createClassFile (char *className);
     253    DbeFile *getDbeFile (char *filename, int filetype);
     254    SourceFile *get_Unknown_Source ();
     255    SourceFile *createSourceFile (const char *path);
     256    Histable *createHistObject (Histable::Type);
     257    Function *createFunction ();
     258    Function *create_hide_function (LoadObject *lo);
     259    Function *get_Total_Function ();
     260    Function *get_Unknown_Function ();
     261    Function *get_JUnknown_Function ();
     262    Function *get_jvm_Function ();
     263    LoadObject *get_OMP_LoadObject ();
     264    Function *get_OMP_Function (int);
     265    JMethod *createJMethod ();
     266    Histable *createIndexObject (int idxtype, int64_t idx);
     267    Histable *createIndexObject (int idxtype, Histable *hobj);
     268  
     269    enum SpecialFunction
     270    {
     271      TruncatedStackFunc,
     272      FailedUnwindFunc,
     273      LastSpecialFunction
     274    };
     275    Function *getSpecialFunction (SpecialFunction);
     276  
     277    Histable *
     278    findObjectById (uint64_t _id)
     279    {
     280      long id = (long) _id;
     281      return (id >= 0 && id < objs->size ()) ? objs->fetch (id) : NULL;
     282    }
     283  
     284    Histable *findObjectById (Histable::Type type, int subtype, uint64_t id);
     285  
     286    // Other access functions
     287    bool find_obj (FILE *dis_file, FILE *inp_file, Histable *&obj, char *name,
     288  		 const char *sel, Histable::Type type, bool xdefault);
     289    int ask_which (FILE *dis_file, FILE *inp_file, Vector<Histable*> *list, char *name);
     290    LoadObject *map_NametoLoadObject (char *name, Vector<Histable*> *, int which);
     291    Module *map_NametoModule (char *name, Vector<Histable*> *, int which);
     292    Function *map_NametoFunction (char *, Vector<Histable*> *, const char *);
     293    DataObject *map_NametoDataObject (char *name, Vector<Histable*> *, int which);
     294    bool match_FName (char *name, Function *func);
     295  
     296    // Functions to convert a string to all matching Functions/DataObjects
     297    Vector<Function *> *match_func_names (const char *ustr, Histable::NameFormat nfmt);
     298    Vector<DataObject *> *match_dobj_names (char *);
     299  
     300    // Functions to convert a string to all matching JThreads
     301    Vector<JThread*> *match_java_threads (char *ustr, int matchParent,
     302  					Vector<uint64_t> * &grids,
     303  					Vector<uint64_t> * &expids);
     304    // Function to convert a string to all matching File names
     305    Vector<FileData *> *match_file_names (char *ustr, Histable::NameFormat nfmt);
     306  
     307    // Access functions concerning the search path
     308    Vector<char*> *
     309    get_search_path ()
     310    {
     311      return search_path;
     312    }
     313  
     314    Vector<DbeFile*>*get_classpath ();
     315    void set_search_path (Vector<char*> *path, bool reset);
     316    void set_search_path (char *lpath, bool reset);
     317    bool add_classpath (char *path);
     318    bool add_path (char *path);
     319    void set_pathmaps (Vector<pathmap_t*> *newPathMap);
     320    Vector<pathmap_t*> *get_pathmaps ();
     321  
     322    // functions to aid debugging
     323    void dump_stacks (FILE *);
     324    void dump_dataobjects (FILE *);
     325    void dump_segments (FILE *);
     326    void dump_map (FILE *);
     327  
     328    // Find dynamic property by name
     329    int registerPropertyName (const char *name);
     330    int getPropIdByName (const char *name);
     331    char* getPropName (int propId);
     332    char* getPropUName (int propId);
     333  
     334    Vector<UserLabel*> *userLabels; // List of er_labels
     335    UserLabel *findUserLabel (const char *name);
     336    DbeJarFile *get_JarFile (const char *name);
     337    void append (UserLabel *lbl);
     338    void append (SourceFile *sf);
     339    void append (Experiment *exp);
     340    void append (Hwcentry *exp);
     341    void set_need_refind ();
     342  
     343    // Find user defined object by name
     344    Expression *findObjDefByName (const char *);
     345    void get_filter_keywords (Vector<void*> *res);
     346  
     347    // Get the Settings class object
     348    Settings *
     349    get_settings ()
     350    {
     351      return settings;
     352    }
     353  
     354    // static members, used to define or fetch the various IndexSpaces
     355    Vector<void*> *getIndxObjDescriptions (void);
     356    Vector<void*> *getCustomIndxObjects (void);
     357    char *indxobj_define (const char *, char *, const char *, char *, char *);
     358    char *getIndexSpaceName (int index);
     359    char *getIndexSpaceDescr (int index);
     360    Expression *getIndexSpaceExpr (int index);
     361    char *getIndexSpaceExprStr (int index);
     362    int findIndexSpaceByName (const char *mname);
     363    void removeIndexSpaceByName (const char *mname);
     364    IndexObjType_t *getIndexSpace (int index);
     365    IndexObjType_t *findIndexSpace (const char *mname);
     366    Expression *ql_parse (const char *expr_spec);
     367    BaseMetric *find_metric (BaseMetric::Type type, const char *cmd, const char *expr_spec = NULL);
     368    static void dump (char *msg, Vector<Metric*> *mlist);
     369    static void dump (char *msg, Vector<BaseMetric*> *mlist);
     370    static Platform_t platform;               // Sparc, Intel
     371    Vector<ExpGroup *> *expGroups;
     372    HashMap<char*, LoadObject *> *comp_lobjs; // list of comparable LoadObjects
     373    HashMap<char*, DbeLine *> *comp_dbelines; // list of comparable DbeLines
     374    HashMap<char*, SourceFile*>*comp_sources; // list of comparable SourceFiles
     375    char *localized_SP_UNKNOWN_NAME;
     376  
     377    void
     378    set_lib_visibility_used ()
     379    {
     380      lib_visibility_used = true;
     381    }
     382  
     383    bool
     384    is_lib_visibility_used ()
     385    {
     386      return lib_visibility_used;
     387    }
     388  
     389    void unlink_tmp_files ();
     390    char *get_tmp_file_name (const char *nm, bool for_java);
     391  
     392    Vector<char *> *tmp_files;
     393    int status_ompavail;
     394    int archive_mode;
     395    bool ipc_mode;
     396    bool rdt_mode;
     397  
     398    // data and methods concerning the machine model
     399    //    methods are in source file MachineModel.cc
     400    Vector<char*> *list_mach_models (); // scan . and system lib directory for models
     401    char *load_mach_model (char *);
     402  
     403    char *
     404    get_mach_model ()
     405    {
     406      return dbe_strdup (mach_model_loaded);
     407    };
     408    Vector<SourceFile *> *get_sources ();
     409  
     410  private:
     411    void init ();
     412    void check_tab_avail ();
     413    bool add_path (char *path, Vector<char*> *pathes);
     414    Experiment *createExperiment ();
     415  
     416    // Divide the regular createExperiment into two parts -
     417    // Part1 creates just the Experiment data structure
     418    // Part2 updates related fields and vectors
     419    Experiment *createExperimentPart1 ();
     420    void createExperimentPart2 (Experiment *exp);
     421  
     422    Histable *findIndexObject (int idxtype, uint64_t idx);
     423    void append_mesgs (StringBuilder *sb, char *path, Experiment *exp);
     424    static void insert_metric (BaseMetric *mtr, Vector<BaseMetric*> *mlist);
     425    void update_metric_tree (BaseMetric *m);
     426  
     427    char *find_mach_model (char *);   // fine machine model file by name
     428    Vector<Experiment*> *exps;        // Master list of experiments
     429    Vector<Histable*> *objs;          // Master list of Functions,Modules,Segments
     430    Vector<DataObject*> *dobjs;       // Master list of DataObjects
     431    Vector<LoadObject*> *lobjs;       // Auxiliary list of LoadObjects
     432    Vector<Hwcentry*> *hwcentries;
     433    Vector<HashMap<uint64_t, Histable*>*> *idxobjs; // Master list of IndexObjects
     434    HashMap<char*, SourceFile*> *sourcesMap;  // list of Source which were not archived
     435    Vector<SourceFile*> *sources;         // list of SourceFiles
     436    Map<const char*, DbeJarFile*>*dbeJarFiles;
     437    Vector<Countable*> *metrics;
     438    Vector<BaseMetric*> *reg_metrics;     // Master list of BaseMetrics
     439    BaseMetricTreeNode* reg_metrics_tree; // Hierarchy of BaseMetrics
     440    Vector<char*> *search_path;
     441    Vector<char*> *classpath;
     442    Vector<DbeFile*> *classpath_df;
     443    Map<const char*, DbeFile*>*dbeFiles;
     444    Vector<DbeView*> *views;              // Master list of DbeViews
     445    bool interactive;                     // interactive mode
     446    bool lib_visibility_used;
     447    LoadObject *lo_total;                 // Total LoadObject
     448    Function *f_total;                    // Total function
     449    LoadObject *lo_unknown;               // Unknown LoadObject
     450    Function *f_unknown;                  // Unknown function
     451    SourceFile *sf_unknown;               // Unknown source file
     452    Function *f_jvm;                      // pseudo-function <JVM-System>
     453    Vector<Function*> *f_special;         // pseudo-functions
     454    Function *j_unknown;                  // pseudo-function <no Java callstack>
     455    LoadObject *lo_omp;                   // OMP LoadObject (libmtsk)
     456    Vector<Function*> *omp_functions;     // OMP-overhead, etc.
     457    DataObject *d_unknown;                // Unknown dataobject
     458    DataObject *d_scalars;                // Scalars dataobject
     459    DataObject *d_total;                  // Total dataobject
     460    List **dnameHTable;                   // DataObject name hash table
     461    Settings *settings;                   // setting/defaults structure
     462    Vector<IndexObjType_t*> *dyn_indxobj; // Index Object definitions
     463    int dyn_indxobj_indx;
     464    int dyn_indxobj_indx_fixed;
     465  
     466    void propNames_name_store (int propId, const char *propName);
     467    void propNames_name_store (int propId, const char *propName,
     468  			     const char *propUName, VType_type vType, int flags);
     469    char* propNames_name_fetch (int propId);
     470    Vector<PropDescr*> *propNames;
     471    char *defExpName;
     472    int user_exp_id_counter;
     473    char *mach_model_loaded;
     474    char *tmp_dir_name;
     475  };
     476  
     477  // For now, there's only one, so keep its pointer
     478  extern DbeSession *dbeSession;
     479  
     480  extern Vector<char *> *split_str (char *str, char delimiter);
     481  #endif  /* _DBESESSION_H */