SlidingStateWindow* Logger::sliding_state_window_ = NULL;
const char** Logger::log_events_ = NULL;
CompressionHelper* Logger::compression_helper_ = NULL;
-bool Logger::is_logging_ = false;
+int Logger::logging_nesting_ = 0;
int Logger::cpu_profiler_nesting_ = 0;
int Logger::heap_profiler_nesting_ = 0;
void Logger::IntEvent(const char* name, int value) {
#ifdef ENABLE_LOGGING_AND_PROFILING
- if (!Log::IsEnabled() || !FLAG_log) return;
+ if (FLAG_log) UncheckedIntEvent(name, value);
+#endif
+}
+
+
+#ifdef ENABLE_LOGGING_AND_PROFILING
+void Logger::UncheckedIntEvent(const char* name, int value) {
+ if (!Log::IsEnabled()) return;
LogMessageBuilder msg;
msg.Append("%s,%d\n", name, value);
msg.WriteToLogFile();
-#endif
}
+#endif
void Logger::HandleEvent(const char* name, Object** location) {
// Must be the same message as Log::kDynamicBufferSeal.
LOG(UncheckedStringEvent("profiler", "pause"));
}
+ --logging_nesting_;
}
}
if (flags &
(PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
if (--heap_profiler_nesting_ == 0) {
FLAG_log_gc = false;
+ --logging_nesting_;
}
}
if (tag != 0) {
- IntEvent("close-tag", tag);
- }
- if (GetActiveProfilerModules() == PROFILER_MODULE_NONE) {
- is_logging_ = false;
+ UncheckedIntEvent("close-tag", tag);
}
}
void Logger::ResumeProfiler(int flags, int tag) {
if (!Log::IsEnabled()) return;
if (tag != 0) {
- IntEvent("open-tag", tag);
+ UncheckedIntEvent("open-tag", tag);
}
if (flags & PROFILER_MODULE_CPU) {
if (cpu_profiler_nesting_++ == 0) {
- is_logging_ = true;
+ ++logging_nesting_;
if (FLAG_prof_lazy) {
profiler_->Engage();
LOG(UncheckedStringEvent("profiler", "resume"));
if (flags &
(PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
if (heap_profiler_nesting_++ == 0) {
- is_logging_ = true;
+ ++logging_nesting_;
FLAG_log_gc = true;
}
}
compression_helper_ = new CompressionHelper(kCompressionWindowSize);
}
- is_logging_ = start_logging;
+ if (start_logging) {
+ logging_nesting_ = 1;
+ }
if (FLAG_prof) {
profiler_ = new Profiler();
if (!FLAG_prof_auto) {
profiler_->pause();
} else {
- is_logging_ = true;
+ logging_nesting_ = 1;
}
if (!FLAG_prof_lazy) {
profiler_->Engage();
}
static bool is_logging() {
- return is_logging_;
+ return logging_nesting_ > 0;
}
// Pause/Resume collection of profiling data.
// Logs a StringEvent regardless of whether FLAG_log is true.
static void UncheckedStringEvent(const char* name, const char* value);
+ // Logs an IntEvent regardless of whether FLAG_log is true.
+ static void UncheckedIntEvent(const char* name, int value);
+
// Stops logging and profiling in case of insufficient resources.
static void StopLoggingAndProfiling();
friend class LoggerTestHelper;
- static bool is_logging_;
+ static int logging_nesting_;
static int cpu_profiler_nesting_;
static int heap_profiler_nesting_;
#else
class ScopedLoggerInitializer {
public:
- explicit ScopedLoggerInitializer(bool log, bool prof_lazy)
- : saved_log_(i::FLAG_log),
- saved_prof_lazy_(i::FLAG_prof_lazy),
+ explicit ScopedLoggerInitializer(bool prof_lazy)
+ : saved_prof_lazy_(i::FLAG_prof_lazy),
saved_prof_(i::FLAG_prof),
saved_prof_auto_(i::FLAG_prof_auto),
- trick_to_run_init_flags_(init_flags_(log, prof_lazy)),
+ trick_to_run_init_flags_(init_flags_(prof_lazy)),
need_to_set_up_logger_(i::V8::IsRunning()),
scope_(),
env_(v8::Context::New()) {
i::FLAG_prof_lazy = saved_prof_lazy_;
i::FLAG_prof = saved_prof_;
i::FLAG_prof_auto = saved_prof_auto_;
- i::FLAG_log = saved_log_;
}
v8::Handle<v8::Context>& env() { return env_; }
private:
- static bool init_flags_(bool log, bool prof_lazy) {
- i::FLAG_log = log;
+ static bool init_flags_(bool prof_lazy) {
i::FLAG_prof = true;
i::FLAG_prof_lazy = prof_lazy;
i::FLAG_prof_auto = false;
return prof_lazy;
}
- const bool saved_log_;
const bool saved_prof_lazy_;
const bool saved_prof_;
const bool saved_prof_auto_;
TEST(ProfLazyMode) {
- ScopedLoggerInitializer initialize_logger(false, true);
+ ScopedLoggerInitializer initialize_logger(true);
// No sampling should happen prior to resuming profiler.
CHECK(!LoggerTestHelper::IsSamplerActive());
}
TEST(LogCallbacks) {
- ScopedLoggerInitializer initialize_logger(false, false);
+ ScopedLoggerInitializer initialize_logger(false);
LogBufferMatcher matcher;
v8::Persistent<v8::FunctionTemplate> obj =
}
TEST(LogAccessorCallbacks) {
- ScopedLoggerInitializer initialize_logger(false, false);
+ ScopedLoggerInitializer initialize_logger(false);
LogBufferMatcher matcher;
v8::Persistent<v8::FunctionTemplate> obj =
TEST(LogTags) {
- ScopedLoggerInitializer initialize_logger(true, false);
+ ScopedLoggerInitializer initialize_logger(false);
LogBufferMatcher matcher;
const char* open_tag = "open-tag,";
}
+TEST(IsLoggingPreserved) {
+ ScopedLoggerInitializer initialize_logger(false);
+
+ CHECK(Logger::is_logging());
+ Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
+ CHECK(Logger::is_logging());
+ Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
+ CHECK(Logger::is_logging());
+
+ CHECK(Logger::is_logging());
+ Logger::ResumeProfiler(
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+ CHECK(Logger::is_logging());
+ Logger::PauseProfiler(
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+ CHECK(Logger::is_logging());
+
+ CHECK(Logger::is_logging());
+ Logger::ResumeProfiler(
+ v8::PROFILER_MODULE_CPU |
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+ CHECK(Logger::is_logging());
+ Logger::PauseProfiler(
+ v8::PROFILER_MODULE_CPU |
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+ CHECK(Logger::is_logging());
+}
+
+
static inline bool IsStringEqualTo(const char* r, const char* s) {
return strncmp(r, s, strlen(r)) == 0;
}