| 1 | //
|
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
|
|---|
| 3 | //
|
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
|---|
| 5 | // file "LICENCE" distributed with Cforall.
|
|---|
| 6 | //
|
|---|
| 7 | // Time.hpp --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Thierry Delisle
|
|---|
| 10 | // Created On : Fri Mar 01 15:14:11 2019
|
|---|
| 11 | // Last Modified By : Andrew Beach
|
|---|
| 12 | // Last Modified On :
|
|---|
| 13 | // Update Count :
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include "Common/Stats/Base.hpp"
|
|---|
| 19 |
|
|---|
| 20 | #if defined( NO_STATISTICS )
|
|---|
| 21 | #define NO_TIME_STATISTICS
|
|---|
| 22 | #endif
|
|---|
| 23 |
|
|---|
| 24 | namespace Stats {
|
|---|
| 25 | namespace Time {
|
|---|
| 26 | # if defined(NO_TIME_STATISTICS)
|
|---|
| 27 | inline void StartGlobal() {}
|
|---|
| 28 |
|
|---|
| 29 | inline void StartBlock(const char * const) {}
|
|---|
| 30 | inline void StopBlock() {}
|
|---|
| 31 |
|
|---|
| 32 | inline void print() {}
|
|---|
| 33 |
|
|---|
| 34 | struct BlockGuard {
|
|---|
| 35 | BlockGuard(const char * const) {}
|
|---|
| 36 | ~BlockGuard() {}
|
|---|
| 37 | };
|
|---|
| 38 |
|
|---|
| 39 | template<typename func_t>
|
|---|
| 40 | inline void TimeBlock(const char *, func_t f) {
|
|---|
| 41 | f();
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | template<typename ret_t = void, typename func_t, typename... arg_t>
|
|---|
| 45 | inline ret_t TimeCall(
|
|---|
| 46 | const char *, func_t func, arg_t&&... arg) {
|
|---|
| 47 | return func(std::forward<arg_t>(arg)...);
|
|---|
| 48 | }
|
|---|
| 49 | # else
|
|---|
| 50 | void StartGlobal();
|
|---|
| 51 |
|
|---|
| 52 | void StartBlock(const char * const name);
|
|---|
| 53 | void StopBlock();
|
|---|
| 54 |
|
|---|
| 55 | void print();
|
|---|
| 56 |
|
|---|
| 57 | struct BlockGuard {
|
|---|
| 58 | BlockGuard(const char * const name ) { StartBlock(name); }
|
|---|
| 59 | ~BlockGuard() { StopBlock(); }
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 | template<typename func_t>
|
|---|
| 63 | inline void TimeBlock(const char * name, func_t func) {
|
|---|
| 64 | BlockGuard guard(name);
|
|---|
| 65 | func();
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | template<typename ret_t = void, typename func_t, typename... arg_t>
|
|---|
| 69 | inline ret_t TimeCall(
|
|---|
| 70 | const char * name, func_t func, arg_t&&... arg) {
|
|---|
| 71 | BlockGuard guard(name);
|
|---|
| 72 | return func(std::forward<arg_t>(arg)...);
|
|---|
| 73 | }
|
|---|
| 74 | # endif
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|