BuildCache
perf_utils.hpp
1 //--------------------------------------------------------------------------------------------------
2 // Copyright (c) 2018 Marcus Geelnard
3 //
4 // This software is provided 'as-is', without any express or implied warranty. In no event will the
5 // authors be held liable for any damages arising from the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose, including commercial
8 // applications, and to alter it and redistribute it freely, subject to the following restrictions:
9 //
10 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote
11 // the original software. If you use this software in a product, an acknowledgment in the
12 // product documentation would be appreciated but is not required.
13 //
14 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
15 // being the original software.
16 //
17 // 3. This notice may not be removed or altered from any source distribution.
18 //--------------------------------------------------------------------------------------------------
19 
20 #ifndef BUILDCACHE_PERF_UTILS_HPP_
21 #define BUILDCACHE_PERF_UTILS_HPP_
22 
23 #include <cstdint>
24 
25 namespace bcache {
26 namespace perf {
28 enum id_t {
29  ID_FIND_EXECUTABLE = 0,
30  ID_FIND_WRAPPER = 1,
31  ID_LUA_INIT = 2,
32  ID_LUA_LOAD_SCRIPT = 3,
33  ID_LUA_RUN = 4,
34  ID_RESOLVE_ARGS = 5,
35  ID_GET_CAPABILITIES = 6,
36  ID_PREPROCESS = 7,
37  ID_FILTER_ARGS = 8,
38  ID_GET_PRG_ID = 9,
39  ID_CACHE_LOOKUP = 10,
40  ID_RETRIEVE_CACHED_FILES = 11,
41  ID_GET_BUILD_FILES = 12,
42  ID_RUN_FOR_MISS = 13,
43  ID_ADD_TO_CACHE = 14,
44  ID_RUN_FOR_FALLBACK = 15,
45  ID_UPDATE_STATS = 16,
46  ID_TOTAL = 17,
47  ID_HASH_EXTRA_FILES = 18,
48  ID_HASH_INPUT_FILES = 19,
49  ID_HASH_INCLUDE_FILES = 20,
50  NUM_PERF_IDS
51 };
52 
55 int64_t start();
56 
60 void stop(const int64_t start_time, const id_t id);
61 
63 void report();
64 
66 class perf_scope_t {
67 public:
68  perf_scope_t(const id_t id) : m_id(id), m_t0(start()) {
69  }
70 
71  ~perf_scope_t() {
72  stop(m_t0, m_id);
73  }
74 
75 private:
76  const id_t m_id;
77  const int64_t m_t0;
78 };
79 } // namespace perf
80 } // namespace bcache
81 
82 // Convenience macros.
83 #define PERF_START(id) const auto t0_ID_##id = bcache::perf::start()
84 #define PERF_STOP(id) bcache::perf::stop(t0_ID_##id, bcache::perf::ID_##id)
85 #define PERF_SCOPE(id) bcache::perf::perf_scope_t p_ID_##id(bcache::perf::ID_##id)
86 
87 #endif // BUILDCACHE_PERF_UTILS_HPP_
bcache::perf::report
void report()
Report the results.
Definition: perf_utils.cpp:74
bcache::perf::start
int64_t start()
Start measuring time.
Definition: perf_utils.cpp:65
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::perf::perf_scope_t
A scoped perf logger.
Definition: perf_utils.hpp:66
bcache::perf::id_t
id_t
Recognized instrumentation IDs.
Definition: perf_utils.hpp:28
bcache::perf::stop
void stop(const int64_t start_time, const id_t id)
Stop measuring time.
Definition: perf_utils.cpp:69
bcache::config::perf
bool perf()
Definition: configuration.cpp:660