OSVR-Core
Tracing.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_Tracing_h_GUID_0D1E8891_2D51_4281_9CBC_2B9B4DFB28C1
26 #define INCLUDED_Tracing_h_GUID_0D1E8891_2D51_4281_9CBC_2B9B4DFB28C1
27 
28 // Internal Includes
29 #include <osvr/Common/Export.h>
30 #include <osvr/Common/TracingConfig.h>
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 #include <cstdint>
37 #include <string>
38 
39 namespace osvr {
40 namespace common {
41  namespace tracing {
42  typedef std::int64_t TraceBeginStamp;
43 #ifdef OSVR_COMMON_TRACING_ENABLED
44  struct OSVR_COMMON_EXPORT MainTracePolicy {
45  static TraceBeginStamp begin(const char *text);
46  static void end(const char *text, TraceBeginStamp stamp);
47  static void mark(const char *text);
48  };
49 
50  struct OSVR_COMMON_EXPORT WorkerTracePolicy {
51  static TraceBeginStamp begin(const char *text);
52  static void end(const char *text, TraceBeginStamp stamp);
53  static void mark(const char *text);
54  };
56  template <typename TracePolicy> class TracingRegion {
57  public:
59  ~TracingRegion() { TracePolicy::end(m_text, m_stamp); }
60 
61  protected:
64  explicit TracingRegion(const char text[]) : m_text(text) {
65  m_stamp = TracePolicy::begin(m_text);
66  }
68  TracingRegion(TracingRegion const &) = delete;
70  TracingRegion &operator=(TracingRegion const &) = delete;
71 
72  private:
73  TraceBeginStamp m_stamp;
74  const char *m_text;
75  };
76  template <typename Policy>
77  inline void markConcatenation(const char *fixedString,
78  std::string const &string) {
79  Policy::mark((fixedString + string).c_str());
80  }
81 #else // OSVR_COMMON_TRACING_ENABLED ^^ // vv !OSVR_COMMON_TRACING_ENABLED
82  struct MainTracePolicy {
83  static TraceBeginStamp begin(const char *) { return 0; }
84  static void end(const char *, TraceBeginStamp) {}
85  static void mark(const char *) {}
86  };
88  static TraceBeginStamp begin(const char *) { return 0; }
89  static void end(const char *, TraceBeginStamp) {}
90  static void mark(const char *) {}
91  };
92 
93  template <typename TracePolicy> class TracingRegion {
94  protected:
95  explicit TracingRegion(const char *) {}
96  };
97  inline TraceBeginStamp driverUpdateStart(std::string const &,
98  std::string const &) {
99  return 0;
100  }
101  inline void driverUpdateEnd(TraceBeginStamp) {}
102  template <typename Policy>
103  inline void markConcatenation(const char *, std::string const &) {}
104 #endif // !OSVR_COMMON_TRACING_ENABLED
105 
106  // -- Common code between dummy implementation and real implementation
107 
109  class ServerUpdate : public TracingRegion<MainTracePolicy> {
110  public:
111  ServerUpdate() : TracingRegion<MainTracePolicy>("ServerUpdate") {}
112  };
113 
114  inline void markPathTreeBroadcast() {
115  MainTracePolicy::mark("Path Tree Broadcast");
116  }
117  inline void markHardwareDetect() {
118  MainTracePolicy::mark("Hardware Detection");
119  }
120 
122  class ClientUpdate : public TracingRegion<MainTracePolicy> {
123  public:
124  ClientUpdate() : TracingRegion<MainTracePolicy>("ClientUpdate") {}
125  };
126  inline void markTimestampOutOfOrder() {
127  MainTracePolicy::mark("Timestamp out of order");
128  }
129  inline void markNewTrackerData() {
130  MainTracePolicy::mark("New tracker data");
131  }
132  inline void markGetState(std::string const &path) {
133  markConcatenation<WorkerTracePolicy>("GetState ", path);
134  }
135  inline void markGetInterface(std::string const &path) {
136  markConcatenation<WorkerTracePolicy>("GetInterface ", path);
137  }
138  inline void markReleaseInterface(std::string const &path) {
139  markConcatenation<WorkerTracePolicy>("ReleaseInterface ", path);
140  }
141 
142  } // namespace tracing
143 } // namespace common
144 } // namespace osvr
145 
146 #endif // INCLUDED_Tracing_h_GUID_0D1E8891_2D51_4281_9CBC_2B9B4DFB28C1
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
Definition: Tracing.h:93
"Guard"-type class to trace the region of a server update
Definition: Tracing.h:122
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
"Guard"-type class to trace the region of a server update
Definition: Tracing.h:109