#include "IgTools/IgProf/src/IgProf.h"
#include "IgTools/IgProf/src/IgProfTrace.h"
#include "IgTools/IgHook/interface/IgHook.h"
#include "IgTools/IgHook/interface/IgHookTrace.h"
#include <cstdlib>
#include <cstring>
#include <signal.h>
#include <sys/time.h>
Go to the source code of this file.
Functions | |
static int | dopthread_sigmask (IgHook::SafeData< igprof_dopthread_sigmask_t > &hook, int how, sigset_t *newmask, sigset_t *oldmask) |
static int | dosigaction (IgHook::SafeData< igprof_dosigaction_t > &hook, int signum, const struct sigaction *act, struct sigaction *oact) |
static void | enableSignalHandler (void) |
Enable profiling signal handler. | |
static void | enableTimer (void) |
Enable profiling timer. | |
IGPROF_LIBHOOK (3, int, dopthread_sigmask, _main,(int how, sigset_t *newmask, sigset_t *oldmask),(how, newmask, oldmask),"pthread_sigmask", 0, 0) IGPROF_LIBHOOK(3 | |
static void | initialize (void) |
Possibly start performance profiler. | |
static void | profileSignalHandler (int, siginfo_t *, void *) |
Performance profiler signal handler, SIGPROF or SIGALRM depending on the current profiler mode. | |
static void | threadInit (void) |
Thread setup function. | |
Variables | |
_main | |
int struct sigaction * | act |
static bool | autoboot = (initialize(), true) |
dosigaction | |
int | |
int struct sigaction struct sigaction * | oact |
int struct sigaction struct sigaction static IgProfTrace::CounterDef | s_ct_ticks = { "PERF_TICKS", IgProfTrace::TICK, -1 } |
static bool | s_initialized = false |
static int | s_itimer = ITIMER_PROF |
static int | s_moduleid = -1 |
static int | s_signal = SIGPROF |
int struct sigaction struct sigaction | sigaction |
int | signum |
static int dopthread_sigmask | ( | IgHook::SafeData< igprof_dopthread_sigmask_t > & | hook, | |
int | how, | |||
sigset_t * | newmask, | |||
sigset_t * | oldmask | |||
) | [static] |
Definition at line 171 of file IgProfPerf.cc.
References IgHook::SafeData< Func >::chain, IgProf::debug(), sigdelset, and sigismember.
00173 { 00174 if (newmask 00175 && (how == SIG_BLOCK || how == SIG_SETMASK) 00176 && sigismember(newmask, s_signal)) 00177 { 00178 IgProf::debug("pthread_sigmask(): prevented profiling signal" 00179 " %d from being blocked in thread 0x%lx\n", 00180 s_signal, (unsigned long) pthread_self()); 00181 sigdelset(newmask, s_signal); 00182 } 00183 00184 return hook.chain(how, newmask, oldmask); 00185 }
static int dosigaction | ( | IgHook::SafeData< igprof_dosigaction_t > & | hook, | |
int | signum, | |||
const struct sigaction * | act, | |||
struct sigaction * | oact | |||
) | [static] |
Definition at line 189 of file IgProfPerf.cc.
References IgHook::SafeData< Func >::chain, IgProf::debug(), profileSignalHandler(), SA_SIGINFO, sigaction, and sigemptyset.
00191 { 00192 struct sigaction sa; 00193 if (signum == s_signal 00194 && act 00195 && act->sa_handler != (sighandler_t) &profileSignalHandler) 00196 { 00197 IgProf::debug("sigaction(): prevented profiling signal" 00198 " %d from being overridden in thread 0x%lx\n", 00199 s_signal, (unsigned long) pthread_self()); 00200 sigemptyset(&sa.sa_mask); 00201 sa.sa_handler = (sighandler_t) &profileSignalHandler; 00202 sa.sa_flags = SA_RESTART | SA_SIGINFO; 00203 act = &sa; 00204 } 00205 00206 return hook.chain(signum, act, oact); 00207 }
Enable profiling signal handler.
Definition at line 67 of file IgProfPerf.cc.
References IgProf::isMultiThreaded(), profileSignalHandler(), SA_SIGINFO, sigaction, sigaddset, and sigemptyset.
Referenced by initialize(), and threadInit().
00068 { 00069 sigset_t profset; 00070 sigemptyset(&profset); 00071 sigaddset(&profset, s_signal); 00072 if (IgProf::isMultiThreaded()) 00073 pthread_sigmask(SIG_UNBLOCK, &profset, 0); 00074 else 00075 sigprocmask(SIG_UNBLOCK, &profset, 0); 00076 00077 struct sigaction sa; 00078 sigemptyset(&sa.sa_mask); 00079 sa.sa_handler = (sighandler_t) &profileSignalHandler; 00080 sa.sa_flags = SA_RESTART | SA_SIGINFO; 00081 sigaction(s_signal, &sa, 0); 00082 }
Enable profiling timer.
You should have called enableSignalHandler() before calling this function. This needs to be executed in every thread to be profiled.
Definition at line 59 of file IgProfPerf.cc.
Referenced by initialize(), and threadInit().
00060 { 00061 itimerval interval = { { 0, 10000 }, { 0, 10000 } }; 00062 setitimer(s_itimer, &interval, 0); 00063 }
IGPROF_LIBHOOK | ( | 3 | , | |
int | , | |||
dopthread_sigmask | , | |||
_main | , | |||
(int how, sigset_t *newmask, sigset_t *oldmask) | , | |||
(how, newmask, oldmask) | , | |||
"pthread_sigmask" | , | |||
0 | , | |||
0 | ||||
) |
Possibly start performance profiler.
Definition at line 96 of file IgProfPerf.cc.
References IgProf::debug(), IgProf::disable(), IgProf::enable(), enableSignalHandler(), enableTimer(), IgHook::hook(), IgProf::initialize(), Config::options, IgProf::options(), and threadInit().
00097 { 00098 if (s_initialized) return; 00099 s_initialized = true; 00100 00101 const char *options = IgProf::options(); 00102 bool enable = false; 00103 00104 while (options && *options) 00105 { 00106 while (*options == ' ' || *options == ',') 00107 ++options; 00108 00109 if (! strncmp(options, "perf", 4)) 00110 { 00111 enable = true; 00112 options += 4; 00113 while (*options) 00114 { 00115 if (! strncmp(options, ":real", 5)) 00116 { 00117 s_signal = SIGALRM; 00118 s_itimer = ITIMER_REAL; 00119 options += 5; 00120 } 00121 else if (! strncmp(options, ":user", 5)) 00122 { 00123 s_signal = SIGVTALRM; 00124 s_itimer = ITIMER_VIRTUAL; 00125 options += 5; 00126 } 00127 else if (! strncmp(options, ":process", 7)) 00128 { 00129 s_signal = SIGPROF; 00130 s_itimer = ITIMER_PROF; 00131 options += 7; 00132 } 00133 else 00134 break; 00135 } 00136 } 00137 else 00138 options++; 00139 00140 while (*options && *options != ',' && *options != ' ') 00141 options++; 00142 } 00143 00144 if (! enable) 00145 return; 00146 00147 if (! IgProf::initialize(&s_moduleid, &threadInit, true)) 00148 return; 00149 00150 IgProf::disable(true); 00151 if (s_itimer == ITIMER_REAL) 00152 IgProf::debug("Perf: measuring real time\n"); 00153 else if (s_itimer == ITIMER_VIRTUAL) 00154 IgProf::debug("Perf: profiling user time\n"); 00155 else if (s_itimer == ITIMER_PROF) 00156 IgProf::debug("Perf: profiling process time\n"); 00157 00158 // Enable profiler. 00159 IgHook::hook(dopthread_sigmask_hook_main.raw); 00160 IgHook::hook(dosigaction_hook_main.raw); 00161 IgProf::debug("Performance profiler enabled\n"); 00162 00163 enableSignalHandler(); 00164 enableTimer(); 00165 IgProf::enable(true); 00166 }
Performance profiler signal handler, SIGPROF or SIGALRM depending on the current profiler mode.
Record a tick for the current program location. Assumes the signal handler is registered for the correct thread. Skip ticks when this profiler is not enabled.
Definition at line 38 of file IgProfPerf.cc.
References IgProf::buffer(), IgProfTrace::COUNT, IgProf::enabled(), IgProfTrace::MAX_DEPTH, IgProfTrace::push(), s_ct_ticks, and IgHookTrace::stacktrace().
Referenced by dosigaction(), and enableSignalHandler().
00039 { 00040 if (! IgProf::enabled(false)) 00041 return; 00042 00043 IgProfTrace *buf = IgProf::buffer(s_moduleid); 00044 if (! buf) 00045 return; 00046 00047 void *addresses [IgProfTrace::MAX_DEPTH]; 00048 int depth = IgHookTrace::stacktrace(addresses, IgProfTrace::MAX_DEPTH); 00049 IgProfTrace::Record entry = { IgProfTrace::COUNT, &s_ct_ticks, 1, 1, 0 }; 00050 00051 // Drop two bottom frames, three top ones (stacktrace, me, signal frame). 00052 buf->push(addresses+3, depth-4, &entry, 1); 00053 }
Definition at line 86 of file IgProfPerf.cc.
References enableSignalHandler(), and enableTimer().
Referenced by initialize().
00087 { 00088 // Enable profiling in this thread. 00089 enableSignalHandler(); 00090 enableTimer(); 00091 }
Definition at line 20 of file IgProfPerf.cc.
double SprTrainedRBF::act [read] |
Definition at line 210 of file IgProfPerf.cc.
dosigaction |
Definition at line 20 of file IgProfPerf.cc.
Definition at line 20 of file IgProfPerf.cc.
int struct sigaction struct sigaction static IgProfTrace::CounterDef s_ct_ticks = { "PERF_TICKS", IgProfTrace::TICK, -1 } [static] |
bool s_initialized = false [static] |
Definition at line 27 of file IgProfPerf.cc.
Definition at line 29 of file IgProfPerf.cc.
int s_moduleid = -1 [static] |
Definition at line 30 of file IgProfPerf.cc.
Definition at line 28 of file IgProfPerf.cc.
Definition at line 21 of file IgProfPerf.cc.
Referenced by edm::disableRTSigs(), dosigaction(), enableSignalHandler(), edm::installSig(), and setupTimer().