| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 void Profiler::Engage() { | 219 void Profiler::Engage() { |
| 220 OS::LogSharedLibraryAddresses(); | 220 OS::LogSharedLibraryAddresses(); |
| 221 | 221 |
| 222 // Start thread processing the profiler buffer. | 222 // Start thread processing the profiler buffer. |
| 223 running_ = true; | 223 running_ = true; |
| 224 Start(); | 224 Start(); |
| 225 | 225 |
| 226 // Register to get ticks. | 226 // Register to get ticks. |
| 227 Logger::ticker_->SetProfiler(this); | 227 Logger::ticker_->SetProfiler(this); |
| 228 | 228 |
| 229 LOG(StringEvent("profiler", "begin")); | 229 LOG(UncheckedStringEvent("profiler", "begin")); |
| 230 } | 230 } |
| 231 | 231 |
| 232 | 232 |
| 233 void Profiler::Disengage() { | 233 void Profiler::Disengage() { |
| 234 // Stop receiving ticks. | 234 // Stop receiving ticks. |
| 235 Logger::ticker_->ClearProfiler(); | 235 Logger::ticker_->ClearProfiler(); |
| 236 | 236 |
| 237 // Terminate the worker thread by setting running_ to false, | 237 // Terminate the worker thread by setting running_ to false, |
| 238 // inserting a fake element in the queue and then wait for | 238 // inserting a fake element in the queue and then wait for |
| 239 // the thread to terminate. | 239 // the thread to terminate. |
| 240 running_ = false; | 240 running_ = false; |
| 241 TickSample sample; | 241 TickSample sample; |
| 242 sample.pc = 0; | 242 sample.pc = 0; |
| 243 sample.sp = 0; | 243 sample.sp = 0; |
| 244 sample.state = OTHER; | 244 sample.state = OTHER; |
| 245 Insert(&sample); | 245 Insert(&sample); |
| 246 Join(); | 246 Join(); |
| 247 | 247 |
| 248 LOG(StringEvent("profiler", "end")); | 248 LOG(UncheckedStringEvent("profiler", "end")); |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 void Profiler::Run() { | 252 void Profiler::Run() { |
| 253 TickSample sample; | 253 TickSample sample; |
| 254 bool overflow = Logger::profiler_->Remove(&sample); | 254 bool overflow = Logger::profiler_->Remove(&sample); |
| 255 while (running_) { | 255 while (running_) { |
| 256 LOG(TickEvent(&sample, overflow)); | 256 LOG(TickEvent(&sample, overflow)); |
| 257 overflow = Logger::profiler_->Remove(&sample); | 257 overflow = Logger::profiler_->Remove(&sample); |
| 258 } | 258 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 275 #ifdef ENABLE_LOGGING_AND_PROFILING | 275 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 276 if (logfile_ == NULL || !FLAG_log_code) return; | 276 if (logfile_ == NULL || !FLAG_log_code) return; |
| 277 ScopedLock sl(mutex_); | 277 ScopedLock sl(mutex_); |
| 278 fprintf(logfile_, "%s", content); | 278 fprintf(logfile_, "%s", content); |
| 279 #endif | 279 #endif |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 void Logger::StringEvent(const char* name, const char* value) { | 283 void Logger::StringEvent(const char* name, const char* value) { |
| 284 #ifdef ENABLE_LOGGING_AND_PROFILING | 284 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 285 if (logfile_ == NULL || !FLAG_log) return; | 285 if (FLAG_log) UncheckedStringEvent(name, value); |
| 286 ScopedLock sl(mutex_); | |
| 287 fprintf(logfile_, "%s,\"%s\"\n", name, value); | |
| 288 #endif | 286 #endif |
| 289 } | 287 } |
| 290 | 288 |
| 291 | 289 |
| 290 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 291 void Logger::UncheckedStringEvent(const char* name, const char* value) { |
| 292 if (logfile_ == NULL) return; |
| 293 ScopedLock sl(mutex_); |
| 294 fprintf(logfile_, "%s,\"%s\"\n", name, value); |
| 295 } |
| 296 #endif |
| 297 |
| 298 |
| 292 void Logger::IntEvent(const char* name, int value) { | 299 void Logger::IntEvent(const char* name, int value) { |
| 293 #ifdef ENABLE_LOGGING_AND_PROFILING | 300 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 294 if (logfile_ == NULL || !FLAG_log) return; | 301 if (logfile_ == NULL || !FLAG_log) return; |
| 295 ScopedLock sl(mutex_); | 302 ScopedLock sl(mutex_); |
| 296 fprintf(logfile_, "%s,%d\n", name, value); | 303 fprintf(logfile_, "%s,%d\n", name, value); |
| 297 #endif | 304 #endif |
| 298 } | 305 } |
| 299 | 306 |
| 300 | 307 |
| 301 void Logger::HandleEvent(const char* name, Object** location) { | 308 void Logger::HandleEvent(const char* name, Object** location) { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 FLAG_log_suspect = true; | 808 FLAG_log_suspect = true; |
| 802 FLAG_log_handles = true; | 809 FLAG_log_handles = true; |
| 803 FLAG_log_regexp = true; | 810 FLAG_log_regexp = true; |
| 804 } | 811 } |
| 805 | 812 |
| 806 // --prof implies --log-code. | 813 // --prof implies --log-code. |
| 807 if (FLAG_prof) FLAG_log_code = true; | 814 if (FLAG_prof) FLAG_log_code = true; |
| 808 | 815 |
| 809 bool open_log_file = FLAG_log || FLAG_log_api || FLAG_log_code | 816 bool open_log_file = FLAG_log || FLAG_log_api || FLAG_log_code |
| 810 || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect | 817 || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect |
| 811 || FLAG_log_regexp; | 818 || FLAG_log_regexp || FLAG_log_state_changes; |
| 812 | 819 |
| 813 // If we're logging anything, we need to open the log file. | 820 // If we're logging anything, we need to open the log file. |
| 814 if (open_log_file) { | 821 if (open_log_file) { |
| 815 if (strcmp(FLAG_logfile, "-") == 0) { | 822 if (strcmp(FLAG_logfile, "-") == 0) { |
| 816 logfile_ = stdout; | 823 logfile_ = stdout; |
| 817 } else if (strchr(FLAG_logfile, '%') != NULL) { | 824 } else if (strchr(FLAG_logfile, '%') != NULL) { |
| 818 // If there's a '%' in the log file name we have to expand | 825 // If there's a '%' in the log file name we have to expand |
| 819 // placeholders. | 826 // placeholders. |
| 820 HeapStringAllocator allocator; | 827 HeapStringAllocator allocator; |
| 821 StringStream stream(&allocator); | 828 StringStream stream(&allocator); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 | 931 |
| 925 | 932 |
| 926 // | 933 // |
| 927 // VMState class implementation. A simple stack of VM states held by the | 934 // VMState class implementation. A simple stack of VM states held by the |
| 928 // logger and partially threaded through the call stack. States are pushed by | 935 // logger and partially threaded through the call stack. States are pushed by |
| 929 // VMState construction and popped by destruction. | 936 // VMState construction and popped by destruction. |
| 930 // | 937 // |
| 931 #ifdef ENABLE_LOGGING_AND_PROFILING | 938 #ifdef ENABLE_LOGGING_AND_PROFILING |
| 932 static const char* StateToString(StateTag state) { | 939 static const char* StateToString(StateTag state) { |
| 933 switch (state) { | 940 switch (state) { |
| 941 case JS: |
| 942 return "JS"; |
| 934 case GC: | 943 case GC: |
| 935 return "GC"; | 944 return "GC"; |
| 936 case COMPILER: | 945 case COMPILER: |
| 937 return "COMPILER"; | 946 return "COMPILER"; |
| 938 case OTHER: | 947 case OTHER: |
| 939 return "OTHER"; | 948 return "OTHER"; |
| 940 default: | 949 default: |
| 941 UNREACHABLE(); | 950 UNREACHABLE(); |
| 942 return NULL; | 951 return NULL; |
| 943 } | 952 } |
| 944 } | 953 } |
| 945 | 954 |
| 946 VMState::VMState(StateTag state) { | 955 VMState::VMState(StateTag state) { |
| 947 state_ = state; | 956 state_ = state; |
| 948 previous_ = Logger::current_state_; | 957 previous_ = Logger::current_state_; |
| 949 Logger::current_state_ = this; | 958 Logger::current_state_ = this; |
| 950 | 959 |
| 951 if (FLAG_log_state_changes) { | 960 if (FLAG_log_state_changes) { |
| 952 LOG(StringEvent("Entering", StateToString(state_))); | 961 LOG(UncheckedStringEvent("Entering", StateToString(state_))); |
| 953 if (previous_) { | 962 if (previous_) { |
| 954 LOG(StringEvent("From", StateToString(previous_->state_))); | 963 LOG(UncheckedStringEvent("From", StateToString(previous_->state_))); |
| 955 } | 964 } |
| 956 } | 965 } |
| 957 } | 966 } |
| 958 | 967 |
| 959 | 968 |
| 960 VMState::~VMState() { | 969 VMState::~VMState() { |
| 961 Logger::current_state_ = previous_; | 970 Logger::current_state_ = previous_; |
| 962 | 971 |
| 963 if (FLAG_log_state_changes) { | 972 if (FLAG_log_state_changes) { |
| 964 LOG(StringEvent("Leaving", StateToString(state_))); | 973 LOG(UncheckedStringEvent("Leaving", StateToString(state_))); |
| 965 if (previous_) { | 974 if (previous_) { |
| 966 LOG(StringEvent("To", StateToString(previous_->state_))); | 975 LOG(UncheckedStringEvent("To", StateToString(previous_->state_))); |
| 967 } | 976 } |
| 968 } | 977 } |
| 969 } | 978 } |
| 970 #endif | 979 #endif |
| 971 | 980 |
| 972 } } // namespace v8::internal | 981 } } // namespace v8::internal |
| OLD | NEW |