(root)/
binutils-2.41/
gprofng/
src/
BaseMetric.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  #ifndef _BASEMETRIC_H
      22  #define _BASEMETRIC_H
      23  
      24  #include "dbe_structs.h"
      25  #include "hwcentry.h"
      26  #include "Table.h"
      27  
      28  // METRIC_*_PRECISION determine the least threshold value
      29  // for time measured metrics. Any event that counts for less
      30  // than 1sec/METRIC_PRECISION is discarded.
      31  #define METRIC_SIG_PRECISION    MICROSEC
      32  #define METRIC_HR_PRECISION     MICROSEC
      33  
      34  class Expression;
      35  class Definition;
      36  class Histable;
      37  template <class ITEM> class Vector;
      38  
      39  class BaseMetric
      40  {
      41  public:
      42    // sync enum changes with AnMetric.java
      43    enum Type
      44    { // Subtype==STATIC metrics:
      45      ONAME = 1,  //ONAME must be 1
      46      SIZES,
      47      ADDRESS,
      48      // Clock Profiling, Derived Metrics:
      49      CP_TOTAL,
      50      CP_TOTAL_CPU,
      51      // Clock profiling, Solaris Microstates (LMS_* defines)
      52      CP_LMS_USER,
      53      CP_LMS_SYSTEM,
      54      CP_LMS_TRAP,
      55      CP_LMS_TFAULT,
      56      CP_LMS_DFAULT,
      57      CP_LMS_KFAULT,
      58      CP_LMS_USER_LOCK,
      59      CP_LMS_SLEEP,
      60      CP_LMS_WAIT_CPU,
      61      CP_LMS_STOPPED,
      62      // Kernel clock profiling
      63      CP_KERNEL_CPU,
      64      // Sync Tracing
      65      SYNC_WAIT_TIME,
      66      SYNC_WAIT_COUNT,
      67      // HWC
      68      HWCNTR,
      69      // Heap Tracing:
      70      HEAP_ALLOC_CNT,
      71      HEAP_ALLOC_BYTES,
      72      HEAP_LEAK_CNT,
      73      HEAP_LEAK_BYTES,
      74      // I/O Tracing:
      75      IO_READ_BYTES,
      76      IO_READ_CNT,
      77      IO_READ_TIME,
      78      IO_WRITE_BYTES,
      79      IO_WRITE_CNT,
      80      IO_WRITE_TIME,
      81      IO_OTHER_CNT,
      82      IO_OTHER_TIME,
      83      IO_ERROR_CNT,
      84      IO_ERROR_TIME,
      85      // MPI Tracing:
      86      MPI_TIME,
      87      MPI_SEND,
      88      MPI_BYTES_SENT,
      89      MPI_RCV,
      90      MPI_BYTES_RCVD,
      91      MPI_OTHER,
      92      // OMP states:
      93      OMP_NONE,
      94      OMP_OVHD,
      95      OMP_WORK,
      96      OMP_IBAR,
      97      OMP_EBAR,
      98      OMP_WAIT,
      99      OMP_SERL,
     100      OMP_RDUC,
     101      OMP_LKWT,
     102      OMP_CTWT,
     103      OMP_ODWT,
     104      OMP_MSTR,
     105      OMP_SNGL,
     106      OMP_ORDD,
     107      OMP_MASTER_THREAD,
     108      // MPI states:
     109      MPI_WORK,
     110      MPI_WAIT,
     111      // Races and Deadlocks
     112      RACCESS,
     113      DEADLOCKS,
     114      // Derived Metrics
     115      DERIVED
     116    };
     117  
     118    // sync enum changes with AnMetric.java
     119    enum SubType
     120    {
     121      STATIC      = 1, // Type==SIZES, ADDRESS, ONAME
     122      EXCLUSIVE   = 2,
     123      INCLUSIVE   = 4,
     124      ATTRIBUTED  = 8,
     125      DATASPACE   = 16 // Can be accessed in dataspace views
     126    };
     127  
     128    BaseMetric (Type t);
     129    BaseMetric (Hwcentry *ctr, const char* _aux, const char* _cmdname,
     130  	      const char* _username, int v_styles); // depended bm
     131    BaseMetric (Hwcentry *ctr, const char* _aux, const char* _username,
     132  	      int v_styles, BaseMetric* _depended_bm = NULL); // master bm
     133    BaseMetric (const char *_cmd, const char *_username, Definition *def); // derived metrics
     134    BaseMetric (const BaseMetric& m);
     135    virtual ~BaseMetric ();
     136  
     137    int get_id ()                     { return id; }
     138    Type get_type ()                  { return type; }
     139    Hwcentry *get_hw_ctr ()           { return hw_ctr; }
     140    char *get_aux ()                  { return aux; }
     141    char *get_username ()             { return username; }
     142    char *get_cmd ()                  { return cmd; }
     143    int get_flavors ()                { return flavors; }
     144    int get_clock_unit ()             { return clock_unit; }
     145    long long get_precision ()        { return precision; }
     146    ValueTag get_vtype ()             { return valtype; }
     147    int get_value_styles ()           { return value_styles; }
     148    bool is_zeroThreshold ()          { return zeroThreshold; }
     149    ProfData_type get_packet_type ()  { return packet_type; }
     150    Expression *get_cond ()           { return cond; }
     151    Expression *get_val ()            { return val; }
     152    Expression *get_expr ()           { return expr; }
     153    char *get_expr_spec ()            { return expr_spec; }
     154    Definition *get_definition ()     { return definition; };
     155    BaseMetric *get_dependent_bm ()   { return dependent_bm; };
     156  
     157    bool
     158    comparable ()
     159    {
     160      return val_spec != NULL || type == DERIVED || type == SIZES || type == ADDRESS;
     161    }
     162  
     163    // setters..
     164    void set_default_visbits (SubType subtype, int _visbits);
     165    void set_id (int _id)         { id = _id; }   //TBR, if possible
     166    // For comparison, set which packets to eval:
     167    void set_expr_spec (char *_expr_spec);
     168    void set_cond_spec (char *_cond_spec);
     169    int get_default_visbits (SubType subtype);
     170    char *dump ();
     171    Histable *get_comparable_obj (Histable *obj);
     172    bool is_internal ();          // Invisible for users
     173  
     174    char *legend;                 // for comparison: add'l column text
     175  
     176  private:
     177    BaseMetric *dependent_bm;     // for HWCs only: a link to the timecvt metric
     178    Expression *cond;             // determines which packets to evaluate
     179    char *cond_spec;              // used to generate "cond"
     180    Expression *val;              // determines the numeric value for packet
     181    char *val_spec;               // used to generate "val"
     182    Expression *expr; // for comparison: an additional expression to determine
     183  		    // which packets to eval. Should be NULL otherwise.
     184    char *expr_spec;                  // used to generate "expr"
     185    int id;                           // unique id (assigned to last_id @ "new")
     186    Type type;                        // e.g. HWCNTR
     187    char *aux;                        // for HWCs only: Hwcentry ctr->name
     188    char *cmd;                        // the .rc metric command, e.g. "total"
     189    char *username;                   // e.g. "GTXT("Total Wait Time")"
     190    int flavors;                      // bitmask of SubType capabilities
     191    int value_styles;                 // bitmask of ValueType capabilities
     192    static const int NSUBTYPES = 2;   // STATIC/EXCLUSIVE, INCLUSIVE
     193    int default_visbits[NSUBTYPES];   // ValueType, e.g. VAL_VALUE|VAL_TIMEVAL
     194    ValueTag valtype;                 // e.g. VT_LLONG
     195    long long precision;              // e.g. METRIC_SIG_PRECISION, 1, etc.
     196    Hwcentry *hw_ctr;                 // HWC definition
     197    ProfData_type packet_type;        // e.g. DATA_HWC, or -1 for N/A
     198    bool zeroThreshold;               // deadlock stuff
     199    Presentation_clock_unit clock_unit;
     200  
     201    static int last_id;           // incremented by 1 w/ every "new". Not MT-safe
     202    Definition *definition;
     203  
     204    void hwc_init (Hwcentry *ctr, const char* _aux, const char* _cmdname, const char* _username, int v_styles);
     205    void init (Type t);
     206    char *get_basetype_name ();
     207    void specify ();
     208    void specify_metric (char *_cond_spec, char *_val_spec);
     209    void set_val_spec (char *_val_spec);
     210    void specify_mstate_metric (int st);
     211    void specify_ompstate_metric (int st);
     212    void specify_prof_metric (char *_cond_spec);
     213  };
     214  
     215  class Definition
     216  {
     217  public:
     218  
     219    enum opType
     220    {
     221      opNULL,
     222      opPrimitive,
     223      opDivide
     224    };
     225  
     226    Definition (opType _op);
     227    ~Definition ();
     228    static Definition *add_definition (char *_def);
     229    Vector<BaseMetric *> *get_dependencies ();
     230    long *get_map ();
     231    double eval (long *indexes, TValue *values);
     232  
     233    opType op;
     234    Definition *arg1;
     235    Definition *arg2;
     236    char *def;
     237  
     238  private:
     239    BaseMetric *bm;
     240    long *map;
     241    Vector<BaseMetric *> *dependencies;
     242    long index;
     243  };
     244  
     245  #endif  /* _BASEMETRIC_H */
     246