The Gaudi Framework  master (37c0b60a)
PerfMonAuditor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include <GaudiKernel/Auditor.h>
12 #include <GaudiKernel/HashMap.h>
15 #include <GaudiKernel/IToolSvc.h>
16 #include <GaudiKernel/MsgStream.h>
17 #include <GaudiKernel/VectorMap.h>
18 
19 /*BEGIN: perfmon*/
20 #include <cstring>
21 #include <fstream>
22 #include <iostream>
23 #include <map>
24 #include <perfmon/pfmlib.h>
25 #include <perfmon/pfmlib_core.h>
27 #include <sstream>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 #include <perfmon/perfmon.h>
34 
36 
38 
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <getopt.h>
42 #include <signal.h>
43 #include <stdarg.h>
44 #include <stdint.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <sys/mman.h>
49 #include <sys/ptrace.h>
50 #include <sys/resource.h>
51 #include <sys/time.h>
52 #include <sys/types.h>
53 #include <sys/wait.h>
54 #include <time.h>
55 #include <unistd.h>
56 #include <zlib.h>
57 
58 #include "IgHook_IgHookTrace.h"
59 #include <algorithm>
60 #include <cmath>
61 #include <list>
62 #include <stack>
63 #include <sys/stat.h>
64 
65 // dlopen (link with -ldl)
66 #include <dlfcn.h>
67 
68 #define MAX_EVT_NAME_LEN 256
69 #define NUM_PMCS PFMLIB_MAX_PMCS
70 #define NUM_PMDS PFMLIB_MAX_PMDS
71 #define FMT_NAME PFM_DFL_SMPL_NAME
72 #define BPL ( sizeof( uint64_t ) << 3 )
73 #define LBPL 6
74 
75 #define SYM_NAME_MAX_LENGTH 10000
76 #define MAX_OUTPUT_FILENAME_LENGTH 1024
77 #define MAX_EVENT_NAME_LENGTH 500
78 #define MAX_PREFIX_NAME_LENGTH 1024
79 #define FILENAME_MAX_LENGTH 1024
80 
81 #define MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS 4
82 
83 #define cpuid( func, ax, bx, cx, dx ) \
84  __asm__ __volatile__( "cpuid" : "=a"( ax ), "=b"( bx ), "=c"( cx ), "=d"( dx ) : "a"( func ) );
85 
86 static pfarg_pmd_t pd_smpl[NUM_PMDS];
87 static uint64_t collected_samples, collected_partial;
88 static int ctx_fd;
89 static pfm_dfl_smpl_hdr_t* hdr;
90 static uint64_t ovfl_count;
91 static size_t entry_size;
92 static unsigned int num_smpl_pmds;
94  samples( MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS ); // a map of modules each containing numbers of samples of their
95  // addresses
97  results( MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS ); // a map of modules and their result values across multiple events
98 static uint64_t last_overflow;
99 static uint64_t last_count;
101 
103 /*END: perfmon*/
104 
105 namespace {
107  template <typename T>
108  inline T function_cast( void* p ) {
109  union {
110  void* object;
111  T function;
112  } caster;
113  caster.object = p;
114  return caster.function;
115  }
116  class PFMon {
117  public:
118  bool loaded;
119  typedef void ( *pfm_stop_t )( int );
120  pfm_stop_t pfm_stop{ nullptr };
121  typedef void ( *pfm_self_stop_t )( int );
122  pfm_self_stop_t pfm_self_stop{ nullptr };
123  typedef os_err_t ( *pfm_restart_t )( int );
124  pfm_restart_t pfm_restart{ nullptr };
125  typedef int ( *pfm_read_pmds_t )( int, pfarg_pmd_t*, int );
126  pfm_read_pmds_t pfm_read_pmds{ nullptr };
127  typedef pfm_err_t ( *pfm_initialize_t )();
128  pfm_initialize_t pfm_initialize{ nullptr };
129  typedef pfm_err_t ( *pfm_find_full_event_t )( const char*, pfmlib_event_t* );
130  pfm_find_full_event_t pfm_find_full_event{ nullptr };
131  typedef pfm_err_t ( *pfm_dispatch_events_t )( pfmlib_input_param_t*, void*, pfmlib_output_param_t*, void* );
132  pfm_dispatch_events_t pfm_dispatch_events{ nullptr };
133  typedef os_err_t ( *pfm_create_context_t )( pfarg_ctx_t*, char*, void*, size_t );
134  pfm_create_context_t pfm_create_context{ nullptr };
135  typedef os_err_t ( *pfm_write_pmcs_t )( int, pfarg_pmc_t*, int );
136  pfm_write_pmcs_t pfm_write_pmcs{ nullptr };
137  typedef os_err_t ( *pfm_write_pmds_t )( int, pfarg_pmd_t*, int );
138  pfm_write_pmds_t pfm_write_pmds{ nullptr };
139  typedef os_err_t ( *pfm_load_context_t )( int, pfarg_load_t* );
140  pfm_load_context_t pfm_load_context{ nullptr };
141  typedef os_err_t ( *pfm_start_t )( int fd, pfarg_start_t* );
142  pfm_start_t pfm_start{ nullptr };
143  typedef char* ( *pfm_strerror_t )( int );
144  pfm_strerror_t pfm_strerror{ nullptr };
145  typedef pfm_err_t ( *pfm_set_options_t )( pfmlib_options_t* );
146  pfm_set_options_t pfm_set_options{ nullptr };
147  typedef pfm_err_t ( *pfm_get_num_counters_t )( unsigned int* );
148  pfm_get_num_counters_t pfm_get_num_counters{ nullptr };
149  static PFMon& instance() { return s_instance; }
150 
151  private:
152  // static void failure() { throw 1; }
153 
154  void* handle;
155 
156  PFMon() {
157  handle = dlopen( "libpfm.so", RTLD_NOW );
158  if ( handle ) {
159  loaded = true;
160  } else {
161  loaded = false;
162  }
163  if ( loaded ) {
164  pfm_start = function_cast<pfm_start_t>( dlsym( handle, "pfm_start" ) );
165  pfm_stop = function_cast<pfm_stop_t>( dlsym( handle, "pfm_stop" ) );
166  pfm_self_stop = function_cast<pfm_self_stop_t>( dlsym( handle, "pfm_stop" ) ); // it's the same
167  pfm_restart = function_cast<pfm_restart_t>( dlsym( handle, "pfm_restart" ) );
168  pfm_read_pmds = function_cast<pfm_read_pmds_t>( dlsym( handle, "pfm_read_pmds" ) );
169  pfm_initialize = function_cast<pfm_initialize_t>( dlsym( handle, "pfm_initialize" ) );
170  pfm_find_full_event = function_cast<pfm_find_full_event_t>( dlsym( handle, "pfm_find_full_event" ) );
171  pfm_dispatch_events = function_cast<pfm_dispatch_events_t>( dlsym( handle, "pfm_dispatch_events" ) );
172  pfm_create_context = function_cast<pfm_create_context_t>( dlsym( handle, "pfm_create_context" ) );
173  pfm_write_pmcs = function_cast<pfm_write_pmcs_t>( dlsym( handle, "pfm_write_pmcs" ) );
174  pfm_write_pmds = function_cast<pfm_write_pmds_t>( dlsym( handle, "pfm_write_pmds" ) );
175  pfm_load_context = function_cast<pfm_load_context_t>( dlsym( handle, "pfm_load_context" ) );
176  pfm_strerror = function_cast<pfm_strerror_t>( dlsym( handle, "pfm_strerror" ) );
177  pfm_set_options = function_cast<pfm_set_options_t>( dlsym( handle, "pfm_set_options" ) );
178  pfm_get_num_counters = function_cast<pfm_get_num_counters_t>( dlsym( handle, "pfm_get_num_counters" ) );
179  } else {
180  // pfm_start = pfm_stop = pfm_self_stop = pfm_restart = pfm_read_pmds = pfm_initialize = pfm_find_full_event =
181  // pfm_dispatch_events = pfm_create_context = pfm_write_pmcs = pfm_write_pmds = pfm_load_context = pfm_strerror
182  // = pfm_set_options = pfm_get_num_counters = failure;
183  }
184  }
185  ~PFMon() {
186  if ( handle ) dlclose( handle );
187  }
188 
189  PFMon( const PFMon& ) = delete;
190  PFMon& operator=( const PFMon& ) = delete;
191 
192  static PFMon s_instance;
193  };
194 
195  PFMon PFMon::s_instance;
196 } // namespace
197 
198 // ============================================================================
208 class PerfMonAuditor : virtual public Auditor {
209 public:
210  void before( StandardEventType evt, INamedInterface* alg ) override;
211  void after( StandardEventType evt, INamedInterface* alg, const StatusCode& sc ) override;
212  using Auditor::after;
213  using Auditor::before;
214 
215 private:
220 
221 public:
222  StatusCode initialize() override;
223  StatusCode finalize() override;
224  int is_nehalem() {
225 #ifdef __ICC
226 // Disable ICC remark #593: variable "x" was set but never used
227 # pragma warning( push )
228 # pragma warning( disable : 593 )
229 #endif
230  int a, b, c, d;
231  cpuid( 1, a, b, c, d );
232  int sse4_2_mask = 1 << 20;
233  if ( c & sse4_2_mask )
234  return 1;
235  else
236  return 0;
237 #ifdef __ICC
238 # pragma warning( pop )
239 #endif
240  }
241 
242 private:
243  PFMon& m_pfm;
244  /*
245  typedef void (*pfm_stop_t)(int);
246  pfm_stop_t pfm_stop;
247  typedef void (*pfm_self_stop_t)(int);
248  pfm_self_stop_t pfm_self_stop;
249 
250  typedef os_err_t (*pfm_restart_t)(int);
251  pfm_restart_t pfm_restart;
252 
253  //typedef int (*pfm_read_pmds_t)(int, pfarg_pmd_t*, int);
254  //pfm_read_pmds_t pfm_read_pmds;
255 
256  typedef pfm_err_t (*pfm_initialize_t)();
257  pfm_initialize_t pfm_initialize;
258  typedef pfm_err_t (*pfm_find_full_event_t)(const char *, pfmlib_event_t *);
259  pfm_find_full_event_t pfm_find_full_event;
260  typedef pfm_err_t (*pfm_dispatch_events_t)(pfmlib_input_param_t *, void *, pfmlib_output_param_t *, void *);
261  pfm_dispatch_events_t pfm_dispatch_events;
262  typedef os_err_t (*pfm_create_context_t)(pfarg_ctx_t *, char *, void *, size_t);
263  pfm_create_context_t pfm_create_context;
264  typedef os_err_t (*pfm_write_pmcs_t)(int, pfarg_pmc_t *, int);
265  pfm_write_pmcs_t pfm_write_pmcs;
266  typedef os_err_t (*pfm_write_pmds_t)(int, pfarg_pmd_t *, int);
267  pfm_write_pmds_t pfm_write_pmds;
268  typedef os_err_t (*pfm_load_context_t)(int, pfarg_load_t *);
269  pfm_load_context_t pfm_load_context;
270  typedef os_err_t (*pfm_start_t)(int fd, pfarg_start_t *);
271  pfm_start_t pfm_start;
272  typedef char* (*pfm_strerror_t)(int);
273  pfm_strerror_t pfm_strerror;
274  typedef pfm_err_t (*pfm_set_options_t)(pfmlib_options_t *);
275  pfm_set_options_t pfm_set_options;
276  typedef pfm_err_t (*pfm_get_num_counters_t)(unsigned int *);
277  pfm_get_num_counters_t pfm_get_num_counters;
278  */
279 
280 public:
282  : // standard constructor
283  Auditor( name, pSvc )
284  , m_pfm( PFMon::instance() )
285  , m_map()
286  , m_indent( 0 )
287  , m_inEvent( false ) {
289  declareProperty( "EVENT0", event_str[0] );
290  declareProperty( "EVENT1", event_str[1] );
291  declareProperty( "EVENT2", event_str[2] );
292  declareProperty( "EVENT3", event_str[3] );
293  declareProperty( "FAMILY", family );
294  declareProperty( "PREFIX", prefix );
295  declareProperty( "INV0", inv[0] );
296  declareProperty( "INV1", inv[1] );
297  declareProperty( "INV2", inv[2] );
298  declareProperty( "INV3", inv[3] );
299  declareProperty( "CMASK0", cmask[0] );
300  declareProperty( "CMASK1", cmask[1] );
301  declareProperty( "CMASK2", cmask[2] );
302  declareProperty( "CMASK3", cmask[3] );
303  declareProperty( "SP0", sp[0] );
304  declareProperty( "SP1", sp[1] );
305  declareProperty( "SP2", sp[2] );
306  declareProperty( "SP3", sp[3] );
307  declareProperty( "SAMPLE", sampling );
308  declareProperty( "START_AT_EVENT", start_at_event );
309  declareProperty( "IS_NEHALEM", is_nehalem_ret );
310 
312  /*
313  // loading functions from PFM library
314  void* handle = dlopen("libpfm.so", RTLD_NOW);
315  if (!handle) {
316  // error() << "Cannot open library: " << dlerror() << endmsg;
317  }
318  typedef void (*hello_t)();
319  hello_t hello = (hello_t) dlsym(handle, "hello");
320  if (!hello) {
321  // error() << "Cannot load symbol 'hello': " << dlerror() << endmsg;
322  dlclose(handle);
323  }
324 
325  pfm_start = (pfm_start_t) dlsym(handle, "pfm_start");
326  pfm_stop = (pfm_stop_t) dlsym(handle, "pfm_stop");
327  pfm_self_stop = (pfm_self_stop_t) dlsym(handle, "pfm_stop"); //it's the same
328  pfm_restart = (pfm_restart_t) dlsym(handle, "pfm_restart");
329  //pfm_read_pmds = (pfm_read_pmds_t) dlsym(handle, "pfm_read_pmds");
330  pfm_initialize = (pfm_initialize_t) dlsym(handle, "pfm_initialize");
331  pfm_find_full_event = (pfm_find_full_event_t) dlsym(handle, "pfm_find_full_event");
332  pfm_dispatch_events = (pfm_dispatch_events_t) dlsym(handle, "pfm_dispatch_events");
333  pfm_create_context = (pfm_create_context_t) dlsym(handle, "pfm_create_context");
334  pfm_write_pmcs = (pfm_write_pmcs_t) dlsym(handle, "pfm_write_pmcs");
335  pfm_write_pmds = (pfm_write_pmds_t) dlsym(handle, "pfm_write_pmds");
336  pfm_load_context = (pfm_load_context_t) dlsym(handle, "pfm_load_context");
337  pfm_strerror = (pfm_strerror_t) dlsym(handle, "pfm_strerror");
338  pfm_set_options = (pfm_set_options_t) dlsym(handle, "pfm_set_options");
339  pfm_get_num_counters = (pfm_get_num_counters_t) dlsym(handle, "pfm_get_num_counters");
340  // use it to do the calculation
341  // info() << "Calling hello..." << endmsg;
342  // hello();
343 
344  // close the library
345  // info() << "Closing library..." << endmsg;
346  dlclose(handle);
347  */
348 
350  }
351 
352  virtual ~PerfMonAuditor() {} // virtual destructor
353 
354 private:
355  PerfMonAuditor(); // the default constructor is disabled
356  PerfMonAuditor( const PerfMonAuditor& ); // copy constructor is disabled
357  PerfMonAuditor& operator=( const PerfMonAuditor& ); // assignement operator is disabled
358 
359 private:
362  int m_indent; // indentation level
363  bool m_inEvent; // "In event" flag
364 
365 private:
367 
374  int fd;
375  unsigned int i;
376  int ret{ 0 };
377  void startpm();
378  void pausepm();
379  void stoppm();
380  void finalizepm();
386  unsigned int ph_ev_count{ 0 };
389  unsigned int start_at_event;
393  bool nehalem;
394  bool westmere;
395  bool core;
396 
397  bool sampling;
399  int detect_unavail_pmcs( int fd, pfmlib_regmask_t* r_pmcs ) { return detect_unavail_pmu_regs( fd, r_pmcs, NULL ); }
400  void pfm_bv_set( uint64_t* bv, uint16_t rnum ) { bv[rnum >> LBPL] |= 1UL << ( rnum & ( BPL - 1 ) ); }
401  int pfm_bv_isset( uint64_t* bv, uint16_t rnum ) {
402  return bv[rnum >> LBPL] & ( 1UL << ( rnum & ( BPL - 1 ) ) ) ? 1 : 0;
403  }
404  void pfm_bv_copy( uint64_t* d, uint64_t* j, uint16_t n ) {
405  if ( n <= BPL )
406  *d = *j;
407  else { memcpy( d, j, ( n >> LBPL ) * sizeof( uint64_t ) ); }
408  }
409  static void process_smpl_buf( pfm_dfl_smpl_hdr_t* hdr, size_t entry_size );
410  static void sigio_handler( int, siginfo_t*, void* ); // dlopen ==>
411  // void sigio_handler(int, struct siginfo *, struct sigcontext *);
412  void start_smpl();
413  void stop_smpl();
414  void finalize_smpl();
417  void* buf_addr;
418  unsigned num_counters;
419  unsigned int max_pmd;
421 
422  int level;
423 
424  bool first_alg;
427 };
428 
430  memset( &ctx, 0, sizeof( ctx ) );
431  memset( &inp, 0, sizeof( inp ) );
432  memset( &outp, 0, sizeof( outp ) );
433  memset( pd, 0, sizeof( pd ) );
434  memset( pc, 0, sizeof( pc ) );
435  memset( &load_arg, 0, sizeof( load_arg ) );
436  memset( &params, 0, sizeof( params ) );
437  memset( &nhm_params, 0, sizeof( nhm_params ) );
438 
439  for ( int i = 0; i < used_counters_number; i++ ) {
440  ret = m_pfm.pfm_find_full_event( event_cstr[i], &inp.pfp_events[i] );
441  if ( ret != PFMLIB_SUCCESS ) {
442  error() << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
443  }
444  }
446  inp.pfp_event_count = 4;
447  for ( int i = 0; i < used_counters_number; i++ ) {
448  if ( inv[i] ) {
451  }
452  if ( cmask[i] > 0 ) {
453  ( params.pfp_core_counters[i] ).cnt_mask = cmask[i];
454  ( nhm_params.pfp_nhm_counters[i] ).cnt_mask = cmask[i];
455  }
456  }
457  if ( nehalem || westmere ) {
458  ret = m_pfm.pfm_dispatch_events( &inp, &nhm_params, &outp, NULL );
459  } else {
460  ret = m_pfm.pfm_dispatch_events( &inp, &params, &outp, NULL );
461  }
462  if ( ret != PFMLIB_SUCCESS ) {
463  error() << "ERROR: cannot dispatch events: " << m_pfm.pfm_strerror( ret ) << ". Aborting..." << endmsg;
464  }
465  for ( unsigned int i = 0; i < outp.pfp_pmc_count; i++ ) {
468  }
469  for ( unsigned int i = 0; i < outp.pfp_pmd_count; i++ ) {
471  pd[i].reg_value = 0;
472  }
473  fd = m_pfm.pfm_create_context( &ctx, NULL, 0, 0 );
474  if ( fd == -1 ) { error() << "ERROR: Context not created. Aborting..." << endmsg; }
475  if ( m_pfm.pfm_write_pmcs( fd, pc, outp.pfp_pmc_count ) == -1 ) {
476  error() << "ERROR: Could not write pmcs. Aborting..." << endmsg;
477  }
478  if ( m_pfm.pfm_write_pmds( fd, pd, outp.pfp_pmd_count ) == -1 ) {
479  error() << "ERROR: Could not write pmds. Aborting..." << endmsg;
480  }
481  load_arg.load_pid = getpid();
482  if ( m_pfm.pfm_load_context( fd, &load_arg ) == -1 ) {
483  error() << "ERROR: Could not load context. Aborting..." << endmsg;
484  // error() << "Could not read pmds" << endmsg;
485  }
486 
487  m_pfm.pfm_start( fd, NULL );
488 }
489 
490 // stoppm()
491 // const ModuleDescription& desc : description of the module that just finished its execution (we are only interested in
492 // its name)
493 // stops the counting calling pfm_stop() and stores the counting results into the "results" map
495  m_pfm.pfm_stop( fd );
496  if ( m_pfm.pfm_read_pmds( fd, pd, inp.pfp_event_count ) == -1 ) { error() << "Could not read pmds" << endmsg; }
497  for ( int i = 0; i < used_counters_number; i++ ) {
498  results[i][( alg_stack.top().first )->name()].push_back( alg_stack.top().second[i] + pd[i].reg_value );
499  }
500 
501  close( fd );
502 }
503 
505  m_pfm.pfm_stop( fd );
506  if ( m_pfm.pfm_read_pmds( fd, pd, inp.pfp_event_count ) == -1 ) { error() << "Could not read pmds" << endmsg; }
507 
508  for ( int i = 0; i < used_counters_number; i++ ) { alg_stack.top().second[i] += pd[i].reg_value; }
509 
510  close( fd );
511 }
512 
513 // finalizepm()
514 // called when all the countings of the current event are finished, it dumps the results
515 // into the output file corresponding to the event being counted
517  info() << "start of finalizepm ucn:" << used_counters_number << endmsg;
518  for ( int i = 0; i < used_counters_number; i++ ) {
520  filename += '_';
521  filename += event_cstr[i];
522 
523  for ( auto& c : filename )
524  if ( c == ':' ) c = '-';
525 
526  if ( inv[i] ) filename += "_INV_1";
527  if ( cmask[i] > 0 ) filename += "_CMASK_" + std::to_string( cmask[i] );
528  filename += ".txt";
529 
530  info() << "Filename:" << filename << endmsg;
531  FILE* outfile = fopen( filename.c_str(), "w" );
532  if ( nehalem ) {
533  fprintf( outfile, "NHM " );
534  } else if ( westmere ) {
535  fprintf( outfile, "WSM " );
536  } else if ( core ) {
537  fprintf( outfile, "CORE " );
538  }
539  fprintf( outfile, "%s %u %d %d\n", event_cstr[i], cmask[i], inv[i], sp[i] );
540 
541  for ( const auto& r : results[i] ) {
542  fprintf( outfile, "%s\n", r.first.c_str() );
543  for ( unsigned long int j : r.second ) { fprintf( outfile, "%lu\n", j ); }
544  }
545  fclose( outfile );
546  }
547 }
548 
550  if ( !m_pfm.loaded ) {
551  error() << "pfm library could not be loaded" << endmsg;
552  return StatusCode::FAILURE;
553  }
554 
555  info() << "Initializing..." << endmsg;
557  if ( sc.isFailure() ) { return sc; }
559  for ( int i = 0; i < MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS; i++ ) {
560  if ( event_str[i].length() > 0 ) used_counters_number++;
561  }
562  for ( int i = 0; i < MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS; i++ ) { strcpy( event_cstr[i], event_str[i].c_str() ); }
563  strcpy( prefix_cstr, prefix.c_str() );
564 
565  if ( m_pfm.pfm_initialize() != PFMLIB_SUCCESS ) { error() << "Cannot initialize perfmon!!" << endmsg; }
566  ph_ev_count = 0;
567  first_alg = true;
568  event_count_reached = false;
569  nehalem = false;
570  core = false;
571  westmere = false;
572  if ( family.compare( "CORE" ) == 0 )
573  core = true;
574  else if ( family.compare( "NEHALEM" ) == 0 )
575  nehalem = true;
576  else if ( family.compare( "WESTMERE" ) == 0 )
577  westmere = true;
578  else { error() << "ERROR: Unsupported processor family " << family << ". aborting..." << endmsg; }
579 
580  info() << "Initialized!" << endmsg;
581  return StatusCode::SUCCESS;
582 }
583 
584 // process_smpl_buf()
585 // pfm_dfl_smpl_hdr_t *hdr : pointer to header of the buffer containing addresses sampled during the sampling process
586 // size_t entry_size : size of each entry, used to navigate through the various entries
587 // called when the sampling buffer is full, saves the samples into memory ("samples" map)
588 void PerfMonAuditor::process_smpl_buf( pfm_dfl_smpl_hdr_t* hdr, size_t entry_size ) {
591  size_t pos, count;
592  uint64_t entry;
593  if ( hdr->hdr_overflows == last_overflow && hdr->hdr_count == last_count ) {
594  printf( "skipping identical set of samples...\n" );
595  return;
596  }
597  count = hdr->hdr_count;
598  ent = (pfm_dfl_smpl_entry_t*)( hdr + 1 );
599  pos = (unsigned long)ent;
600  entry = collected_samples;
601  while ( count-- ) {
602  // if(ent->ovfl_pmd>=0 && ent->ovfl_pmd<=3)
603  if ( ent->ovfl_pmd <= 3 ) {
604  ( ( samples[ent->ovfl_pmd] )[( alg_stack.top().first )->name()] )[(unsigned long)( ent->ip )]++;
605  }
606  pos += entry_size;
607  ent = (pfm_dfl_smpl_entry_t*)pos;
608  entry++;
609  }
610  collected_samples = entry;
611  last_overflow = hdr->hdr_overflows;
612  if ( last_count != hdr->hdr_count && ( last_count || last_overflow == 0 ) ) { collected_partial += hdr->hdr_count; }
613  last_count = hdr->hdr_count;
614  return;
615 }
616 
617 // sigio_handler()
618 // int n : signal number of the signal being delivered
619 // siginfo_t *info : pointer to a siginfo_t structure containing info about the signal
620 // signal handler used to catch sampling buffer overflows. When they occur it calls the process_smpl_buf() function
621 void PerfMonAuditor::sigio_handler( int /*n*/, siginfo_t* /*info*/, void* ) {
622  PFMon& pfm = PFMon::instance();
624  int fd = ctx_fd;
625  int r;
626  if ( fd != ctx_fd ) {
627  // error() << "ERROR: handler does not get valid file descriptor. Aborting..." << endmsg;
628  }
629  if ( pfm.pfm_read_pmds( fd, pd_smpl + 1, 1 ) == -1 ) {
630  // error() << "ERROR: pfm_read_pmds: " << strerror(errno) << ". Aborting..." << endmsg;
631  }
632  while ( true ) {
633  r = read( fd, &msg, sizeof( msg ) );
634  if ( r != sizeof( msg ) ) {
635  if ( r == -1 && errno == EINTR ) {
636  printf( "read interrupted, retrying\n" );
637  continue;
638  }
639  // error() << "ERROR: cannot read overflow message: " << strerror(errno) << ". Aborting..." << endmsg;
640  }
641  break;
642  }
643  switch ( msg.type ) {
644  case PFM_MSG_OVFL: // the sampling buffer is full
645  process_smpl_buf( hdr, entry_size );
646  ovfl_count++;
647  if ( pfm.pfm_restart( fd ) ) {
648  if ( errno != EBUSY ) {
649  // error() << "ERROR: pfm_restart error errno " << errno << ". Aborting..." << endmsg;
650  } else {
651  printf( "pfm_restart: task probably terminated \n" );
652  }
653  }
654  break;
655  default:
656  // error() << "ERROR: unknown message type " << msg.type << ". Aborting..." << endmsg;
657  break;
658  }
659 }
660 
661 // start_smpl()
662 // const ModuleDescription& desc : description of the module that is just starting its execution (we are only interested
663 // in its name)
664 // initializes all the necessary structures to start the sampling, calling pfm_self_start()
666  ovfl_count = 0;
667  num_smpl_pmds = 0;
668  last_overflow = ~0;
669  max_pmd = 0;
670  memset( &pfmlib_options, 0, sizeof( pfmlib_options ) );
673  m_pfm.pfm_set_options( &pfmlib_options );
674  ret = m_pfm.pfm_initialize();
675  if ( ret != PFMLIB_SUCCESS ) {
676  error() << "ERROR: Cannot initialize library: " << m_pfm.pfm_strerror( ret ) << ". Aborting..." << endmsg;
677  }
678  struct sigaction act;
679  memset( &act, 0, sizeof( act ) );
680  act.sa_sigaction = sigio_handler; // dlopen() ==>
681  // act.sa_handler = (sig_t)&sigio_handler;
682  sigaction( SIGIO, &act, 0 );
683  memset( &ctx, 0, sizeof( ctx ) );
684  memset( &buf_arg, 0, sizeof( buf_arg ) );
685  memset( &inp, 0, sizeof( inp ) );
686  memset( &outp, 0, sizeof( outp ) );
687  memset( pd_smpl, 0, sizeof( pd_smpl ) );
688  memset( pc, 0, sizeof( pc ) );
689  memset( &load_args, 0, sizeof( load_args ) );
690  m_pfm.pfm_get_num_counters( &num_counters );
691  memset( &params, 0, sizeof( params ) );
692  memset( &nhm_params, 0, sizeof( nhm_params ) );
693 
694  for ( int i = 0; i < used_counters_number; i++ ) {
695  ret = m_pfm.pfm_find_full_event( event_cstr[i], &inp.pfp_events[i] );
696  if ( ret != PFMLIB_SUCCESS ) {
697  error() << "ERROR: cannot find event: " << event_cstr[i] << ". Aborting..." << endmsg;
698  }
699  }
701  inp.pfp_event_count = 4;
702  for ( int i = 0; i < used_counters_number; i++ ) {
703  if ( inv[i] ) {
706  }
707  if ( cmask[i] > 0 ) {
708  ( params.pfp_core_counters[i] ).cnt_mask = cmask[i];
709  ( nhm_params.pfp_nhm_counters[i] ).cnt_mask = cmask[i];
710  }
711  }
712  if ( nehalem || westmere ) {
713  ret = m_pfm.pfm_dispatch_events( &inp, &nhm_params, &outp, NULL );
714  } else {
715  ret = m_pfm.pfm_dispatch_events( &inp, &params, &outp, NULL );
716  }
717  if ( ret != PFMLIB_SUCCESS ) {
718  error() << "ERROR: cannot configure events: " << m_pfm.pfm_strerror( ret ) << ". Aborting..." << endmsg;
719  }
720  for ( unsigned int i = 0; i < outp.pfp_pmc_count; i++ ) {
723  }
724  for ( unsigned int i = 0; i < outp.pfp_pmd_count; i++ ) {
725  pd_smpl[i].reg_num = outp.pfp_pmds[i].reg_num;
726  if ( i ) {
727  pfm_bv_set( pd_smpl[0].reg_smpl_pmds, pd_smpl[i].reg_num );
728  if ( pd_smpl[i].reg_num > max_pmd ) { max_pmd = pd_smpl[i].reg_num; }
729  num_smpl_pmds++;
730  }
731  }
732  for ( int i = 0; i < used_counters_number; i++ ) {
734  pfm_bv_copy( pd_smpl[i].reg_reset_pmds, pd_smpl[i].reg_smpl_pmds, max_pmd );
735  pd_smpl[i].reg_value = (uint64_t)( sp[i] * -1 );
736  pd_smpl[i].reg_short_reset = (uint64_t)( sp[i] * -1 );
737  pd_smpl[i].reg_long_reset = (uint64_t)( sp[i] * -1 );
738  pd_smpl[i].reg_random_seed = 5; // tocheck
739  pd_smpl[i].reg_random_mask = 0xff; // tocheck
740  }
741  entry_size = sizeof( pfm_dfl_smpl_entry_t ) + ( num_smpl_pmds << 3 );
742  ctx.ctx_flags = 0;
743  buf_arg.buf_size = 3 * getpagesize() + 512;
744  ctx_fd = m_pfm.pfm_create_context( &ctx, (char*)FMT_NAME, &buf_arg, sizeof( buf_arg ) );
745  if ( ctx_fd == -1 ) {
746  if ( errno == ENOSYS ) {
747  error() << "ERROR: Your kernel does not have performance monitoring support! Aborting..." << endmsg;
748  }
749  error() << "ERROR: Can't create PFM context " << strerror( errno ) << ". Aborting..." << endmsg;
750  }
751  buf_addr = mmap( NULL, buf_arg.buf_size, PROT_READ, MAP_PRIVATE, ctx_fd, 0 );
752  if ( buf_addr == MAP_FAILED ) {
753  error() << "ERROR: cannot mmap sampling buffer: " << strerror( errno ) << ". Aborting..." << endmsg;
754  }
756  if ( PFM_VERSION_MAJOR( hdr->hdr_version ) < 1 ) {
757  error() << "ERROR: invalid buffer format version. Aborting..." << endmsg;
758  }
759  if ( m_pfm.pfm_write_pmcs( ctx_fd, pc, outp.pfp_pmc_count ) ) {
760  error() << "ERROR: pfm_write_pmcs error errno " << strerror( errno ) << ". Aborting..." << endmsg;
761  }
762  if ( m_pfm.pfm_write_pmds( ctx_fd, pd_smpl, outp.pfp_pmd_count ) ) {
763  error() << "ERROR: pfm_write_pmds error errno " << strerror( errno ) << ". Aborting..." << endmsg;
764  }
765  load_args.load_pid = getpid();
766  if ( m_pfm.pfm_load_context( ctx_fd, &load_args ) ) {
767  error() << "ERROR: pfm_load_context error errno " << strerror( errno ) << ". Aborting..." << endmsg;
768  }
769  ret = fcntl( ctx_fd, F_SETFL, fcntl( ctx_fd, F_GETFL, 0 ) | O_ASYNC );
770  if ( ret == -1 ) { error() << "ERROR: cannot set ASYNC: " << strerror( errno ) << ". Aborting..." << endmsg; }
771  ret = fcntl( ctx_fd, F_SETOWN, getpid() );
772  if ( ret == -1 ) { error() << "ERROR: cannot setown: " << strerror( errno ) << ". Aborting..." << endmsg; }
773  // pfm_self_start(ctx_fd); ==>
774  m_pfm.pfm_start( ctx_fd, NULL );
775 }
776 
777 // stop_smpl()
778 // const ModuleDescription& desc : description of the module that just finished its execution (we are only interested in
779 // its name)
780 // stops the sampling and calls process_smpl_buf() one last time to process all the remaining samples
782  m_pfm.pfm_self_stop( ctx_fd );
783  process_smpl_buf( hdr, entry_size );
784  close( ctx_fd );
785  ret = munmap( hdr, buf_arg.buf_size );
786  if ( ret ) { error() << "Cannot unmap buffer: %s" << strerror( errno ) << endmsg; }
787  return;
788 }
789 
790 // finalize_smpl()
791 // processes the sampling results in order to find library and offset of each sampled address, using the symbol() and
792 // tosymbol() functions,
793 // and then dumps the new found information into gzipped output files, to be processed later
795  int err;
796  for ( int i = 0; i < used_counters_number; i++ ) {
798  filename += '_';
799  filename += event_cstr[i];
800 
801  for ( auto& c : filename )
802  if ( c == ':' ) c = '-';
803 
804  if ( inv[i] ) filename += "_INV_1";
805  if ( cmask[i] > 0 ) filename += "_CMASK_" + std::to_string( cmask[i] );
806  filename += ".txt.gz";
807 
808  gzFile outfile = gzopen( filename.c_str(), "wb" );
809  if ( outfile != NULL ) {
810  if ( nehalem ) {
811  gzprintf( outfile, "NHM " );
812  } else if ( westmere ) {
813  gzprintf( outfile, "WSM " );
814  } else if ( core ) {
815  gzprintf( outfile, "CORE " );
816  }
817  if ( gzprintf( outfile, "%s %d %d %d\n", event_cstr[i], cmask[i], inv[i], sp[i] ) <
818  (int)strlen( event_cstr[i] ) ) {
819  error() << "ERROR: gzputs err: " << gzerror( outfile, &err ) << ". Aborting..." << endmsg;
820  }
821  for ( const auto& it : samples[i] ) {
822  unsigned long long sum = 0;
823  for ( const auto& jt : it.second ) { sum += jt.second; }
824  if ( gzprintf( outfile, "%s%%%llu\n", it.first.c_str(), sum ) < (int)( it.first.length() ) ) {
825  error() << "ERROR: gzputs err: " << gzerror( outfile, &err ) << ". Aborting..." << endmsg;
826  }
827  for ( const auto& jt : it.second ) {
828  char sym_name[SYM_NAME_MAX_LENGTH];
829  bzero( sym_name, SYM_NAME_MAX_LENGTH );
830  const char* libName;
831  const char* symbolName;
832  int libOffset = 0;
833  int offset = 0;
834  void* sym_addr = IgHookTrace::tosymbol( (void*)( jt.first ) );
835  if ( sym_addr != NULL ) {
836  bool success = IgHookTrace::symbol( sym_addr, symbolName, libName, offset, libOffset );
837  if ( success ) {
838  if ( symbolName != NULL && strlen( symbolName ) > 0 ) {
839  strcpy( sym_name, symbolName );
840  strcat( sym_name, " " );
841  } else {
842  strcpy( sym_name, "??? " );
843  }
844  if ( libName != NULL && strlen( libName ) > 0 ) {
845  strcat( sym_name, libName );
846  strcat( sym_name, " " );
847  } else {
848  strcat( sym_name, "??? " );
849  }
850  sprintf( sym_name + strlen( sym_name ), "%d ", libOffset );
851  if ( strlen( sym_name ) <= 0 ) { error() << "ERROR: Symbol name length is zero. Aborting..." << endmsg; }
852  } else {
853  strcpy( sym_name, "??? ??? 0 " );
854  }
855  } else {
856  strcpy( sym_name, "??? ??? 0 " );
857  }
858  if ( gzprintf( outfile, "%s %d\n", sym_name, jt.second ) < (int)strlen( sym_name ) ) {
859  error() << "ERROR: gzputs err: " << gzerror( outfile, &err ) << endmsg;
860  }
861  }
862  }
863  } else {
864  error() << "ERROR: Could not open file: " << filename << ". Aborting..." << endmsg;
865  }
866  gzclose( outfile );
867  }
868 }
869 
871  if ( sampling == 0 )
872  finalizepm();
873  else
874  finalize_smpl();
875  return Auditor::finalize();
876 }
877 
878 void PerfMonAuditor::before( StandardEventType evt, INamedInterface* alg ) {
879  switch ( evt ) {
882  break;
883  case IAuditor::Execute:
884  i_beforeExecute( alg );
885  break;
886  default:
887  break;
888  }
889  return;
890 }
891 
892 void PerfMonAuditor::after( StandardEventType evt, INamedInterface* alg, const StatusCode& ) {
893  switch ( evt ) {
896  break;
897  case IAuditor::Execute:
898  i_afterExecute( alg );
899  break;
900  default:
901  break;
902  }
903  return;
904 }
905 
907 
909 
911  if ( !alg ) return;
912  // info() << "before:inside! " << alg->name() << endmsg;
913  if ( first_alg ) {
914  first_alg = false;
915  first_alg_name = alg->name();
916  // info() << "first_alg_name= " << alg->name() << endmsg;
917  }
918  if ( !event_count_reached ) {
919  if ( !first_alg_name.compare( alg->name() ) ) {
920  ph_ev_count++;
921  // info() << "EVENT COUNT: " << ph_ev_count << endmsg;
922  if ( ph_ev_count == start_at_event ) {
923  event_count_reached = true;
924  // info() << "!!! EVENT COUNT REACHED: " << ph_ev_count << endmsg;
925  }
926  }
927  }
928  if ( event_count_reached ) {
929  // info() << "before:inside! " << alg->name() << endmsg;
930 
931  if ( !alg_stack.empty() ) {
932  if ( sampling == 0 )
933  pausepm(); // pausing father algorithm counting
934  else
935  stop_smpl();
936  }
937  ++m_indent;
938  std::vector<unsigned long int> zeroes( 4, 0 );
939  alg_stack.push( std::make_pair( alg, zeroes ) );
940  if ( sampling == 0 )
941  startpm();
942  else
943  start_smpl();
944  }
945 }
946 
948  if ( !alg ) { return; } // info() << "after:inside! " << alg->name() << endmsg;
949 
950  if ( event_count_reached ) {
951  // info() << "after:inside! " << alg->name() << endmsg;
952 
953  if ( sampling == 0 )
954  stoppm();
955  else
956  stop_smpl();
957  alg_stack.pop();
958  --m_indent;
959  if ( !alg_stack.empty() ) {
960  if ( sampling == 0 )
961  startpm();
962  else
963  start_smpl(); // resuming father algorithm counting
964  }
965  }
966 }
967 
IOTest.evt
evt
Definition: IOTest.py:107
PerfMonAuditor::params
pfmlib_core_input_param_t params
Definition: PerfMonAuditor.cpp:390
pfm_start
os_err_t pfm_start(int fd, pfarg_start_t *start)
pfm_dfl_smpl_hdr_t::hdr_version
uint32_t hdr_version
Definition: perfmon_dfl_smpl.h:51
pfmlib_nhm_input_param_t::pfp_nhm_counters
pfmlib_nhm_counter_t pfp_nhm_counters[PMU_NHM_NUM_COUNTERS]
Definition: pfmlib_intel_nhm.h:139
PerfMonAuditor::i_beforeInitialize
void i_beforeInitialize(INamedInterface *alg)
Definition: PerfMonAuditor.cpp:906
pfm_dfl_smpl_arg_t::buf_size
uint64_t buf_size
Definition: perfmon_dfl_smpl.h:35
pfarg_pmd_t
Definition: perfmon_v2.h:38
PerfMonAuditor::inv
bool inv[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
Definition: PerfMonAuditor.cpp:387
pfmlib_core_input_param_t::pfp_core_counters
pfmlib_core_counter_t pfp_core_counters[PMU_CORE_NUM_COUNTERS]
Definition: pfmlib_core.h:79
PerfMonAuditor::is_nehalem
int is_nehalem()
Definition: PerfMonAuditor.cpp:224
pfm_write_pmds
os_err_t pfm_write_pmds(int fd, pfarg_pmd_t *pmds, int count)
pfarg_ctx_t
Definition: perfmon_v2.h:18
pfmlib_options_t::pfm_verbose
unsigned int pfm_verbose
Definition: pfmlib.h:138
std::string
STL class.
PerfMonAuditor::~PerfMonAuditor
virtual ~PerfMonAuditor()
Definition: PerfMonAuditor.cpp:352
pfmlib_output_param_t::pfp_pmd_count
unsigned int pfp_pmd_count
Definition: pfmlib.h:127
pfmlib_input_param_t::pfp_events
pfmlib_event_t pfp_events[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:112
IAuditor::Execute
@ Execute
Definition: IAuditor.h:34
PerfMonAuditor::i_afterExecute
void i_afterExecute(INamedInterface *alg)
Definition: PerfMonAuditor.cpp:947
pfarg_pmd_t::reg_short_reset
uint64_t reg_short_reset
Definition: perfmon_v2.h:44
pfarg_pmc_t::reg_num
uint16_t reg_num
Definition: perfmon_v2.h:28
pfm_dfl_smpl_hdr_t::hdr_overflows
uint64_t hdr_overflows
Definition: perfmon_dfl_smpl.h:48
PerfMonAuditor::inp
pfmlib_input_param_t inp
Definition: PerfMonAuditor.cpp:368
gaudirun.fd
fd
Definition: gaudirun.py:630
PerfMonAuditor::family
std::string family
Definition: PerfMonAuditor.cpp:383
PerfMonAuditor::core
bool core
Definition: PerfMonAuditor.cpp:395
pfmlib_core_input_param_t
Definition: pfmlib_core.h:78
PerfMonAuditor::load_args
pfarg_load_t load_args
Definition: PerfMonAuditor.cpp:416
pfarg_pmd_t::reg_flags
uint32_t reg_flags
Definition: perfmon_v2.h:41
pfarg_pmc_t
Definition: perfmon_v2.h:27
pfmlib_options_t::pfm_debug
unsigned int pfm_debug
Definition: pfmlib.h:137
std::vector
STL class.
os_err_t
int os_err_t
Definition: perfmon.h:69
ISvcLocator
Definition: ISvcLocator.h:46
pfarg_start_t
Definition: perfmon_v2.h:58
std::stack
STL class.
GaudiUtils::VectorMap< const INamedInterface *, int >
PerfMonAuditor::stop_smpl
void stop_smpl()
Definition: PerfMonAuditor.cpp:781
MAX_EVENT_NAME_LENGTH
#define MAX_EVENT_NAME_LENGTH
Definition: PerfMonAuditor.cpp:77
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:19
pfarg_pmd_t::reg_value
uint64_t reg_value
Definition: perfmon_v2.h:42
Auditor::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:82
pfarg_pmc_t::reg_value
uint64_t reg_value
Definition: perfmon_v2.h:31
pfm_read_pmds
os_err_t pfm_read_pmds(int fd, pfarg_pmd_t *pmds, int count)
PerfMonAuditor::PerfMonAuditor
PerfMonAuditor(const std::string &name, ISvcLocator *pSvc)
Definition: PerfMonAuditor.cpp:281
PerfMonAuditor::detect_unavail_pmcs
int detect_unavail_pmcs(int fd, pfmlib_regmask_t *r_pmcs)
Definition: PerfMonAuditor.cpp:399
PerfMonAuditor::level
int level
Definition: PerfMonAuditor.cpp:422
gaudirun.c
c
Definition: gaudirun.py:525
pfm_initialize
pfm_err_t pfm_initialize(void)
pfm_strerror
char * pfm_strerror(int code)
PerfMonAuditor::pfmlib_options
pfmlib_options_t pfmlib_options
Definition: PerfMonAuditor.cpp:420
IgHook_IgHookTrace.h
PerfMonAuditor::pausepm
void pausepm()
Definition: PerfMonAuditor.cpp:504
SYM_NAME_MAX_LENGTH
#define SYM_NAME_MAX_LENGTH
Definition: PerfMonAuditor.cpp:75
pfarg_load_t
Definition: perfmon_v2.h:68
pfmlib_nhm_input_param_t
Definition: pfmlib_intel_nhm.h:138
pfmlib_reg_t::reg_value
unsigned long long reg_value
Definition: pfmlib.h:97
PerfMonAuditor::finalize_smpl
void finalize_smpl()
Definition: PerfMonAuditor.cpp:794
pfm_dfl_smpl_entry_t
Definition: perfmon_dfl_smpl.h:67
HashMap.h
PFM_PLM3
#define PFM_PLM3
Definition: pfmlib.h:53
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.cpp:190
PerfMonAuditor::pfm_bv_copy
void pfm_bv_copy(uint64_t *d, uint64_t *j, uint16_t n)
Definition: PerfMonAuditor.cpp:404
PerfMonAuditor::PerfMonAuditor
PerfMonAuditor(const PerfMonAuditor &)
pfmlib_core.h
PerfMonAuditor::outp
pfmlib_output_param_t outp
Definition: PerfMonAuditor.cpp:369
PFM_VERSION_MAJOR
#define PFM_VERSION_MAJOR(x)
Definition: perfmon.h:213
pfm_create_context
os_err_t pfm_create_context(pfarg_ctx_t *ctx, char *smpl_name, void *smpl_arg, size_t smpl_size)
IIncidentSvc.h
pfmlib_intel_nhm.h
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.cpp:79
IToolSvc.h
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:81
Auditor::name
const std::string & name() const override
Definition: Auditor.cpp:192
PerfMonAuditor::first_alg_name
std::string first_alg_name
Definition: PerfMonAuditor.cpp:425
PerfMonAuditor::nhm_params
pfmlib_nhm_input_param_t nhm_params
Definition: PerfMonAuditor.cpp:391
VectorMap.h
pfarg_pmd_t::reg_num
uint16_t reg_num
Definition: perfmon_v2.h:39
Auditor::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:112
NUM_PMDS
#define NUM_PMDS
Definition: PerfMonAuditor.cpp:70
Auditor
Definition: Auditor.h:43
StatusCode
Definition: StatusCode.h:65
PerfMonAuditor
Definition: PerfMonAuditor.cpp:208
PerfMonAuditor::pfm_bv_set
void pfm_bv_set(uint64_t *bv, uint16_t rnum)
Definition: PerfMonAuditor.cpp:400
ProduceConsume.j
j
Definition: ProduceConsume.py:104
PerfMonAuditor::startpm
void startpm()
Definition: PerfMonAuditor.cpp:429
IgHookTrace::symbol
static bool symbol(void *address, const char *&sym, const char *&lib, int &offset, int &liboffset)
Definition: IgHook_IgHookTrace.cpp:222
perfmon.h
IAuditor::Initialize
@ Initialize
Definition: IAuditor.h:34
PerfMonAuditor::finalize
StatusCode finalize() override
Definition: PerfMonAuditor.cpp:870
std::string::c_str
T c_str(T... args)
PFM_CORE_SEL_INV
#define PFM_CORE_SEL_INV
Definition: pfmlib_core.h:68
pfmlib_reg_t::reg_num
unsigned int reg_num
Definition: pfmlib.h:99
PerfMonAuditor::finalizepm
void finalizepm()
Definition: PerfMonAuditor.cpp:516
pfmlib_output_param_t::pfp_pmcs
pfmlib_reg_t pfp_pmcs[PFMLIB_MAX_PMCS]
Definition: pfmlib.h:128
std::string::compare
T compare(T... args)
pfm_set_options
pfm_err_t pfm_set_options(pfmlib_options_t *opt)
PerfMonAuditor::ctx
pfarg_ctx_t ctx
Definition: PerfMonAuditor.cpp:370
std::to_string
T to_string(T... args)
PerfMonAuditor::detect_unavail_pmu_regs
int detect_unavail_pmu_regs(int fd, pfmlib_regmask_t *r_pmcs, pfmlib_regmask_t *r_pmds)
NUM_PMCS
#define NUM_PMCS
Definition: PerfMonAuditor.cpp:69
LBPL
#define LBPL
Definition: PerfMonAuditor.cpp:73
IgHookTrace::tosymbol
static void * tosymbol(void *address)
Definition: IgHook_IgHookTrace.cpp:247
PerfMonAuditor::after
void after(StandardEventType evt, INamedInterface *alg, const StatusCode &sc) override
Definition: PerfMonAuditor.cpp:892
PerfMonAuditor::Map
GaudiUtils::VectorMap< const INamedInterface *, int > Map
Definition: PerfMonAuditor.cpp:360
PerfMonAuditor::is_nehalem_ret
int is_nehalem_ret
Definition: PerfMonAuditor.cpp:366
PerfMonAuditor::stoppm
void stoppm()
Definition: PerfMonAuditor.cpp:494
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
FMT_NAME
#define FMT_NAME
Definition: PerfMonAuditor.cpp:71
pfmlib_input_param_t::pfp_dfl_plm
unsigned int pfp_dfl_plm
Definition: pfmlib.h:109
PerfMonAuditor::m_map
Map m_map
Definition: PerfMonAuditor.cpp:361
PerfMonAuditor::event_str
std::string event_str[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
Definition: PerfMonAuditor.cpp:381
pfmlib_input_param_t::pfp_event_count
unsigned int pfp_event_count
Definition: pfmlib.h:108
pfm_find_full_event
pfm_err_t pfm_find_full_event(const char *str, pfmlib_event_t *e)
PerfMonAuditor::ret
int ret
Definition: PerfMonAuditor.cpp:376
PerfMonAuditor::buf_addr
void * buf_addr
Definition: PerfMonAuditor.cpp:417
PerfMonAuditor::m_indent
int m_indent
Definition: PerfMonAuditor.cpp:362
PFM_NHM_SEL_INV
#define PFM_NHM_SEL_INV
Definition: pfmlib_intel_nhm.h:103
pfm_dfl_smpl_hdr_t
Definition: perfmon_dfl_smpl.h:45
cpluginsvc.n
n
Definition: cpluginsvc.py:234
PerfMonAuditor::num_counters
unsigned num_counters
Definition: PerfMonAuditor.cpp:418
PerfMonAuditor::prefix
std::string prefix
Definition: PerfMonAuditor.cpp:382
PerfMonAuditor::buf_arg
pfm_dfl_smpl_arg_t buf_arg
Definition: PerfMonAuditor.cpp:415
PFMLIB_SUCCESS
#define PFMLIB_SUCCESS
Definition: pfmlib.h:267
pfm_dfl_smpl_entry_t::ip
uint64_t ip
Definition: perfmon_dfl_smpl.h:72
PerfMonAuditor::event_count_reached
bool event_count_reached
Definition: PerfMonAuditor.cpp:426
pfm_dfl_smpl_arg_t
Definition: perfmon_dfl_smpl.h:34
PerfMonAuditor::westmere
bool westmere
Definition: PerfMonAuditor.cpp:394
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
pfmlib.h
hivetimeline.read
def read(f, regex=".*", skipevents=0)
Definition: hivetimeline.py:32
pfarg_pmd_t::reg_random_mask
uint64_t reg_random_mask
Definition: perfmon_v2.h:50
PerfMonAuditor::i
unsigned int i
Definition: PerfMonAuditor.cpp:375
INamedInterface
Definition: INamedInterface.h:25
PerfMonAuditor::pc
pfarg_pmc_t pc[NUM_PMCS]
Definition: PerfMonAuditor.cpp:372
PerfMonAuditor::start_at_event
unsigned int start_at_event
Definition: PerfMonAuditor.cpp:389
PropertyHolder< CommonMessaging< implements< IAuditor, IProperty > > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
Definition: PropertyHolder.h:106
pfarg_ctx_t::ctx_flags
uint32_t ctx_flags
Definition: perfmon_v2.h:19
PerfMonAuditor::first_alg
bool first_alg
Definition: PerfMonAuditor.cpp:424
PerfMonAuditor::process_smpl_buf
static void process_smpl_buf(pfm_dfl_smpl_hdr_t *hdr, size_t entry_size)
Definition: PerfMonAuditor.cpp:588
MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS
#define MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS
Definition: PerfMonAuditor.cpp:81
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
PFM_REGFL_RANDOM
#define PFM_REGFL_RANDOM
Definition: perfmon.h:113
PerfMonAuditor::m_inEvent
bool m_inEvent
Definition: PerfMonAuditor.cpp:363
PerfMonAuditor::used_counters_number
int used_counters_number
Definition: PerfMonAuditor.cpp:392
PerfMonAuditor::event_cstr
char event_cstr[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS][MAX_EVENT_NAME_LENGTH]
Definition: PerfMonAuditor.cpp:384
PerfMonAuditor::fd
int fd
Definition: PerfMonAuditor.cpp:374
pfm_restart
os_err_t pfm_restart(int fd)
IIncidentListener.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
PerfMonAuditor::m_pfm
PFMon & m_pfm
Definition: PerfMonAuditor.cpp:243
pfm_stop
os_err_t pfm_stop(int fd)
pfarg_msg_t
Definition: perfmon.h:205
perfmon_dfl_smpl.h
PerfMonAuditor::pd
pfarg_pmd_t pd[NUM_PMDS]
Definition: PerfMonAuditor.cpp:371
pfmlib_event_t
Definition: pfmlib.h:84
BPL
#define BPL
Definition: PerfMonAuditor.cpp:72
PerfMonAuditor::operator=
PerfMonAuditor & operator=(const PerfMonAuditor &)
PerfMonAuditor::PerfMonAuditor
PerfMonAuditor()
PerfMonAuditor::prefix_cstr
char prefix_cstr[MAX_PREFIX_NAME_LENGTH]
Definition: PerfMonAuditor.cpp:385
pfm_dfl_smpl_entry_t::ovfl_pmd
uint16_t ovfl_pmd
Definition: perfmon_dfl_smpl.h:69
pfm_load_context
os_err_t pfm_load_context(int fd, pfarg_load_t *load)
pfmlib_output_param_t
Definition: pfmlib.h:125
PerfMonAuditor::nehalem
bool nehalem
Definition: PerfMonAuditor.cpp:393
PerfMonAuditor::i_afterInitialize
void i_afterInitialize(INamedInterface *alg)
Definition: PerfMonAuditor.cpp:908
pfmlib_output_param_t::pfp_pmds
pfmlib_reg_t pfp_pmds[PFMLIB_MAX_PMDS]
Definition: pfmlib.h:129
PerfMonAuditor::cmask
unsigned int cmask[MAX_NUMBER_OF_PROGRAMMABLE_COUNTERS]
Definition: PerfMonAuditor.cpp:388
std::make_pair
T make_pair(T... args)
PFM_MSG_OVFL
#define PFM_MSG_OVFL
Definition: perfmon.h:210
PerfMonAuditor::ph_ev_count
unsigned int ph_ev_count
Definition: PerfMonAuditor.cpp:386
pfm_err_t
int pfm_err_t
Definition: pfmlib.h:150
PerfMonAuditor::max_pmd
unsigned int max_pmd
Definition: PerfMonAuditor.cpp:419
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
PerfMonAuditor::sigio_handler
static void sigio_handler(int, siginfo_t *, void *)
Definition: PerfMonAuditor.cpp:621
PerfMonAuditor::pfm_bv_isset
int pfm_bv_isset(uint64_t *bv, uint16_t rnum)
Definition: PerfMonAuditor.cpp:401
pfmlib_input_param_t
Definition: pfmlib.h:107
PerfMonAuditor::i_beforeExecute
void i_beforeExecute(INamedInterface *alg)
Definition: PerfMonAuditor.cpp:910
pfm_get_num_counters
pfm_err_t pfm_get_num_counters(unsigned int *num)
PerfMonAuditor::start_smpl
void start_smpl()
Definition: PerfMonAuditor.cpp:665
pfmlib_output_param_t::pfp_pmc_count
unsigned int pfp_pmc_count
Definition: pfmlib.h:126
pfarg_pmd_t::reg_long_reset
uint64_t reg_long_reset
Definition: perfmon_v2.h:43
pfm_dfl_smpl_hdr_t::hdr_count
uint64_t hdr_count
Definition: perfmon_dfl_smpl.h:46
MAX_PREFIX_NAME_LENGTH
#define MAX_PREFIX_NAME_LENGTH
Definition: PerfMonAuditor.cpp:78
graphanalysis.filename
filename
Definition: graphanalysis.py:130
pfm_write_pmcs
os_err_t pfm_write_pmcs(int fd, pfarg_pmc_t *pmcs, int count)
PerfMonAuditor::sampling
bool sampling
Definition: PerfMonAuditor.cpp:397
pfarg_pmd_t::reg_random_seed
uint32_t reg_random_seed
Definition: perfmon_v2.h:51
cpuid
#define cpuid(func, ax, bx, cx, dx)
Definition: PerfMonAuditor.cpp:83
pfmlib_regmask_t
Definition: pfmlib.h:75
pfmlib_options_t
Definition: pfmlib.h:136
PerfMonAuditor::load_arg
pfarg_load_t load_arg
Definition: PerfMonAuditor.cpp:373
pfarg_load_t::load_pid
uint32_t load_pid
Definition: perfmon_v2.h:69
pfm_dispatch_events
pfm_err_t pfm_dispatch_events(pfmlib_input_param_t *p, void *model_in, pfmlib_output_param_t *q, void *model_out)
MsgStream.h
PFM_REGFL_OVFL_NOTIFY
#define PFM_REGFL_OVFL_NOTIFY
Definition: perfmon.h:112
PerfMonAuditor::initialize
StatusCode initialize() override
Definition: PerfMonAuditor.cpp:549
PerfMonAuditor::before
void before(StandardEventType evt, INamedInterface *alg) override
Definition: PerfMonAuditor.cpp:878
Auditor.h