Marlin  1.17.1
 All Classes Namespaces Functions Variables Enumerations Friends Pages
MemoryMonitor.h
1 #ifndef MemoryMonitor_h
2 #define MemoryMonitor_h
3 
4 #include "marlin/Processor.h"
5 #include "lcio.h"
6 
7 #include "stdlib.h"
8 #include "stdio.h"
9 #include "string.h"
10 
11 using namespace lcio ;
12 using namespace marlin ;
13 
14 
27 class MemoryMonitor : public Processor {
28 
29 public:
30 
31  virtual Processor* newProcessor() { return new MemoryMonitor ; }
32 
33  MemoryMonitor() ;
34 
35  // Initialisation - run at the beginning to start histograms, etc.
36  virtual void init() ;
37 
38  // Called at the beginning of every run
39  virtual void processRunHeader( LCRunHeader* run ) ;
40 
41  // Run over each event - the main algorithm
42  virtual void processEvent( LCEvent * evt ) ;
43 
44  // Run at the end of each event
45  virtual void check( LCEvent * evt ) ;
46 
47  // Called at the very end for cleanup, histogram saving, etc.
48  virtual void end() ;
49 
50 
51 protected:
52 
53  int _howOften=1;
54 
55  // Run and event counters
56  int _eventNumber=-1;
57  int _runNumber=-1;
58 
59  int parseLine(char* line){
60  int i = strlen(line);
61  while (*line < '0' || *line > '9') line++;
62  line[i-3] = '\0';
63  i = atoi(line);
64  return i;
65  };
66 
67  //Used only on linux machines
68  int getValue(){ //Note: this value is in KB!
69  FILE* file = fopen("/proc/self/status", "r");
70  int result = -1;
71  char line[128];
72 
73 
74  while (fgets(line, 128, file) != NULL){
75  if (strncmp(line, "VmRSS:", 6) == 0){
76  result = parseLine(line);
77  break;
78  }
79  }
80  fclose(file);
81  return result;
82  };
83 
84 
85 } ;
86 
87 #endif
88 
89 
90 
virtual Processor * newProcessor()
Return a new instance of the processor.
Definition: MemoryMonitor.h:31
MemoryMonitor is a memory monitoring application for Marlin.
Definition: MemoryMonitor.h:27
Base class for Marlin processors.
Definition: Processor.h:64