1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INCLUDE_PERFETTO_TRACING_DEBUG_ANNOTATION_H_
18 #define INCLUDE_PERFETTO_TRACING_DEBUG_ANNOTATION_H_
19 
20 #include "perfetto/base/export.h"
21 #include "perfetto/tracing/traced_value_forward.h"
22 #include "protos/perfetto/trace/track_event/debug_annotation.pbzero.h"
23 
24 #include <stdint.h>
25 
26 #include <memory>
27 #include <string>
28 
29 namespace {
30 // std::underlying_type can't be used with non-enum types, so we need this
31 // indirection.
32 template <typename T, bool = std::is_enum<T>::value>
33 struct safe_underlying_type {
34   using type = typename std::underlying_type<T>::type;
35 };
36 
37 template <typename T>
38 struct safe_underlying_type<T, false> {
39   using type = T;
40 };
41 }  // namespace
42 
43 namespace perfetto {
44 namespace protos {
45 namespace pbzero {
46 class DebugAnnotation;
47 }  // namespace pbzero
48 }  // namespace protos
49 
50 // A base class for custom track event debug annotations.
51 class PERFETTO_EXPORT DebugAnnotation {
52  public:
53   DebugAnnotation() = default;
54   virtual ~DebugAnnotation();
55 
56   // Called to write the contents of the debug annotation into the trace.
57   virtual void Add(protos::pbzero::DebugAnnotation*) const = 0;
58 
59   void WriteIntoTracedValue(TracedValue context) const;
60 };
61 
62 }  // namespace perfetto
63 
64 #endif  // INCLUDE_PERFETTO_TRACING_DEBUG_ANNOTATION_H_
65