Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 class SignalSender : public Thread { | 1031 class SignalSender : public Thread { |
| 1032 public: | 1032 public: |
| 1033 enum SleepInterval { | 1033 enum SleepInterval { |
| 1034 HALF_INTERVAL, | 1034 HALF_INTERVAL, |
| 1035 FULL_INTERVAL | 1035 FULL_INTERVAL |
| 1036 }; | 1036 }; |
| 1037 | 1037 |
| 1038 explicit SignalSender(int interval) | 1038 explicit SignalSender(int interval) |
| 1039 : Thread("SignalSender"), | 1039 : Thread("SignalSender"), |
| 1040 vm_tgid_(getpid()), | 1040 vm_tgid_(getpid()), |
| 1041 interval_(interval) {} | 1041 interval_(interval), |
| 1042 tick_count_(0) {} | |
| 1042 | 1043 |
| 1043 static void InstallSignalHandler() { | 1044 static void InstallSignalHandler() { |
| 1044 struct sigaction sa; | 1045 struct sigaction sa; |
| 1045 sa.sa_sigaction = ProfilerSignalHandler; | 1046 sa.sa_sigaction = ProfilerSignalHandler; |
| 1046 sigemptyset(&sa.sa_mask); | 1047 sigemptyset(&sa.sa_mask); |
| 1047 sa.sa_flags = SA_RESTART | SA_SIGINFO; | 1048 sa.sa_flags = SA_RESTART | SA_SIGINFO; |
| 1048 signal_handler_installed_ = | 1049 signal_handler_installed_ = |
| 1049 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); | 1050 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); |
| 1050 } | 1051 } |
| 1051 | 1052 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1073 ScopedLock lock(mutex_); | 1074 ScopedLock lock(mutex_); |
| 1074 SamplerRegistry::RemoveActiveSampler(sampler); | 1075 SamplerRegistry::RemoveActiveSampler(sampler); |
| 1075 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { | 1076 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { |
| 1076 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); | 1077 RuntimeProfiler::StopRuntimeProfilerThreadBeforeShutdown(instance_); |
| 1077 delete instance_; | 1078 delete instance_; |
| 1078 instance_ = NULL; | 1079 instance_ = NULL; |
| 1079 RestoreSignalHandler(); | 1080 RestoreSignalHandler(); |
| 1080 } | 1081 } |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1084 static void ResetInterval(int interval) { | |
| 1085 ScopedLock lock(mutex_); | |
| 1086 if (instance_ != NULL) { | |
| 1087 instance_->interval_ = interval; | |
| 1088 instance_->tick_count_ = 0; | |
| 1089 } | |
| 1090 } | |
| 1091 | |
| 1083 // Implement Thread::Run(). | 1092 // Implement Thread::Run(). |
| 1084 virtual void Run() { | 1093 virtual void Run() { |
| 1085 SamplerRegistry::State state; | 1094 SamplerRegistry::State state; |
| 1086 while ((state = SamplerRegistry::GetState()) != | 1095 while ((state = SamplerRegistry::GetState()) != |
| 1087 SamplerRegistry::HAS_NO_SAMPLERS) { | 1096 SamplerRegistry::HAS_NO_SAMPLERS) { |
| 1088 bool cpu_profiling_enabled = | 1097 bool cpu_profiling_enabled = |
| 1089 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); | 1098 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); |
| 1090 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); | 1099 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); |
| 1091 if (cpu_profiling_enabled && !signal_handler_installed_) { | 1100 if (cpu_profiling_enabled && !signal_handler_installed_) { |
| 1092 InstallSignalHandler(); | 1101 InstallSignalHandler(); |
| 1093 } else if (!cpu_profiling_enabled && signal_handler_installed_) { | 1102 } else if (!cpu_profiling_enabled && signal_handler_installed_) { |
| 1094 RestoreSignalHandler(); | 1103 RestoreSignalHandler(); |
| 1095 } | 1104 } |
| 1096 // When CPU profiling is enabled both JavaScript and C++ code is | 1105 // When CPU profiling is enabled both JavaScript and C++ code is |
| 1097 // profiled. We must not suspend. | 1106 // profiled. We must not suspend. |
| 1098 if (!cpu_profiling_enabled) { | 1107 if (!cpu_profiling_enabled) { |
| 1099 if (rate_limiter_.SuspendIfNecessary()) continue; | 1108 if (rate_limiter_.SuspendIfNecessary()) continue; |
| 1100 } | 1109 } |
| 1110 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS) | |
| 1111 // ARM and MIPS CPUs are typically slower than IA32/X64, so for them | |
| 1112 // the tick interval is increased to let them perform a more significant | |
| 1113 // amount of work between subsequent ticks. | |
| 1114 if (tick_count_ == 5) { | |
|
danno
2011/12/07 13:21:52
Constants for these?
Jakob Kummerow
2011/12/12 10:02:38
Done.
| |
| 1115 interval_ = 5; | |
| 1116 } | |
| 1117 tick_count_++; | |
| 1118 #endif | |
| 1101 if (cpu_profiling_enabled && runtime_profiler_enabled) { | 1119 if (cpu_profiling_enabled && runtime_profiler_enabled) { |
| 1102 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { | 1120 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { |
| 1103 return; | 1121 return; |
| 1104 } | 1122 } |
| 1105 Sleep(HALF_INTERVAL); | 1123 Sleep(HALF_INTERVAL); |
| 1106 if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { | 1124 if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { |
| 1107 return; | 1125 return; |
| 1108 } | 1126 } |
| 1109 Sleep(HALF_INTERVAL); | 1127 Sleep(HALF_INTERVAL); |
| 1110 } else { | 1128 } else { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1158 "SignalSender usleep error; interval = %u, errno = %d\n", | 1176 "SignalSender usleep error; interval = %u, errno = %d\n", |
| 1159 interval, | 1177 interval, |
| 1160 errno); | 1178 errno); |
| 1161 ASSERT(result == 0 || errno == EINTR); | 1179 ASSERT(result == 0 || errno == EINTR); |
| 1162 } | 1180 } |
| 1163 #endif | 1181 #endif |
| 1164 USE(result); | 1182 USE(result); |
| 1165 } | 1183 } |
| 1166 | 1184 |
| 1167 const int vm_tgid_; | 1185 const int vm_tgid_; |
| 1168 const int interval_; | 1186 int interval_; |
| 1187 int tick_count_; | |
| 1169 RuntimeProfilerRateLimiter rate_limiter_; | 1188 RuntimeProfilerRateLimiter rate_limiter_; |
| 1170 | 1189 |
| 1171 // Protects the process wide state below. | 1190 // Protects the process wide state below. |
| 1172 static Mutex* mutex_; | 1191 static Mutex* mutex_; |
| 1173 static SignalSender* instance_; | 1192 static SignalSender* instance_; |
| 1174 static bool signal_handler_installed_; | 1193 static bool signal_handler_installed_; |
| 1175 static struct sigaction old_signal_handler_; | 1194 static struct sigaction old_signal_handler_; |
| 1176 | 1195 |
| 1177 DISALLOW_COPY_AND_ASSIGN(SignalSender); | 1196 DISALLOW_COPY_AND_ASSIGN(SignalSender); |
| 1178 }; | 1197 }; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1206 SignalSender::AddActiveSampler(this); | 1225 SignalSender::AddActiveSampler(this); |
| 1207 } | 1226 } |
| 1208 | 1227 |
| 1209 | 1228 |
| 1210 void Sampler::Stop() { | 1229 void Sampler::Stop() { |
| 1211 ASSERT(IsActive()); | 1230 ASSERT(IsActive()); |
| 1212 SignalSender::RemoveActiveSampler(this); | 1231 SignalSender::RemoveActiveSampler(this); |
| 1213 SetActive(false); | 1232 SetActive(false); |
| 1214 } | 1233 } |
| 1215 | 1234 |
| 1235 void Sampler::ResetInterval(int interval) { | |
| 1236 SignalSender::ResetInterval(interval); | |
| 1237 } | |
| 1238 | |
| 1216 | 1239 |
| 1217 } } // namespace v8::internal | 1240 } } // namespace v8::internal |
| OLD | NEW |