Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MemoryMonitor.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 #include "marlin/MemoryMonitor.h"
3 
4 #include "sys/types.h"
5 
6 #ifdef __APPLE__
7 #include "sys/sysctl.h"
8 #include <mach/mach.h>
9 
10 #else
11 #include "sys/sysinfo.h"
12 #endif
13 
14 using namespace lcio ;
15 using namespace marlin ;
16 using namespace std ;
17 
19 
20 
22 
23  // modify processor description
24  _description = "Simple processor to print out the memory consumption at defined intervals" ;
25 
26  registerProcessorParameter("howOften",
27  "Print Event Number Every N Events",
28  _howOften,
29  int(1) ) ;
30 }
31 
32 
34 
35  // Print the initial parameters
36  printParameters() ;
37 
38  // Reset counters
39  _runNumber = 0 ;
40  _eventNumber = 0 ;
41 
42 
43 }
44 
45 
46 void MemoryMonitor::processRunHeader( LCRunHeader* ) {
47  _runNumber++ ;
48 }
49 
50 void MemoryMonitor::processEvent( LCEvent* ) {
51 
52 
53  if (_eventNumber % _howOften == 0) {
54 
55 #ifdef __APPLE__
56  struct task_basic_info t_info;
57  mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
58 
59  if (KERN_SUCCESS != task_info(mach_task_self(),
60  TASK_BASIC_INFO, (task_info_t)&t_info,
61  &t_info_count))
62  {
63  streamlog_out(ERROR) << "Problem accessing system information from MacOS X!"<< std::endl ;
64  }
65 
66  streamlog_out(MESSAGE) << " Processed event "<<_eventNumber
67  << " Resident size is: "<< t_info.resident_size<<" virtual size: "<<t_info.virtual_size
68  << std::endl ;
69 
70 #else
71  struct sysinfo memInfo;
72 
73  sysinfo (&memInfo);
74 
75  unsigned long physMemUsed = memInfo.totalram - memInfo.freeram;
76  //Multiply in next statement to avoid int overflow on right hand side...
77 
78 
79  streamlog_out(MESSAGE) << " Processed event "<<_eventNumber
80  << " Physical memory in use: "<<physMemUsed
81  << std::endl ;
82 #endif
83  }
84  // Increment the event number
85  _eventNumber++ ;
86 
87 }
88 
89 void MemoryMonitor::check( LCEvent* ) {
90  // nothing to check here - could be used to fill checkplots in reconstruction processor
91 }
92 
93 
95 
96  streamlog_out(MESSAGE) << "MemoryMonitor::end() " << name() << " processed " << _eventNumber << " events in " << _runNumber << " runs "
97  << std::endl ;
98 
99 
100 
101 }
void registerProcessorParameter(const std::string &parameterName, const std::string &parameterDescription, T &parameter, const T &defaultVal, int setSize=0)
Register a steering variable for this processor - call in constructor of processor.
Definition: Processor.h:254
virtual const std::string & name() const
Return name of this processor.
Definition: Processor.h:132
T endl(T...args)
MemoryMonitor is a memory monitoring application for Marlin.
Definition: MemoryMonitor.h:27
virtual void end()
Called after data processing for clean up in the inverse order of the init() method so that resources...
MemoryMonitor aMemoryMonitor
void printParameters()
Print the parameters and their values depending on the given verbosity level.
Definition: Processor.h:156
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
virtual void check(LCEvent *evt)
Called for every event - right after processEvent() has been called for this processor.
virtual void init()
Called at the begin of the job before anything is read.
Base class for Marlin processors.
Definition: Processor.h:64
std::string _description
Describes what the processor does.
Definition: Processor.h:452
virtual void processRunHeader(LCRunHeader *run)
Called for every run, e.g.