OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/profiling.h" | 5 #include "chrome/common/profiling.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/profiler.h" | 10 #include "base/debug/profiler.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 std::string GetProfileName() { | 18 std::string GetProfileName() { |
19 static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}"; | 19 static const char kDefaultProfileName[] = "chrome-profile-{type}-{pid}"; |
20 static std::string profile_name; | 20 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); |
21 | 21 |
22 if (profile_name.empty()) { | 22 if (profile_name.empty()) { |
23 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 23 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
24 if (command_line.HasSwitch(switches::kProfilingFile)) | 24 if (command_line.HasSwitch(switches::kProfilingFile)) |
25 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); | 25 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); |
26 else | 26 else |
27 profile_name = std::string(kDefaultProfileName); | 27 profile_name = std::string(kDefaultProfileName); |
28 std::string process_type = | 28 std::string process_type = |
29 command_line.GetSwitchValueASCII(switches::kProcessType); | 29 command_line.GetSwitchValueASCII(switches::kProcessType); |
30 std::string type = process_type.empty() ? | 30 std::string type = process_type.empty() ? |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return base::debug::BeingProfiled(); | 132 return base::debug::BeingProfiled(); |
133 } | 133 } |
134 | 134 |
135 // static | 135 // static |
136 void Profiling::Toggle() { | 136 void Profiling::Toggle() { |
137 if (BeingProfiled()) | 137 if (BeingProfiled()) |
138 Stop(); | 138 Stop(); |
139 else | 139 else |
140 Start(); | 140 Start(); |
141 } | 141 } |
OLD | NEW |