• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 
6 #ifndef BASE_PROFILER_SCOPED_PROFILE_H_
7 #define BASE_PROFILER_SCOPED_PROFILE_H_
8 
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.
14 
15 #include "base/base_export.h"
16 #include "base/location.h"
17 #include "base/profiler/tracked_time.h"
18 
19 #if defined(GOOGLE_CHROME_BUILD)
20 
21 // We don't ship these profiled regions.  This is for developer builds only.
22 // It allows developers to do some profiling of their code, and see results on
23 // their about:profiler page.
24 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_DEVELOPER_BUILDS(scope_name)       \
25     ((void)0)
26 
27 #else
28 
29 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_DEVELOPER_BUILDS(scope_name)       \
30     ::tracked_objects::ScopedProfile  LINE_BASED_VARIABLE_NAME_FOR_PROFILING(  \
31         FROM_HERE_WITH_EXPLICIT_FUNCTION(#scope_name))
32 
33 #endif
34 
35 
36 
37 #define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line
38 
39 #define LINE_BASED_VARIABLE_NAME_FOR_PROFILING                                 \
40     PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__)
41 
42 #define TRACK_RUN_IN_IPC_HANDLER(dispatch_function_name)                       \
43     ::tracked_objects::ScopedProfile some_tracking_variable_name(              \
44         FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name))
45 
46 
47 namespace tracked_objects {
48 class Births;
49 
50 class BASE_EXPORT ScopedProfile {
51  public:
52   explicit ScopedProfile(const Location& location);
53   ~ScopedProfile();
54 
55   // Stop tracing prior to the end destruction of the instance.
56   void StopClockAndTally();
57 
58  private:
59   Births* birth_;  // Place in code where tracking started.
60   const TrackedTime start_of_run_;
61 
62   DISALLOW_COPY_AND_ASSIGN(ScopedProfile);
63 };
64 
65 }  // namespace tracked_objects
66 
67 #endif   // BASE_PROFILER_SCOPED_PROFILE_H_
68