-
Notifications
You must be signed in to change notification settings - Fork 499
/
Profile.h
57 lines (47 loc) · 1.2 KB
/
Profile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <string>
namespace fl {
namespace detail {
/**
* An RAII abstraction to start and stop profiling recording.
*/
class ScopedProfiler {
public:
ScopedProfiler();
~ScopedProfiler();
};
/**
* An RAII abstractiont to label a profile interval over the lifetime for an
object given a specific scope. For example:
* \code
{
ProfileTracer tr("myOperation");
// some code which does stuff and will be labeled
// as myOperation
}
* \endcode
*/
class ProfileTracer {
public:
explicit ProfileTracer(const std::string& name);
~ProfileTracer();
};
} // namespace detail
} // namespace fl
#if FL_BUILD_PROFILING
// Used to generate a unique name for the expansion
#define _FL_PROFILE_CAT(a, b) a##b
#define FL_PROFILE_TRACE(name) \
fl::detail::ProfileTracer _FL_PROFILE_CAT(profileTracer, __LINE__)(name);
#define FL_SCOPED_PROFILE() \
fl::detail::ScopedProfiler _FL_PROFILE_CAT(scopedProfile, __LINE__);
#else
#define FL_PROFILE_TRACE(_)
#define FL_SCOPED_PROFILE()
#endif