Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Unified Diff: src/platform-linux.cc

Issue 11231002: Perform CPU sampling by CPU sampling thread only iff processing thread is not running. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: fixed crash in tests due to absent sampler Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-linux.cc
diff --git a/src/platform-linux.cc b/src/platform-linux.cc
index bf5565965a4b9bd028fb752a036662130798565c..5609af0e87ed9c12131cde9391abd50317193fc1 100644
--- a/src/platform-linux.cc
+++ b/src/platform-linux.cc
@@ -1025,6 +1025,7 @@ static int GetThreadID() {
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
USE(info);
if (signal != SIGPROF) return;
+
Isolate* isolate = Isolate::UncheckedCurrent();
if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) {
// We require a fully initialized and entered isolate.
@@ -1038,8 +1039,9 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
Sampler* sampler = isolate->logger()->sampler();
if (sampler == NULL || !sampler->IsActive()) return;
+ TickSample sample_obj;
TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate);
- if (sample == NULL) return;
+ if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
@@ -1190,16 +1192,45 @@ class SignalSender : public Thread {
SamplerRegistry::State state;
while ((state = SamplerRegistry::GetState()) !=
SamplerRegistry::HAS_NO_SAMPLERS) {
- if (rate_limiter_.SuspendIfNecessary()) continue;
- if (RuntimeProfiler::IsEnabled()) {
+ bool cpu_profiling_enabled =
+ (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
+ bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
+ // When CPU profiling is enabled both JavaScript and C++ code is
+ // profiled. We must not suspend.
+ if (!cpu_profiling_enabled) {
+ if (rate_limiter_.SuspendIfNecessary()) continue;
+ }
+ if (cpu_profiling_enabled && runtime_profiler_enabled) {
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, NULL)) {
+ return;
+ }
+ Sleep(HALF_INTERVAL);
if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) {
return;
}
+ Sleep(HALF_INTERVAL);
+ } else {
+ if (cpu_profiling_enabled) {
+ if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, NULL)) {
+ return;
+ }
+ }
+ if (runtime_profiler_enabled) {
+ if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile,
+ NULL)) {
+ return;
+ }
+ }
+ Sleep(FULL_INTERVAL);
}
- Sleep(FULL_INTERVAL);
}
}
+ static void DoCpuProfile(Sampler* sampler, void*) {
+ if (!sampler->IsProfiling()) return;
+ sampler->platform_data()->SendProfilingSignal();
+ }
+
static void DoRuntimeProfile(Sampler* sampler, void* ignored) {
if (!sampler->isolate()->IsInitialized()) return;
sampler->isolate()->runtime_profiler()->NotifyTick();
@@ -1284,6 +1315,7 @@ Sampler::Sampler(Isolate* isolate, int interval)
interval_(interval),
profiling_(false),
active_(false),
+ has_processing_thread_(false),
samples_taken_(0) {
data_ = new PlatformData;
}
@@ -1302,7 +1334,6 @@ void Sampler::DoSample() {
void Sampler::Start() {
ASSERT(!IsActive());
- CpuProfilerSignalHandler::InstallSignalHandler();
SetActive(true);
SignalSender::AddActiveSampler(this);
}
@@ -1310,10 +1341,19 @@ void Sampler::Start() {
void Sampler::Stop() {
ASSERT(IsActive());
- CpuProfilerSignalHandler::RestoreSignalHandler();
SignalSender::RemoveActiveSampler(this);
SetActive(false);
}
+void Sampler::StartSampling() {
+ CpuProfilerSignalHandler::InstallSignalHandler();
+}
+
+
+void Sampler::StopSampling() {
+ CpuProfilerSignalHandler::RestoreSignalHandler();
+}
+
+
} } // namespace v8::internal
« no previous file with comments | « src/platform-freebsd.cc ('k') | src/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698