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"
19
#if defined(GOOGLE_CHROME_BUILD)
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) \
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))
37
#define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line
39
#define LINE_BASED_VARIABLE_NAME_FOR_PROFILING \
40
PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__)
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))
47
namespace tracked_objects {
50
class BASE_EXPORT ScopedProfile {
52
explicit ScopedProfile(const Location& location);
55
// Stop tracing prior to the end destruction of the instance.
56
void StopClockAndTally();
59
Births* birth_; // Place in code where tracking started.
60
const TrackedTime start_of_run_;
62
DISALLOW_COPY_AND_ASSIGN(ScopedProfile);
65
} // namespace tracked_objects
67
#endif // BASE_PROFILER_SCOPED_PROFILE_H_