OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/profiler/scoped_tracker.h" | 5 #include "base/profiler/scoped_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 | |
7 namespace tracked_objects { | 9 namespace tracked_objects { |
8 | 10 |
9 namespace { | 11 namespace { |
10 | 12 |
11 ScopedProfile::Mode g_scoped_profile_mode = ScopedProfile::DISABLED; | 13 ScopedProfile::Mode g_scoped_profile_mode = ScopedProfile::DISABLED; |
12 | 14 |
15 // Executes |callback|, augmenting it with provided |location|. | |
16 void ExecuteAndAugmentCallback(const Location& location, | |
Ilya Sherman
2014/10/29 00:23:00
nit: I find the "augment" part of this name confus
vadimt
2014/10/29 00:52:21
Done.
| |
17 const base::Closure& callback) { | |
18 ScopedProfile tracking_profile(location); | |
Ilya Sherman
2014/10/29 00:23:00
Hmm, why not use a ScopedTracker here instead?
vadimt
2014/10/29 00:52:21
ScopedTracker checks if tracking is enabled and ca
Ilya Sherman
2014/10/29 00:57:12
My point is: Why does TrackCallback check g_scoped
vadimt
2014/10/29 17:47:29
This allows me to totally skip creating/destroying
Ilya Sherman
2014/10/30 00:51:35
I think this is unnecessary optimization that redu
| |
19 callback.Run(); | |
20 } | |
21 | |
13 } // namespace | 22 } // namespace |
14 | 23 |
15 // static | 24 // static |
16 void ScopedTracker::Enable() { | 25 void ScopedTracker::Enable() { |
17 g_scoped_profile_mode = ScopedProfile::ENABLED; | 26 g_scoped_profile_mode = ScopedProfile::ENABLED; |
18 } | 27 } |
19 | 28 |
29 // static | |
30 base::Closure ScopedTracker::TrackCallback(const Location& location, | |
31 const base::Closure& callback) { | |
32 if (g_scoped_profile_mode != ScopedProfile::ENABLED) | |
33 return callback; | |
34 | |
35 return base::Bind(ExecuteAndAugmentCallback, location, callback); | |
36 } | |
37 | |
20 ScopedTracker::ScopedTracker(const Location& location) | 38 ScopedTracker::ScopedTracker(const Location& location) |
21 : scoped_profile_(location, g_scoped_profile_mode) { | 39 : scoped_profile_(location, g_scoped_profile_mode) { |
22 } | 40 } |
23 | 41 |
24 } // namespace tracked_objects | 42 } // namespace tracked_objects |
OLD | NEW |