| 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 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 static void RestoreSignalHandler() { | 1079 static void RestoreSignalHandler() { |
| 1080 if (signal_handler_installed_) { | 1080 if (signal_handler_installed_) { |
| 1081 sigaction(SIGPROF, &old_signal_handler_, 0); | 1081 sigaction(SIGPROF, &old_signal_handler_, 0); |
| 1082 signal_handler_installed_ = false; | 1082 signal_handler_installed_ = false; |
| 1083 } | 1083 } |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 static void AddActiveSampler(Sampler* sampler) { | 1086 static void AddActiveSampler(Sampler* sampler) { |
| 1087 ScopedLock lock(mutex_); | 1087 ScopedLock lock(mutex_.Pointer()); |
| 1088 SamplerRegistry::AddActiveSampler(sampler); | 1088 SamplerRegistry::AddActiveSampler(sampler); |
| 1089 if (instance_ == NULL) { | 1089 if (instance_ == NULL) { |
| 1090 // Start a thread that will send SIGPROF signal to VM threads, | 1090 // Start a thread that will send SIGPROF signal to VM threads, |
| 1091 // when CPU profiling will be enabled. | 1091 // when CPU profiling will be enabled. |
| 1092 instance_ = new SignalSender(sampler->interval()); | 1092 instance_ = new SignalSender(sampler->interval()); |
| 1093 instance_->Start(); | 1093 instance_->Start(); |
| 1094 } else { | 1094 } else { |
| 1095 ASSERT(instance_->interval_ == sampler->interval()); | 1095 ASSERT(instance_->interval_ == sampler->interval()); |
| 1096 } | 1096 } |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 static void RemoveActiveSampler(Sampler* sampler) { | 1099 static void RemoveActiveSampler(Sampler* sampler) { |
| 1100 ScopedLock lock(mutex_); | 1100 ScopedLock lock(mutex_.Pointer()); |
| 1101 SamplerRegistry::RemoveActiveSampler(sampler); | 1101 SamplerRegistry::RemoveActiveSampler(sampler); |
| 1102 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 1102 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 1103 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 1103 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 1104 delete instance_; | 1104 delete instance_; |
| 1105 instance_ = NULL; | 1105 instance_ = NULL; |
| 1106 RestoreSignalHandler(); | 1106 RestoreSignalHandler(); |
| 1107 } | 1107 } |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 // Implement Thread::Run(). | 1110 // Implement Thread::Run(). |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 #endif // DEBUG | 1193 #endif // DEBUG |
| 1194 USE(result); | 1194 USE(result); |
| 1195 #endif // ANDROID | 1195 #endif // ANDROID |
| 1196 } | 1196 } |
| 1197 | 1197 |
| 1198 const int vm_tgid_; | 1198 const int vm_tgid_; |
| 1199 const int interval_; | 1199 const int interval_; |
| 1200 RuntimeProfilerRateLimiter rate_limiter_; | 1200 RuntimeProfilerRateLimiter rate_limiter_; |
| 1201 | 1201 |
| 1202 // Protects the process wide state below. | 1202 // Protects the process wide state below. |
| 1203 static Mutex* mutex_; | 1203 static LazyMutex mutex_; |
| 1204 static SignalSender* instance_; | 1204 static SignalSender* instance_; |
| 1205 static bool signal_handler_installed_; | 1205 static bool signal_handler_installed_; |
| 1206 static struct sigaction old_signal_handler_; | 1206 static struct sigaction old_signal_handler_; |
| 1207 | 1207 |
| 1208 private: | 1208 private: |
| 1209 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 1209 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
| 1210 }; | 1210 }; |
| 1211 | 1211 |
| 1212 | 1212 |
| 1213 Mutex* SignalSender::mutex_ = OS::CreateMutex(); | 1213 LazyMutex SignalSender::mutex_ = LAZY_MUTEX_INITIALIZER; |
| 1214 SignalSender* SignalSender::instance_ = NULL; | 1214 SignalSender* SignalSender::instance_ = NULL; |
| 1215 struct sigaction SignalSender::old_signal_handler_; | 1215 struct sigaction SignalSender::old_signal_handler_; |
| 1216 bool SignalSender::signal_handler_installed_ = false; | 1216 bool SignalSender::signal_handler_installed_ = false; |
| 1217 | 1217 |
| 1218 | 1218 |
| 1219 Sampler::Sampler(Isolate* isolate, int interval) | 1219 Sampler::Sampler(Isolate* isolate, int interval) |
| 1220 : isolate_(isolate), | 1220 : isolate_(isolate), |
| 1221 interval_(interval), | 1221 interval_(interval), |
| 1222 profiling_(false), | 1222 profiling_(false), |
| 1223 active_(false), | 1223 active_(false), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1240 | 1240 |
| 1241 | 1241 |
| 1242 void Sampler::Stop() { | 1242 void Sampler::Stop() { |
| 1243 ASSERT(IsActive()); | 1243 ASSERT(IsActive()); |
| 1244 SignalSender::RemoveActiveSampler(this); | 1244 SignalSender::RemoveActiveSampler(this); |
| 1245 SetActive(false); | 1245 SetActive(false); |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 | 1248 |
| 1249 } } // namespace v8::internal | 1249 } } // namespace v8::internal |
| OLD | NEW |