| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // Logger class implementation. | 323 // Logger class implementation. |
| 324 // | 324 // |
| 325 Ticker* Logger::ticker_ = NULL; | 325 Ticker* Logger::ticker_ = NULL; |
| 326 Profiler* Logger::profiler_ = NULL; | 326 Profiler* Logger::profiler_ = NULL; |
| 327 VMState* Logger::current_state_ = NULL; | 327 VMState* Logger::current_state_ = NULL; |
| 328 VMState Logger::bottom_state_(EXTERNAL); | 328 VMState Logger::bottom_state_(EXTERNAL); |
| 329 SlidingStateWindow* Logger::sliding_state_window_ = NULL; | 329 SlidingStateWindow* Logger::sliding_state_window_ = NULL; |
| 330 const char** Logger::log_events_ = NULL; | 330 const char** Logger::log_events_ = NULL; |
| 331 CompressionHelper* Logger::compression_helper_ = NULL; | 331 CompressionHelper* Logger::compression_helper_ = NULL; |
| 332 bool Logger::is_logging_ = false; | 332 bool Logger::is_logging_ = false; |
| 333 int Logger::cpu_profiler_nesting_ = 0; |
| 334 int Logger::heap_profiler_nesting_ = 0; |
| 333 | 335 |
| 334 #define DECLARE_LONG_EVENT(ignore1, long_name, ignore2) long_name, | 336 #define DECLARE_LONG_EVENT(ignore1, long_name, ignore2) long_name, |
| 335 const char* kLongLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { | 337 const char* kLongLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
| 336 LOG_EVENTS_AND_TAGS_LIST(DECLARE_LONG_EVENT) | 338 LOG_EVENTS_AND_TAGS_LIST(DECLARE_LONG_EVENT) |
| 337 }; | 339 }; |
| 338 #undef DECLARE_LONG_EVENT | 340 #undef DECLARE_LONG_EVENT |
| 339 | 341 |
| 340 #define DECLARE_SHORT_EVENT(ignore1, ignore2, short_name) short_name, | 342 #define DECLARE_SHORT_EVENT(ignore1, ignore2, short_name) short_name, |
| 341 const char* kCompressedLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { | 343 const char* kCompressedLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = { |
| 342 LOG_EVENTS_AND_TAGS_LIST(DECLARE_SHORT_EVENT) | 344 LOG_EVENTS_AND_TAGS_LIST(DECLARE_SHORT_EVENT) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 361 for (int i = 0; i < NUMBER_OF_LOG_EVENTS; ++i) { | 363 for (int i = 0; i < NUMBER_OF_LOG_EVENTS; ++i) { |
| 362 msg.Append("alias,%s,%s\n", | 364 msg.Append("alias,%s,%s\n", |
| 363 kCompressedLogEventsNames[i], kLongLogEventsNames[i]); | 365 kCompressedLogEventsNames[i], kLongLogEventsNames[i]); |
| 364 } | 366 } |
| 365 msg.WriteToLogFile(); | 367 msg.WriteToLogFile(); |
| 366 } | 368 } |
| 367 | 369 |
| 368 #endif // ENABLE_LOGGING_AND_PROFILING | 370 #endif // ENABLE_LOGGING_AND_PROFILING |
| 369 | 371 |
| 370 | 372 |
| 371 void Logger::Preamble(const char* content) { | |
| 372 #ifdef ENABLE_LOGGING_AND_PROFILING | |
| 373 if (!Log::IsEnabled() || !FLAG_log_code) return; | |
| 374 LogMessageBuilder msg; | |
| 375 msg.WriteCStringToLogFile(content); | |
| 376 #endif | |
| 377 } | |
| 378 | |
| 379 | |
| 380 void Logger::StringEvent(const char* name, const char* value) { | 373 void Logger::StringEvent(const char* name, const char* value) { |
| 381 #ifdef ENABLE_LOGGING_AND_PROFILING | 374 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 382 if (FLAG_log) UncheckedStringEvent(name, value); | 375 if (FLAG_log) UncheckedStringEvent(name, value); |
| 383 #endif | 376 #endif |
| 384 } | 377 } |
| 385 | 378 |
| 386 | 379 |
| 387 #ifdef ENABLE_LOGGING_AND_PROFILING | 380 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 388 void Logger::UncheckedStringEvent(const char* name, const char* value) { | 381 void Logger::UncheckedStringEvent(const char* name, const char* value) { |
| 389 if (!Log::IsEnabled()) return; | 382 if (!Log::IsEnabled()) return; |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 if (!profiler_->paused()) { | 1150 if (!profiler_->paused()) { |
| 1158 result |= PROFILER_MODULE_CPU; | 1151 result |= PROFILER_MODULE_CPU; |
| 1159 } | 1152 } |
| 1160 if (FLAG_log_gc) { | 1153 if (FLAG_log_gc) { |
| 1161 result |= PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS; | 1154 result |= PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS; |
| 1162 } | 1155 } |
| 1163 return result; | 1156 return result; |
| 1164 } | 1157 } |
| 1165 | 1158 |
| 1166 | 1159 |
| 1167 void Logger::PauseProfiler(int flags) { | 1160 void Logger::PauseProfiler(int flags, int tag) { |
| 1168 if (!Log::IsEnabled()) return; | 1161 if (!Log::IsEnabled()) return; |
| 1169 const int active_modules = GetActiveProfilerModules(); | 1162 if (flags & PROFILER_MODULE_CPU) { |
| 1170 const int modules_to_disable = active_modules & flags; | 1163 // It is OK to have negative nesting. |
| 1171 if (modules_to_disable == PROFILER_MODULE_NONE) return; | 1164 if (--cpu_profiler_nesting_ == 0) { |
| 1172 | 1165 profiler_->pause(); |
| 1173 if (modules_to_disable & PROFILER_MODULE_CPU) { | 1166 if (FLAG_prof_lazy) { |
| 1174 profiler_->pause(); | 1167 if (!FLAG_sliding_state_window) ticker_->Stop(); |
| 1175 if (FLAG_prof_lazy) { | 1168 FLAG_log_code = false; |
| 1176 if (!FLAG_sliding_state_window) ticker_->Stop(); | 1169 // Must be the same message as Log::kDynamicBufferSeal. |
| 1177 FLAG_log_code = false; | 1170 LOG(UncheckedStringEvent("profiler", "pause")); |
| 1178 // Must be the same message as Log::kDynamicBufferSeal. | 1171 } |
| 1179 LOG(UncheckedStringEvent("profiler", "pause")); | |
| 1180 } | 1172 } |
| 1181 } | 1173 } |
| 1182 if (modules_to_disable & | 1174 if (flags & |
| 1183 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { | 1175 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { |
| 1184 FLAG_log_gc = false; | 1176 if (--heap_profiler_nesting_ == 0) { |
| 1177 FLAG_log_gc = false; |
| 1178 } |
| 1185 } | 1179 } |
| 1186 // Turn off logging if no active modules remain. | 1180 if (tag != 0) { |
| 1187 if ((active_modules & ~flags) == PROFILER_MODULE_NONE) { | 1181 IntEvent("close-tag", tag); |
| 1182 } |
| 1183 if (GetActiveProfilerModules() == PROFILER_MODULE_NONE) { |
| 1188 is_logging_ = false; | 1184 is_logging_ = false; |
| 1189 } | 1185 } |
| 1190 } | 1186 } |
| 1191 | 1187 |
| 1192 | 1188 |
| 1193 void Logger::ResumeProfiler(int flags) { | 1189 void Logger::ResumeProfiler(int flags, int tag) { |
| 1194 if (!Log::IsEnabled()) return; | 1190 if (!Log::IsEnabled()) return; |
| 1195 const int modules_to_enable = ~GetActiveProfilerModules() & flags; | 1191 if (tag != 0) { |
| 1196 if (modules_to_enable != PROFILER_MODULE_NONE) { | 1192 IntEvent("open-tag", tag); |
| 1197 is_logging_ = true; | |
| 1198 } | 1193 } |
| 1199 if (modules_to_enable & PROFILER_MODULE_CPU) { | 1194 if (flags & PROFILER_MODULE_CPU) { |
| 1200 if (FLAG_prof_lazy) { | 1195 if (cpu_profiler_nesting_++ == 0) { |
| 1201 profiler_->Engage(); | 1196 is_logging_ = true; |
| 1202 LOG(UncheckedStringEvent("profiler", "resume")); | 1197 if (FLAG_prof_lazy) { |
| 1203 FLAG_log_code = true; | 1198 profiler_->Engage(); |
| 1204 LogCompiledFunctions(); | 1199 LOG(UncheckedStringEvent("profiler", "resume")); |
| 1205 LogFunctionObjects(); | 1200 FLAG_log_code = true; |
| 1206 LogAccessorCallbacks(); | 1201 LogCompiledFunctions(); |
| 1207 if (!FLAG_sliding_state_window) ticker_->Start(); | 1202 LogFunctionObjects(); |
| 1203 LogAccessorCallbacks(); |
| 1204 if (!FLAG_sliding_state_window) ticker_->Start(); |
| 1205 } |
| 1206 profiler_->resume(); |
| 1208 } | 1207 } |
| 1209 profiler_->resume(); | |
| 1210 } | 1208 } |
| 1211 if (modules_to_enable & | 1209 if (flags & |
| 1212 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { | 1210 (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) { |
| 1213 FLAG_log_gc = true; | 1211 if (heap_profiler_nesting_++ == 0) { |
| 1212 is_logging_ = true; |
| 1213 FLAG_log_gc = true; |
| 1214 } |
| 1214 } | 1215 } |
| 1215 } | 1216 } |
| 1216 | 1217 |
| 1217 | 1218 |
| 1218 // This function can be called when Log's mutex is acquired, | 1219 // This function can be called when Log's mutex is acquired, |
| 1219 // either from main or Profiler's thread. | 1220 // either from main or Profiler's thread. |
| 1220 void Logger::StopLoggingAndProfiling() { | 1221 void Logger::StopLoggingAndProfiling() { |
| 1221 Log::stop(); | 1222 Log::stop(); |
| 1222 PauseProfiler(PROFILER_MODULE_CPU); | 1223 PauseProfiler(PROFILER_MODULE_CPU, 0); |
| 1223 } | 1224 } |
| 1224 | 1225 |
| 1225 | 1226 |
| 1226 bool Logger::IsProfilerSamplerActive() { | 1227 bool Logger::IsProfilerSamplerActive() { |
| 1227 return ticker_->IsActive(); | 1228 return ticker_->IsActive(); |
| 1228 } | 1229 } |
| 1229 | 1230 |
| 1230 | 1231 |
| 1231 int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) { | 1232 int Logger::GetLogLines(int from_pos, char* dest_buf, int max_size) { |
| 1232 return Log::GetLogLines(from_pos, dest_buf, max_size); | 1233 return Log::GetLogLines(from_pos, dest_buf, max_size); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 // Otherwise, if the sliding state window computation has not been | 1544 // Otherwise, if the sliding state window computation has not been |
| 1544 // started we do it now. | 1545 // started we do it now. |
| 1545 if (sliding_state_window_ == NULL) { | 1546 if (sliding_state_window_ == NULL) { |
| 1546 sliding_state_window_ = new SlidingStateWindow(); | 1547 sliding_state_window_ = new SlidingStateWindow(); |
| 1547 } | 1548 } |
| 1548 #endif | 1549 #endif |
| 1549 } | 1550 } |
| 1550 | 1551 |
| 1551 | 1552 |
| 1552 } } // namespace v8::internal | 1553 } } // namespace v8::internal |
| OLD | NEW |