Anthony Barbier | b467021 | 2018-05-18 16:55:39 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020 Arm Limited. |
Anthony Barbier | b467021 | 2018-05-18 16:55:39 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef ARM_COMPUTE_TRACEPOINT_H |
| 25 | #define ARM_COMPUTE_TRACEPOINT_H |
| 26 | |
| 27 | #include <string> |
| 28 | #include <type_traits> |
| 29 | #include <vector> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | #ifdef ARM_COMPUTE_TRACING_ENABLED |
| 34 | #define CREATE_TRACEPOINT(...) TracePoint __tp(__VA_ARGS__) |
| 35 | |
| 36 | /** Class used to dump configuration values in functions and kernels */ |
| 37 | class TracePoint final |
| 38 | { |
| 39 | public: |
| 40 | /** Layer types */ |
| 41 | enum class Layer |
| 42 | { |
| 43 | CORE, |
| 44 | RUNTIME |
| 45 | }; |
| 46 | /** struct describing the arguments for a tracepoint */ |
| 47 | struct Args final |
| 48 | { |
| 49 | std::vector<std::string> args{}; |
| 50 | }; |
| 51 | /** Constructor |
| 52 | * |
| 53 | * @param[in] source type of layer for the tracepoint |
| 54 | * @param[in] class_name the name of the class creating the tracepoint |
| 55 | * @param[in] object a pointer to the actual object owning the tracepoint |
| 56 | * @param[in] args a struct describing all the arguments used in the call to the configure() method |
| 57 | * |
| 58 | */ |
| 59 | TracePoint(Layer source, const std::string &class_name, void *object, Args &&args); |
| 60 | /** Destructor */ |
| 61 | ~TracePoint(); |
| 62 | |
| 63 | private: |
| 64 | static int g_depth; /**< current depth */ |
| 65 | int _depth; /**< tracepoint depth */ |
| 66 | }; |
| 67 | |
| 68 | /** Operator to write an argument to a @ref TracePoint |
| 69 | * |
| 70 | * @param[in] tp Tracepoint to be used for writing |
| 71 | * @param[in] arg Argument to be written in the tracepoint |
| 72 | * |
| 73 | * @return A referece to the updated tracepoint |
| 74 | */ |
| 75 | template <typename T> |
| 76 | TracePoint::Args &&operator<<(typename std::enable_if < !std::is_pointer<T>::value, TracePoint::Args >::type &&tp, const T &arg); |
| 77 | template <typename T> |
| 78 | TracePoint::Args &&operator<<(TracePoint::Args &&tp, const T *arg); |
| 79 | |
| 80 | #define CONST_REF_CLASS(type) \ |
| 81 | template <> \ |
| 82 | TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type &arg) \ |
| 83 | { \ |
| 84 | ARM_COMPUTE_UNUSED(tp); \ |
| 85 | tp.args.push_back(#type "(" + to_string(arg) + ")"); \ |
| 86 | return std::move(tp); \ |
| 87 | } |
| 88 | |
| 89 | #define CONST_PTR_ADDRESS(type) \ |
| 90 | template <> \ |
| 91 | TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type *arg) \ |
| 92 | { \ |
| 93 | ARM_COMPUTE_UNUSED(tp); \ |
| 94 | tp.args.push_back(#type "*(" + to_ptr_string(arg) + ")"); \ |
| 95 | return std::move(tp); \ |
| 96 | } |
| 97 | #define CONST_PTR_CLASS(type) \ |
| 98 | template <> \ |
| 99 | TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type *arg) \ |
| 100 | { \ |
| 101 | ARM_COMPUTE_UNUSED(tp); \ |
| 102 | if(arg) \ |
| 103 | tp.args.push_back(#type "(" + to_string(*arg) + ")"); \ |
| 104 | else \ |
| 105 | tp.args.push_back(#type "( nullptr )"); \ |
| 106 | return std::move(tp); \ |
| 107 | } |
| 108 | |
| 109 | #define CONST_REF_SIMPLE(type) \ |
| 110 | template <> \ |
| 111 | TracePoint::Args &&operator<<(TracePoint::Args &&tp, const type &arg) \ |
| 112 | { \ |
| 113 | ARM_COMPUTE_UNUSED(tp); \ |
| 114 | tp.args.push_back(#type "(" + support::cpp11::to_string(arg) + ")"); \ |
| 115 | return std::move(tp); \ |
| 116 | } |
| 117 | |
| 118 | #define TRACE_TO_STRING(type) \ |
| 119 | std::string to_string(const type &arg) \ |
| 120 | { \ |
| 121 | ARM_COMPUTE_UNUSED(arg); \ |
| 122 | return ""; \ |
| 123 | } |
| 124 | #else /* ARM_COMPUTE_TRACING_ENABLED */ |
| 125 | #define CREATE_TRACEPOINT(...) |
| 126 | #define CONST_REF_CLASS(type) |
| 127 | #define CONST_PTR_ADDRESS(type) |
| 128 | #define CONST_PTR_CLASS(type) |
| 129 | #define CONST_REF_SIMPLE(type) |
| 130 | #define TRACE_TO_STRING(type) |
| 131 | #endif /* ARM_COMPUTE_TRACING_ENABLED */ |
| 132 | } //namespace arm_compute |
| 133 | |
| 134 | #endif /* ARM_COMPUTE_TRACEPOINT_H */ |