| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 static void RestoreSignalHandler() { | 1085 static void RestoreSignalHandler() { |
| 1086 if (signal_handler_installed_) { | 1086 if (signal_handler_installed_) { |
| 1087 sigaction(SIGPROF, &old_signal_handler_, 0); | 1087 sigaction(SIGPROF, &old_signal_handler_, 0); |
| 1088 signal_handler_installed_ = false; | 1088 signal_handler_installed_ = false; |
| 1089 } | 1089 } |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 static void AddActiveSampler(Sampler* sampler) { | 1092 static void AddActiveSampler(Sampler* sampler) { |
| 1093 ScopedLock lock(mutex_); | 1093 ScopedLock lock(mutex_.Pointer()); |
| 1094 SamplerRegistry::AddActiveSampler(sampler); | 1094 SamplerRegistry::AddActiveSampler(sampler); |
| 1095 if (instance_ == NULL) { | 1095 if (instance_ == NULL) { |
| 1096 // Start a thread that will send SIGPROF signal to VM threads, | 1096 // Start a thread that will send SIGPROF signal to VM threads, |
| 1097 // when CPU profiling will be enabled. | 1097 // when CPU profiling will be enabled. |
| 1098 instance_ = new SignalSender(sampler->interval()); | 1098 instance_ = new SignalSender(sampler->interval()); |
| 1099 instance_->Start(); | 1099 instance_->Start(); |
| 1100 } else { | 1100 } else { |
| 1101 ASSERT(instance_->interval_ == sampler->interval()); | 1101 ASSERT(instance_->interval_ == sampler->interval()); |
| 1102 } | 1102 } |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 static void RemoveActiveSampler(Sampler* sampler) { | 1105 static void RemoveActiveSampler(Sampler* sampler) { |
| 1106 ScopedLock lock(mutex_); | 1106 ScopedLock lock(mutex_.Pointer()); |
| 1107 SamplerRegistry::RemoveActiveSampler(sampler); | 1107 SamplerRegistry::RemoveActiveSampler(sampler); |
| 1108 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 1108 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 1109 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 1109 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 1110 delete instance_; | 1110 delete instance_; |
| 1111 instance_ = NULL; | 1111 instance_ = NULL; |
| 1112 RestoreSignalHandler(); | 1112 RestoreSignalHandler(); |
| 1113 } | 1113 } |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 // Implement Thread::Run(). | 1116 // Implement Thread::Run(). |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 #endif // DEBUG | 1199 #endif // DEBUG |
| 1200 USE(result); | 1200 USE(result); |
| 1201 #endif // ANDROID | 1201 #endif // ANDROID |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 const int vm_tgid_; | 1204 const int vm_tgid_; |
| 1205 const int interval_; | 1205 const int interval_; |
| 1206 RuntimeProfilerRateLimiter rate_limiter_; | 1206 RuntimeProfilerRateLimiter rate_limiter_; |
| 1207 | 1207 |
| 1208 // Protects the process wide state below. | 1208 // Protects the process wide state below. |
| 1209 static Mutex* mutex_; | 1209 static LazyMutex mutex_; |
| 1210 static SignalSender* instance_; | 1210 static SignalSender* instance_; |
| 1211 static bool signal_handler_installed_; | 1211 static bool signal_handler_installed_; |
| 1212 static struct sigaction old_signal_handler_; | 1212 static struct sigaction old_signal_handler_; |
| 1213 | 1213 |
| 1214 private: | 1214 private: |
| 1215 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 1215 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
| 1216 }; | 1216 }; |
| 1217 | 1217 |
| 1218 | 1218 |
| 1219 Mutex* SignalSender::mutex_ = OS::CreateMutex(); | 1219 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; |
| 1220 SignalSender* SignalSender::instance_ = NULL; | 1220 SignalSender* SignalSender::instance_ = NULL; |
| 1221 struct sigaction SignalSender::old_signal_handler_; | 1221 struct sigaction SignalSender::old_signal_handler_; |
| 1222 bool SignalSender::signal_handler_installed_ = false; | 1222 bool SignalSender::signal_handler_installed_ = false; |
| 1223 | 1223 |
| 1224 | 1224 |
| 1225 Sampler::Sampler(Isolate* isolate, int interval) | 1225 Sampler::Sampler(Isolate* isolate, int interval) |
| 1226 : isolate_(isolate), | 1226 : isolate_(isolate), |
| 1227 interval_(interval), | 1227 interval_(interval), |
| 1228 profiling_(false), | 1228 profiling_(false), |
| 1229 active_(false), | 1229 active_(false), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1246 | 1246 |
| 1247 | 1247 |
| 1248 void Sampler::Stop() { | 1248 void Sampler::Stop() { |
| 1249 ASSERT(IsActive()); | 1249 ASSERT(IsActive()); |
| 1250 SignalSender::RemoveActiveSampler(this); | 1250 SignalSender::RemoveActiveSampler(this); |
| 1251 SetActive(false); | 1251 SetActive(false); |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 | 1254 |
| 1255 } } // namespace v8::internal | 1255 } } // namespace v8::internal |
| OLD | NEW |