GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — stackimpact-java/src/cpu_profiler.cpp at master · stackimpact/stackimpact-java Expand file tree/ Copy pathcpu_profiler.cppMore file actions 112 lines (76 loc) · 2.67 KB / Copy pathcpu_profiler.cppFile metadata and controls112 lines (76 loc) · 2.67 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 #include <signal.h> #include <sys/time.h> #include <string> #include <sstream> #include <iostream> #include "cpu_profiler.h" using namespace std; void SignalHandler(int signum, siginfo_t *info, void *context) { if (info->si_code <= 0) { return; } Agent::instance.cpu_profiler->HandleSignal(context); } bool CPUProfiler::SetupProfiler() { if (!profile_recorder->sample_index.is_lock_free()) { Agent::instance.LogInfo("Lock-free atomics not available."); return false; } struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_handler = NULL; sa.sa_sigaction = SignalHandler; sa.sa_flags = SA_RESTART | SA_SIGINFO; if (sigaction(SIGPROF, &sa, NULL) < 0) { Agent::instance.LogInfo("Signal handler setup failed."); return false; } return true; } void CPUProfiler::DestroyProfiler() { SetSamplingRate(0); struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_handler = SIG_DFL; sigaction(SIGPROF, &sa, NULL); } void CPUProfiler::StartProfiler() { profile_recorder->Reset(); SetSamplingRate(sampling_rate); } void CPUProfiler::StopProfiler() { SetSamplingRate(0); } void CPUProfiler::SetSamplingRate(long rate) { static struct itimerval timer; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec = rate; timer.it_value = timer.it_interval; if (setitimer(ITIMER_PROF, &timer, 0) == -1) { ostringstream msg; msg << "setitimer failed with error " << errno; Agent::instance.LogError(msg.str()); return; } } void CPUProfiler::HandleSignal(void* context) { profile_recorder->RecordSample(0, context); } extern "C" JNIEXPORT jboolean JNICALL Java_com_stackimpact_agent_profilers_CPUProfiler_setupCPUProfiler(JNIEnv* env, jobject unused, jlong sampling_rate) { Agent* agent = &Agent::instance; agent->cpu_profiler->sampling_rate = (long)sampling_rate; return agent->cpu_profiler->SetupProfiler(); } extern "C" JNIEXPORT void JNICALL Java_com_stackimpact_agent_profilers_CPUProfiler_destroyCPUProfiler(JNIEnv* env, jobject unused) { Agent* agent = &Agent::instance; agent->cpu_profiler->DestroyProfiler(); } extern "C" JNIEXPORT void JNICALL Java_com_stackimpact_agent_profilers_CPUProfiler_startCPUProfiler(JNIEnv* env, jobject unused) { Agent* agent = &Agent::instance; agent->cpu_profiler->StartProfiler(); } extern "C" JNIEXPORT jobjectArray JNICALL Java_com_stackimpact_agent_profilers_CPUProfiler_stopCPUProfiler(JNIEnv* env, jobject unused) { Agent* agent = &Agent::instance; agent->cpu_profiler->StopProfiler(); return agent->cpu_profiler->profile_recorder->ExportProfile(env); } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |