Update broken references to image assets
[chromium-blink-merge.git] / base / profiler / scoped_profile.h
blob2c4105d24aa806a3390cc8d5db946f658b49818f
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
3 // found in the LICENSE file.
6 #ifndef BASE_PROFILER_SCOPED_PROFILE_H_
7 #define BASE_PROFILER_SCOPED_PROFILE_H_
9 //------------------------------------------------------------------------------
10 // ScopedProfile provides basic helper functions for profiling a short
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
13 // macros listed below.
15 #include "base/base_export.h"
16 #include "base/location.h"
17 #include "base/profiler/tracked_time.h"
18 #include "base/tracked_objects.h"
20 #define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line
22 #define LINE_BASED_VARIABLE_NAME_FOR_PROFILING \
23 PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__)
25 // Defines the containing scope as a profiled region. This allows developers to
26 // profile their code and see results on their about:profiler page, as well as
27 // on the UMA dashboard.
28 #define TRACK_RUN_IN_THIS_SCOPED_REGION(dispatch_function_name) \
29 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \
30 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name), \
31 ::tracked_objects::ScopedProfile::ENABLED)
33 // Same as TRACK_RUN_IN_THIS_SCOPED_REGION except that there's an extra param
34 // which is concatenated with the function name for better filtering.
35 #define TRACK_SCOPED_REGION(category_name, dispatch_function_name) \
36 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \
37 FROM_HERE_WITH_EXPLICIT_FUNCTION( \
38 "[" category_name "]" dispatch_function_name), \
39 ::tracked_objects::ScopedProfile::ENABLED)
41 namespace tracked_objects {
42 class Births;
44 class BASE_EXPORT ScopedProfile {
45 public:
46 // Mode of operation. Specifies whether ScopedProfile should be a no-op or
47 // needs to create and tally a task.
48 enum Mode {
49 DISABLED, // Do nothing.
50 ENABLED // Create and tally a task.
53 ScopedProfile(const Location& location, Mode mode);
54 ~ScopedProfile();
56 private:
57 Births* birth_; // Place in code where tracking started.
58 TaskStopwatch stopwatch_;
60 DISALLOW_COPY_AND_ASSIGN(ScopedProfile);
63 } // namespace tracked_objects
65 #endif // BASE_PROFILER_SCOPED_PROFILE_H_