Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: src/platform-linux.cc

Issue 6993057: Version 3.4.2 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform.h ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 enum SleepInterval { 972 enum SleepInterval {
973 HALF_INTERVAL, 973 HALF_INTERVAL,
974 FULL_INTERVAL 974 FULL_INTERVAL
975 }; 975 };
976 976
977 explicit SignalSender(int interval) 977 explicit SignalSender(int interval)
978 : Thread(NULL, "SignalSender"), 978 : Thread(NULL, "SignalSender"),
979 vm_tgid_(getpid()), 979 vm_tgid_(getpid()),
980 interval_(interval) {} 980 interval_(interval) {}
981 981
982 static void InstallSignalHandler() {
983 struct sigaction sa;
984 sa.sa_sigaction = ProfilerSignalHandler;
985 sigemptyset(&sa.sa_mask);
986 sa.sa_flags = SA_RESTART | SA_SIGINFO;
987 signal_handler_installed_ =
988 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
989 }
990
991 static void RestoreSignalHandler() {
992 if (signal_handler_installed_) {
993 sigaction(SIGPROF, &old_signal_handler_, 0);
994 signal_handler_installed_ = false;
995 }
996 }
997
982 static void AddActiveSampler(Sampler* sampler) { 998 static void AddActiveSampler(Sampler* sampler) {
983 ScopedLock lock(mutex_); 999 ScopedLock lock(mutex_);
984 SamplerRegistry::AddActiveSampler(sampler); 1000 SamplerRegistry::AddActiveSampler(sampler);
985 if (instance_ == NULL) { 1001 if (instance_ == NULL) {
986 // Install a signal handler. 1002 // Start a thread that will send SIGPROF signal to VM threads,
987 struct sigaction sa; 1003 // when CPU profiling will be enabled.
988 sa.sa_sigaction = ProfilerSignalHandler;
989 sigemptyset(&sa.sa_mask);
990 sa.sa_flags = SA_RESTART | SA_SIGINFO;
991 signal_handler_installed_ =
992 (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
993
994 // Start a thread that sends SIGPROF signal to VM threads.
995 instance_ = new SignalSender(sampler->interval()); 1004 instance_ = new SignalSender(sampler->interval());
996 instance_->Start(); 1005 instance_->Start();
997 } else { 1006 } else {
998 ASSERT(instance_->interval_ == sampler->interval()); 1007 ASSERT(instance_->interval_ == sampler->interval());
999 } 1008 }
1000 } 1009 }
1001 1010
1002 static void RemoveActiveSampler(Sampler* sampler) { 1011 static void RemoveActiveSampler(Sampler* sampler) {
1003 ScopedLock lock(mutex_); 1012 ScopedLock lock(mutex_);
1004 SamplerRegistry::RemoveActiveSampler(sampler); 1013 SamplerRegistry::RemoveActiveSampler(sampler);
1005 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) { 1014 if (SamplerRegistry::GetState() == SamplerRegistry::HAS_NO_SAMPLERS) {
1006 RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown(); 1015 RuntimeProfiler::WakeUpRuntimeProfilerThreadBeforeShutdown();
1007 instance_->Join(); 1016 instance_->Join();
1008 delete instance_; 1017 delete instance_;
1009 instance_ = NULL; 1018 instance_ = NULL;
1010 1019 RestoreSignalHandler();
1011 // Restore the old signal handler.
1012 if (signal_handler_installed_) {
1013 sigaction(SIGPROF, &old_signal_handler_, 0);
1014 signal_handler_installed_ = false;
1015 }
1016 } 1020 }
1017 } 1021 }
1018 1022
1019 // Implement Thread::Run(). 1023 // Implement Thread::Run().
1020 virtual void Run() { 1024 virtual void Run() {
1021 SamplerRegistry::State state; 1025 SamplerRegistry::State state;
1022 while ((state = SamplerRegistry::GetState()) != 1026 while ((state = SamplerRegistry::GetState()) !=
1023 SamplerRegistry::HAS_NO_SAMPLERS) { 1027 SamplerRegistry::HAS_NO_SAMPLERS) {
1024 bool cpu_profiling_enabled = 1028 bool cpu_profiling_enabled =
1025 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); 1029 (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
1026 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); 1030 bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
1031 if (cpu_profiling_enabled && !signal_handler_installed_) {
1032 InstallSignalHandler();
1033 } else if (!cpu_profiling_enabled && signal_handler_installed_) {
1034 RestoreSignalHandler();
1035 }
1027 // When CPU profiling is enabled both JavaScript and C++ code is 1036 // When CPU profiling is enabled both JavaScript and C++ code is
1028 // profiled. We must not suspend. 1037 // profiled. We must not suspend.
1029 if (!cpu_profiling_enabled) { 1038 if (!cpu_profiling_enabled) {
1030 if (rate_limiter_.SuspendIfNecessary()) continue; 1039 if (rate_limiter_.SuspendIfNecessary()) continue;
1031 } 1040 }
1032 if (cpu_profiling_enabled && runtime_profiler_enabled) { 1041 if (cpu_profiling_enabled && runtime_profiler_enabled) {
1033 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { 1042 if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) {
1034 return; 1043 return;
1035 } 1044 }
1036 Sleep(HALF_INTERVAL); 1045 Sleep(HALF_INTERVAL);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 1149
1141 void Sampler::Stop() { 1150 void Sampler::Stop() {
1142 ASSERT(IsActive()); 1151 ASSERT(IsActive());
1143 SignalSender::RemoveActiveSampler(this); 1152 SignalSender::RemoveActiveSampler(this);
1144 SetActive(false); 1153 SetActive(false);
1145 } 1154 }
1146 1155
1147 #endif // ENABLE_LOGGING_AND_PROFILING 1156 #endif // ENABLE_LOGGING_AND_PROFILING
1148 1157
1149 } } // namespace v8::internal 1158 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698