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

Side by Side Diff: base/profiler/scoped_profile.h

Issue 2695833004: Use TRACK_RUN_IN_THIS_SCOPED_REGION for heap profiler (Closed)
Patch Set: fix comment. Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 5
6 #ifndef BASE_PROFILER_SCOPED_PROFILE_H_ 6 #ifndef BASE_PROFILER_SCOPED_PROFILE_H_
7 #define BASE_PROFILER_SCOPED_PROFILE_H_ 7 #define BASE_PROFILER_SCOPED_PROFILE_H_
8 8
9 //------------------------------------------------------------------------------ 9 //------------------------------------------------------------------------------
10 // ScopedProfile provides basic helper functions for profiling a short 10 // ScopedProfile provides basic helper functions for profiling a short
11 // region of code within a scope. It is separate from the related ThreadData 11 // region of code within a scope. It is separate from the related ThreadData
12 // class so that it can be included without much other cruft, and provide the 12 // class so that it can be included without much other cruft, and provide the
13 // macros listed below. 13 // macros listed below.
14 14
15 #include "base/base_export.h" 15 #include "base/base_export.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/profiler/tracked_time.h" 18 #include "base/profiler/tracked_time.h"
19 #include "base/trace_event/heap_profiler.h"
19 #include "base/tracked_objects.h" 20 #include "base/tracked_objects.h"
20 21
21 #define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line 22 // Two level indirection is required for correct macro substitution.
23 #define PASTE_COUNTER_ON_NAME2(name, counter) name##counter
24 #define PASTE_COUNTER_ON_NAME(name, counter) \
25 PASTE_COUNTER_ON_NAME2(name, counter)
22 26
23 #define LINE_BASED_VARIABLE_NAME_FOR_PROFILING \ 27 #define COUNTER_BASED_VARIABLE_NAME_FOR_PROFILING \
24 PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__) 28 PASTE_COUNTER_ON_NAME(some_profiler_variable_, __COUNTER__)
25 29
26 // Defines the containing scope as a profiled region. This allows developers to 30 // Defines the containing scope as a profiled region. This allows developers to
27 // profile their code and see results on their about:profiler page, as well as 31 // profile their code and see results on their about:profiler page, as well as
28 // on the UMA dashboard. 32 // on the UMA dashboard and heap profiler.
29 #define TRACK_RUN_IN_THIS_SCOPED_REGION(dispatch_function_name) \ 33 #define TRACK_RUN_IN_THIS_SCOPED_REGION(dispatch_function_name) \
30 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \ 34 const ::tracked_objects::Location& location = \
31 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name), \ 35 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name); \
32 ::tracked_objects::ScopedProfile::ENABLED) 36 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION \
37 COUNTER_BASED_VARIABLE_NAME_FOR_PROFILING(location.file_name()); \
38 ::tracked_objects::ScopedProfile COUNTER_BASED_VARIABLE_NAME_FOR_PROFILING( \
39 location, ::tracked_objects::ScopedProfile::ENABLED)
33 40
34 // Same as TRACK_RUN_IN_THIS_SCOPED_REGION except that there's an extra param 41 // Same as TRACK_RUN_IN_THIS_SCOPED_REGION except that there's an extra param
35 // which is concatenated with the function name for better filtering. 42 // which is concatenated with the function name for better filtering.
36 #define TRACK_SCOPED_REGION(category_name, dispatch_function_name) \ 43 #define TRACK_SCOPED_REGION(category_name, dispatch_function_name) \
37 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \ 44 const ::tracked_objects::Location& location = \
38 FROM_HERE_WITH_EXPLICIT_FUNCTION( \ 45 FROM_HERE_WITH_EXPLICIT_FUNCTION("[" category_name \
39 "[" category_name "]" dispatch_function_name), \ 46 "]" dispatch_function_name); \
40 ::tracked_objects::ScopedProfile::ENABLED) 47 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION \
48 COUNTER_BASED_VARIABLE_NAME_FOR_PROFILING(location.file_name()); \
49 ::tracked_objects::ScopedProfile COUNTER_BASED_VARIABLE_NAME_FOR_PROFILING( \
50 location, ::tracked_objects::ScopedProfile::ENABLED)
41 51
42 namespace tracked_objects { 52 namespace tracked_objects {
43 class Births; 53 class Births;
44 54
45 class BASE_EXPORT ScopedProfile { 55 class BASE_EXPORT ScopedProfile {
46 public: 56 public:
47 // Mode of operation. Specifies whether ScopedProfile should be a no-op or 57 // Mode of operation. Specifies whether ScopedProfile should be a no-op or
48 // needs to create and tally a task. 58 // needs to create and tally a task.
49 enum Mode { 59 enum Mode {
50 DISABLED, // Do nothing. 60 DISABLED, // Do nothing.
51 ENABLED // Create and tally a task. 61 ENABLED // Create and tally a task.
52 }; 62 };
53 63
54 ScopedProfile(const Location& location, Mode mode); 64 ScopedProfile(const Location& location, Mode mode);
55 ~ScopedProfile(); 65 ~ScopedProfile();
56 66
57 private: 67 private:
58 Births* birth_; // Place in code where tracking started. 68 Births* birth_; // Place in code where tracking started.
59 TaskStopwatch stopwatch_; 69 TaskStopwatch stopwatch_;
60 70
61 DISALLOW_COPY_AND_ASSIGN(ScopedProfile); 71 DISALLOW_COPY_AND_ASSIGN(ScopedProfile);
62 }; 72 };
63 73
64 } // namespace tracked_objects 74 } // namespace tracked_objects
65 75
66 #endif // BASE_PROFILER_SCOPED_PROFILE_H_ 76 #endif // BASE_PROFILER_SCOPED_PROFILE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698