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
parent 9137e4a8
...@@ -194,11 +194,6 @@ class Ticker: public Sampler { ...@@ -194,11 +194,6 @@ class Ticker: public Sampler {
~Ticker() { if (IsActive()) Stop(); } ~Ticker() { if (IsActive()) Stop(); }
virtual void SampleStack(TickSample* sample) {
ASSERT(IsSynchronous());
StackTracer::Trace(sample);
}
virtual void Tick(TickSample* sample) { virtual void Tick(TickSample* sample) {
if (profiler_) profiler_->Insert(sample); if (profiler_) profiler_->Insert(sample);
if (window_) window_->AddState(sample->state); if (window_) window_->AddState(sample->state);
...@@ -224,6 +219,12 @@ class Ticker: public Sampler { ...@@ -224,6 +219,12 @@ class Ticker: public Sampler {
if (!window_ && IsActive()) Stop(); if (!window_ && IsActive()) Stop();
} }
protected:
virtual void DoSampleStack(TickSample* sample) {
ASSERT(IsSynchronous());
StackTracer::Trace(sample);
}
private: private:
SlidingStateWindow* window_; SlidingStateWindow* window_;
Profiler* profiler_; Profiler* profiler_;
......
...@@ -620,7 +620,8 @@ Sampler::Sampler(int interval, bool profiling) ...@@ -620,7 +620,8 @@ Sampler::Sampler(int interval, bool profiling)
: interval_(interval), : interval_(interval),
profiling_(profiling), profiling_(profiling),
synchronous_(profiling), synchronous_(profiling),
active_(false) { active_(false),
samples_taken_(0) {
data_ = new PlatformData(); data_ = new PlatformData();
} }
......
...@@ -865,7 +865,8 @@ Sampler::Sampler(int interval, bool profiling) ...@@ -865,7 +865,8 @@ Sampler::Sampler(int interval, bool profiling)
: interval_(interval), : interval_(interval),
profiling_(profiling), profiling_(profiling),
synchronous_(profiling), synchronous_(profiling),
active_(false) { active_(false),
samples_taken_(0) {
data_ = new PlatformData(this); data_ = new PlatformData(this);
} }
......
...@@ -634,7 +634,8 @@ Sampler::Sampler(int interval, bool profiling) ...@@ -634,7 +634,8 @@ Sampler::Sampler(int interval, bool profiling)
: interval_(interval), : interval_(interval),
profiling_(profiling), profiling_(profiling),
synchronous_(profiling), synchronous_(profiling),
active_(false) { active_(false),
samples_taken_(0) {
data_ = new PlatformData(this); data_ = new PlatformData(this);
} }
......
...@@ -572,7 +572,11 @@ class Sampler::PlatformData : public Malloced { ...@@ -572,7 +572,11 @@ class Sampler::PlatformData : public Malloced {
Sampler::Sampler(int interval, bool profiling) 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(); data_ = new PlatformData();
} }
......
...@@ -605,7 +605,8 @@ Sampler::Sampler(int interval, bool profiling) ...@@ -605,7 +605,8 @@ Sampler::Sampler(int interval, bool profiling)
: interval_(interval), : interval_(interval),
profiling_(profiling), profiling_(profiling),
synchronous_(profiling), synchronous_(profiling),
active_(false) { active_(false),
samples_taken_(0) {
data_ = new PlatformData(); data_ = new PlatformData();
} }
......
...@@ -1905,7 +1905,8 @@ Sampler::Sampler(int interval, bool profiling) ...@@ -1905,7 +1905,8 @@ Sampler::Sampler(int interval, bool profiling)
: interval_(interval), : interval_(interval),
profiling_(profiling), profiling_(profiling),
synchronous_(profiling), synchronous_(profiling),
active_(false) { active_(false),
samples_taken_(0) {
data_ = new PlatformData(this); data_ = new PlatformData(this);
} }
......
...@@ -554,11 +554,14 @@ class TickSample { ...@@ -554,11 +554,14 @@ class TickSample {
class Sampler { class Sampler {
public: public:
// Initialize sampler. // Initialize sampler.
explicit Sampler(int interval, bool profiling); Sampler(int interval, bool profiling);
virtual ~Sampler(); virtual ~Sampler();
// Performs stack sampling. // 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 // This method is called for each sampling period with the current
// program counter. // program counter.
...@@ -580,14 +583,24 @@ class Sampler { ...@@ -580,14 +583,24 @@ class Sampler {
// Whether the sampler is running (that is, consumes resources). // Whether the sampler is running (that is, consumes resources).
bool IsActive() const { return active_; } 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; class PlatformData;
protected:
virtual void DoSampleStack(TickSample* sample) = 0;
private: private:
void IncSamplesTaken() { if (++samples_taken_ < 0) samples_taken_ = 0; }
const int interval_; const int interval_;
const bool profiling_; const bool profiling_;
const bool synchronous_; const bool synchronous_;
bool active_; bool active_;
PlatformData* data_; // Platform specific data. PlatformData* data_; // Platform specific data.
int samples_taken_; // Counts stack samples taken.
DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler);
}; };
......
...@@ -139,6 +139,12 @@ namespace internal { ...@@ -139,6 +139,12 @@ namespace internal {
class LoggerTestHelper : public AllStatic { class LoggerTestHelper : public AllStatic {
public: public:
static bool IsSamplerActive() { return Logger::IsProfilerSamplerActive(); } static bool IsSamplerActive() { return Logger::IsProfilerSamplerActive(); }
static void ResetSamplesTaken() {
reinterpret_cast<Sampler*>(Logger::ticker_)->ResetSamplesTaken();
}
static bool has_samples_taken() {
return reinterpret_cast<Sampler*>(Logger::ticker_)->samples_taken() > 0;
}
}; };
} // namespace v8::internal } // namespace v8::internal
...@@ -147,24 +153,6 @@ class LoggerTestHelper : public AllStatic { ...@@ -147,24 +153,6 @@ class LoggerTestHelper : public AllStatic {
using v8::internal::LoggerTestHelper; 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 { namespace {
class ScopedLoggerInitializer { class ScopedLoggerInitializer {
...@@ -258,6 +246,9 @@ class LogBufferMatcher { ...@@ -258,6 +246,9 @@ class LogBufferMatcher {
static void CheckThatProfilerWorks(LogBufferMatcher* matcher) { static void CheckThatProfilerWorks(LogBufferMatcher* matcher) {
CHECK(!LoggerTestHelper::IsSamplerActive());
LoggerTestHelper::ResetSamplesTaken();
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0); Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0);
CHECK(LoggerTestHelper::IsSamplerActive()); CHECK(LoggerTestHelper::IsSamplerActive());
...@@ -266,19 +257,6 @@ static void CheckThatProfilerWorks(LogBufferMatcher* matcher) { ...@@ -266,19 +257,6 @@ static void CheckThatProfilerWorks(LogBufferMatcher* matcher) {
const char* code_creation = "\ncode-creation,"; // eq. to /^code-creation,/ const char* code_creation = "\ncode-creation,"; // eq. to /^code-creation,/
CHECK_NE(NULL, matcher->Find(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. // Force compiler to generate new code by parametrizing source.
EmbeddedVector<char, 100> script_src; EmbeddedVector<char, 100> script_src;
i::OS::SNPrintF(script_src, i::OS::SNPrintF(script_src,
...@@ -306,7 +284,7 @@ static void CheckThatProfilerWorks(LogBufferMatcher* matcher) { ...@@ -306,7 +284,7 @@ static void CheckThatProfilerWorks(LogBufferMatcher* matcher) {
CHECK_NE(NULL, matcher->Find(code_creation)); CHECK_NE(NULL, matcher->Find(code_creation));
const char* tick = "\ntick,"; const char* tick = "\ntick,";
const bool ticks_found = matcher->Find(tick) != NULL; const bool ticks_found = matcher->Find(tick) != NULL;
CHECK_EQ(was_sigprof_received, ticks_found); CHECK_EQ(LoggerTestHelper::has_samples_taken(), ticks_found);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment