OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2015, Google Inc. |
| 4 * All rights reserved. |
| 5 * |
| 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are |
| 8 * met: |
| 9 * |
| 10 * * Redistributions of source code must retain the above copyright |
| 11 * notice, this list of conditions and the following disclaimer. |
| 12 * * Redistributions in binary form must reproduce the above |
| 13 * copyright notice, this list of conditions and the following disclaimer |
| 14 * in the documentation and/or other materials provided with the |
| 15 * distribution. |
| 16 * * Neither the name of Google Inc. nor the names of its |
| 17 * contributors may be used to endorse or promote products derived from |
| 18 * this software without specific prior written permission. |
| 19 * |
| 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 * |
| 32 */ |
| 33 |
| 34 #ifndef GRPC_CORE_PROFILING_TIMERS_H |
| 35 #define GRPC_CORE_PROFILING_TIMERS_H |
| 36 |
| 37 #ifdef __cplusplus |
| 38 extern "C" { |
| 39 #endif |
| 40 |
| 41 void gpr_timers_global_init(void); |
| 42 void gpr_timers_global_destroy(void); |
| 43 |
| 44 void gpr_timer_add_mark(const char *tagstr, int important, const char *file, |
| 45 int line); |
| 46 void gpr_timer_begin(const char *tagstr, int important, const char *file, |
| 47 int line); |
| 48 void gpr_timer_end(const char *tagstr, int important, const char *file, |
| 49 int line); |
| 50 |
| 51 void gpr_timers_set_log_filename(const char *filename); |
| 52 |
| 53 #if !(defined(GRPC_STAP_PROFILER) + defined(GRPC_BASIC_PROFILER)) |
| 54 /* No profiling. No-op all the things. */ |
| 55 #define GPR_TIMER_MARK(tag, important) \ |
| 56 do { \ |
| 57 } while (0) |
| 58 |
| 59 #define GPR_TIMER_BEGIN(tag, important) \ |
| 60 do { \ |
| 61 } while (0) |
| 62 |
| 63 #define GPR_TIMER_END(tag, important) \ |
| 64 do { \ |
| 65 } while (0) |
| 66 |
| 67 #else /* at least one profiler requested... */ |
| 68 /* ... hopefully only one. */ |
| 69 #if defined(GRPC_STAP_PROFILER) && defined(GRPC_BASIC_PROFILER) |
| 70 #error "GRPC_STAP_PROFILER and GRPC_BASIC_PROFILER are mutually exclusive." |
| 71 #endif |
| 72 |
| 73 /* Generic profiling interface. */ |
| 74 #define GPR_TIMER_MARK(tag, important) \ |
| 75 gpr_timer_add_mark(tag, important, __FILE__, __LINE__); |
| 76 |
| 77 #define GPR_TIMER_BEGIN(tag, important) \ |
| 78 gpr_timer_begin(tag, important, __FILE__, __LINE__); |
| 79 |
| 80 #define GPR_TIMER_END(tag, important) \ |
| 81 gpr_timer_end(tag, important, __FILE__, __LINE__); |
| 82 |
| 83 #ifdef GRPC_STAP_PROFILER |
| 84 /* Empty placeholder for now. */ |
| 85 #endif /* GRPC_STAP_PROFILER */ |
| 86 |
| 87 #ifdef GRPC_BASIC_PROFILER |
| 88 /* Empty placeholder for now. */ |
| 89 #endif /* GRPC_BASIC_PROFILER */ |
| 90 |
| 91 #endif /* at least one profiler requested. */ |
| 92 |
| 93 #ifdef __cplusplus |
| 94 } |
| 95 |
| 96 #if (defined(GRPC_STAP_PROFILER) + defined(GRPC_BASIC_PROFILER)) |
| 97 namespace grpc { |
| 98 class ProfileScope { |
| 99 public: |
| 100 ProfileScope(const char *desc, bool important) : desc_(desc) { |
| 101 GPR_TIMER_BEGIN(desc_, important ? 1 : 0); |
| 102 } |
| 103 ~ProfileScope() { GPR_TIMER_END(desc_, 0); } |
| 104 |
| 105 private: |
| 106 const char *const desc_; |
| 107 }; |
| 108 } |
| 109 |
| 110 #define GPR_TIMER_SCOPE(tag, important) \ |
| 111 ::grpc::ProfileScope _profile_scope_##__LINE__((tag), (important)) |
| 112 #else |
| 113 #define GPR_TIMER_SCOPE(tag, important) \ |
| 114 do { \ |
| 115 } while (false) |
| 116 #endif |
| 117 #endif |
| 118 |
| 119 #endif /* GRPC_CORE_PROFILING_TIMERS_H */ |
OLD | NEW |