Fix crbug/24815. Changes affect profiler "lazy" mode used for V8 in Chromium.

- don't engage the processing thread of CPU profiling until the first time profiling is resumed, this saves us a thread allocation for the majority of users;
- don't log shared libraries addresses: this is useless for JS-only profiling, and also consumes time on startup.

Review URL: http://codereview.chromium.org/340013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3154 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent abbc6b91
......@@ -125,6 +125,9 @@ class Profiler: public Thread {
bool overflow_; // Tell whether a buffer overflow has occurred.
Semaphore* buffer_semaphore_; // Sempahore used for buffer synchronization.
// Tells whether profiler is engaged, that is, processing thread is stated.
bool engaged_;
// Tells whether worker thread should continue running.
bool running_;
......@@ -243,17 +246,25 @@ void SlidingStateWindow::AddState(StateTag state) {
//
// Profiler implementation.
//
Profiler::Profiler() {
buffer_semaphore_ = OS::CreateSemaphore(0);
head_ = 0;
tail_ = 0;
overflow_ = false;
running_ = false;
Profiler::Profiler()
: head_(0),
tail_(0),
overflow_(false),
buffer_semaphore_(OS::CreateSemaphore(0)),
engaged_(false),
running_(false) {
}
void Profiler::Engage() {
if (engaged_) return;
engaged_ = true;
// TODO(mnaganov): This is actually "Chromium" mode. Flags need to be revised.
// http://code.google.com/p/v8/issues/detail?id=487
if (!FLAG_prof_lazy) {
OS::LogSharedLibraryAddresses();
}
// Start thread processing the profiler buffer.
running_ = true;
......@@ -268,6 +279,8 @@ void Profiler::Engage() {
void Profiler::Disengage() {
if (!engaged_) return;
// Stop receiving ticks.
Logger::ticker_->ClearProfiler();
......@@ -1053,6 +1066,7 @@ void Logger::ResumeProfiler(int flags) {
}
if (modules_to_enable & PROFILER_MODULE_CPU) {
if (FLAG_prof_lazy) {
profiler_->Engage();
LOG(UncheckedStringEvent("profiler", "resume"));
FLAG_log_code = true;
LogCompiledFunctions();
......@@ -1245,8 +1259,10 @@ bool Logger::Setup() {
} else {
is_logging_ = true;
}
if (!FLAG_prof_lazy) {
profiler_->Engage();
}
}
LogMessageBuilder::set_write_failure_handler(StopLoggingAndProfiling);
......
......@@ -256,11 +256,10 @@ TEST(ProfLazyMode) {
// No sampling should happen prior to resuming profiler.
CHECK(!LoggerTestHelper::IsSamplerActive());
// Read initial logged data (static libs map).
EmbeddedVector<char, 102400> buffer;
// Nothing must be logged until profiling is resumed.
int log_pos = GetLogLines(0, &buffer);
CHECK_GT(log_pos, 0);
CHECK_GT(buffer.length(), log_pos);
CHECK_EQ(0, log_pos);
CompileAndRunScript("var a = (function(x) { return x + 1; })(10);");
......
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