From 646a578b3f77852b352bb575a8b091d27a5f8ce4 Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Thu, 25 Nov 2010 15:54:52 +0000 Subject: [PATCH] Simplify ProfLazyMode test on Linux. Instead of installing signal handler, count samples taken. Review URL: http://codereview.chromium.org/5325003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5891 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/log.cc | 11 ++++++----- src/platform-freebsd.cc | 3 ++- src/platform-linux.cc | 3 ++- src/platform-macos.cc | 3 ++- src/platform-openbsd.cc | 6 +++++- src/platform-solaris.cc | 3 ++- src/platform-win32.cc | 3 ++- src/platform.h | 17 +++++++++++++++-- test/cctest/test-log.cc | 42 ++++++++++-------------------------------- 9 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/log.cc b/src/log.cc index d12aafb..55f15de 100644 --- a/src/log.cc +++ b/src/log.cc @@ -194,11 +194,6 @@ class Ticker: public Sampler { ~Ticker() { if (IsActive()) Stop(); } - virtual void SampleStack(TickSample* sample) { - ASSERT(IsSynchronous()); - StackTracer::Trace(sample); - } - virtual void Tick(TickSample* sample) { if (profiler_) profiler_->Insert(sample); if (window_) window_->AddState(sample->state); @@ -224,6 +219,12 @@ class Ticker: public Sampler { if (!window_ && IsActive()) Stop(); } + protected: + virtual void DoSampleStack(TickSample* sample) { + ASSERT(IsSynchronous()); + StackTracer::Trace(sample); + } + private: SlidingStateWindow* window_; Profiler* profiler_; diff --git a/src/platform-freebsd.cc b/src/platform-freebsd.cc index 6b8f2c0..0d89a16 100644 --- a/src/platform-freebsd.cc +++ b/src/platform-freebsd.cc @@ -620,7 +620,8 @@ Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), synchronous_(profiling), - active_(false) { + active_(false), + samples_taken_(0) { data_ = new PlatformData(); } diff --git a/src/platform-linux.cc b/src/platform-linux.cc index 89003ba..cb8e919 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -865,7 +865,8 @@ Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), synchronous_(profiling), - active_(false) { + active_(false), + samples_taken_(0) { data_ = new PlatformData(this); } diff --git a/src/platform-macos.cc b/src/platform-macos.cc index 5e0e78d..c3f21dc 100644 --- a/src/platform-macos.cc +++ b/src/platform-macos.cc @@ -634,7 +634,8 @@ Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), synchronous_(profiling), - active_(false) { + active_(false), + samples_taken_(0) { data_ = new PlatformData(this); } diff --git a/src/platform-openbsd.cc b/src/platform-openbsd.cc index e03059a..0751fc7 100644 --- a/src/platform-openbsd.cc +++ b/src/platform-openbsd.cc @@ -572,7 +572,11 @@ class Sampler::PlatformData : public Malloced { Sampler::Sampler(int interval, bool profiling) - : interval_(interval), profiling_(profiling), active_(false) { + : interval_(interval), + profiling_(profiling), + synchronous_(profiling), + active_(false), + samples_taken_(0) { data_ = new PlatformData(); } diff --git a/src/platform-solaris.cc b/src/platform-solaris.cc index fcd69de..ff5d83b 100644 --- a/src/platform-solaris.cc +++ b/src/platform-solaris.cc @@ -605,7 +605,8 @@ Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), synchronous_(profiling), - active_(false) { + active_(false), + samples_taken_(0) { data_ = new PlatformData(); } diff --git a/src/platform-win32.cc b/src/platform-win32.cc index 2a9dd67..1dcc84b 100644 --- a/src/platform-win32.cc +++ b/src/platform-win32.cc @@ -1905,7 +1905,8 @@ Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), synchronous_(profiling), - active_(false) { + active_(false), + samples_taken_(0) { data_ = new PlatformData(this); } diff --git a/src/platform.h b/src/platform.h index 42e6eae..49efc3c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -554,11 +554,14 @@ class TickSample { class Sampler { public: // Initialize sampler. - explicit Sampler(int interval, bool profiling); + Sampler(int interval, bool profiling); virtual ~Sampler(); // Performs stack sampling. - virtual void SampleStack(TickSample* sample) = 0; + void SampleStack(TickSample* sample) { + DoSampleStack(sample); + IncSamplesTaken(); + } // This method is called for each sampling period with the current // program counter. @@ -580,14 +583,24 @@ class Sampler { // Whether the sampler is running (that is, consumes resources). bool IsActive() const { return active_; } + // Used in tests to make sure that stack sampling is performed. + int samples_taken() const { return samples_taken_; } + void ResetSamplesTaken() { samples_taken_ = 0; } + class PlatformData; + protected: + virtual void DoSampleStack(TickSample* sample) = 0; + private: + void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; } + const int interval_; const bool profiling_; const bool synchronous_; bool active_; PlatformData* data_; // Platform specific data. + int samples_taken_; // Counts stack samples taken. DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); }; diff --git a/test/cctest/test-log.cc b/test/cctest/test-log.cc index 7168737..710c10e 100644 --- a/test/cctest/test-log.cc +++ b/test/cctest/test-log.cc @@ -139,6 +139,12 @@ namespace internal { class LoggerTestHelper : public AllStatic { public: static bool IsSamplerActive() { return Logger::IsProfilerSamplerActive(); } + static void ResetSamplesTaken() { + reinterpret_cast(Logger::ticker_)->ResetSamplesTaken(); + } + static bool has_samples_taken() { + return reinterpret_cast(Logger::ticker_)->samples_taken() > 0; + } }; } // namespace v8::internal @@ -147,24 +153,6 @@ class LoggerTestHelper : public AllStatic { using v8::internal::LoggerTestHelper; -// Under Linux, we need to check if signals were delivered to avoid false -// positives. Under other platforms profiling is done via a high-priority -// thread, so this case never happen. -static bool was_sigprof_received = true; -#ifdef __linux__ - -struct sigaction old_sigprof_handler; -pthread_t our_thread; - -static void SigProfSignalHandler(int signal, siginfo_t* info, void* context) { - if (signal != SIGPROF || !pthread_equal(pthread_self(), our_thread)) return; - was_sigprof_received = true; - old_sigprof_handler.sa_sigaction(signal, info, context); -} - -#endif // __linux__ - - namespace { class ScopedLoggerInitializer { @@ -258,6 +246,9 @@ class LogBufferMatcher { static void CheckThatProfilerWorks(LogBufferMatcher* matcher) { + CHECK(!LoggerTestHelper::IsSamplerActive()); + LoggerTestHelper::ResetSamplesTaken(); + Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0); CHECK(LoggerTestHelper::IsSamplerActive()); @@ -266,19 +257,6 @@ static void CheckThatProfilerWorks(LogBufferMatcher* matcher) { const char* code_creation = "\ncode-creation,"; // eq. to /^code-creation,/ CHECK_NE(NULL, matcher->Find(code_creation)); -#ifdef __linux__ - // Intercept SIGPROF handler to make sure that the test process - // had received it. Under load, system can defer it causing test failure. - // It is important to execute this after 'ResumeProfiler'. - our_thread = pthread_self(); - was_sigprof_received = false; - struct sigaction sa; - sa.sa_sigaction = SigProfSignalHandler; - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_SIGINFO; - CHECK_EQ(0, sigaction(SIGPROF, &sa, &old_sigprof_handler)); -#endif // __linux__ - // Force compiler to generate new code by parametrizing source. EmbeddedVector script_src; i::OS::SNPrintF(script_src, @@ -306,7 +284,7 @@ static void CheckThatProfilerWorks(LogBufferMatcher* matcher) { CHECK_NE(NULL, matcher->Find(code_creation)); const char* tick = "\ntick,"; const bool ticks_found = matcher->Find(tick) != NULL; - CHECK_EQ(was_sigprof_received, ticks_found); + CHECK_EQ(LoggerTestHelper::has_samples_taken(), ticks_found); } -- 2.7.4