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 #ifndef BASE_PROFILER_SCOPED_TRACKER_H_ | 5 #ifndef BASE_PROFILER_SCOPED_TRACKER_H_ |
6 #define BASE_PROFILER_SCOPED_TRACKER_H_ | 6 #define BASE_PROFILER_SCOPED_TRACKER_H_ |
7 | 7 |
8 //------------------------------------------------------------------------------ | 8 //------------------------------------------------------------------------------ |
9 // Utilities for temporarily instrumenting code to dig into issues that were | 9 // Utilities for temporarily instrumenting code to dig into issues that were |
10 // found using profiler data. | 10 // found using profiler data. |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 13 #include "base/bind.h" |
13 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
14 #include "base/location.h" | 15 #include "base/location.h" |
15 #include "base/profiler/scoped_profile.h" | 16 #include "base/profiler/scoped_profile.h" |
16 | 17 |
17 namespace tracked_objects { | 18 namespace tracked_objects { |
18 | 19 |
19 // ScopedTracker instruments a region within the code if the instrumentation is | 20 // ScopedTracker instruments a region within the code if the instrumentation is |
20 // enabled. It can be used, for example, to find out if a source of jankiness is | 21 // enabled. It can be used, for example, to find out if a source of jankiness is |
21 // inside the instrumented code region. | 22 // inside the instrumented code region. |
22 // Details: | 23 // Details: |
(...skipping 17 matching lines...) Expand all Loading... |
40 | 41 |
41 // Enables instrumentation for the remainder of the current process' life. If | 42 // Enables instrumentation for the remainder of the current process' life. If |
42 // this function is not called, all profiler instrumentations are no-ops. | 43 // this function is not called, all profiler instrumentations are no-ops. |
43 static void Enable(); | 44 static void Enable(); |
44 | 45 |
45 // Augments a |callback| with provided |location|. This is useful for | 46 // Augments a |callback| with provided |location|. This is useful for |
46 // instrumenting cases when we know that a jank is in a callback and there are | 47 // instrumenting cases when we know that a jank is in a callback and there are |
47 // many possible callbacks, but they come from a relatively small number of | 48 // many possible callbacks, but they come from a relatively small number of |
48 // places. We can instrument these few places and at least know which one | 49 // places. We can instrument these few places and at least know which one |
49 // passes the janky callback. | 50 // passes the janky callback. |
50 static base::Closure TrackCallback(const Location& location, | 51 template <typename P1> |
51 const base::Closure& callback); | 52 static base::Callback<void(P1)> TrackCallback( |
| 53 const Location& location, |
| 54 const base::Callback<void(P1)>& callback) { |
| 55 return base::Bind(&ScopedTracker::ExecuteAndTrackCallback<P1>, location, |
| 56 callback); |
| 57 } |
52 | 58 |
53 private: | 59 private: |
| 60 // Executes |callback|, augmenting it with provided |location|. |
| 61 template <typename P1> |
| 62 static void ExecuteAndTrackCallback(const Location& location, |
| 63 const base::Callback<void(P1)>& callback, |
| 64 P1 p1) { |
| 65 ScopedTracker tracking_profile(location); |
| 66 callback.Run(p1); |
| 67 } |
| 68 |
54 const ScopedProfile scoped_profile_; | 69 const ScopedProfile scoped_profile_; |
55 | 70 |
56 DISALLOW_COPY_AND_ASSIGN(ScopedTracker); | 71 DISALLOW_COPY_AND_ASSIGN(ScopedTracker); |
57 }; | 72 }; |
58 | 73 |
59 } // namespace tracked_objects | 74 } // namespace tracked_objects |
60 | 75 |
61 #endif // BASE_PROFILER_SCOPED_TRACKER_H_ | 76 #endif // BASE_PROFILER_SCOPED_TRACKER_H_ |
OLD | NEW |