17 #ifndef CAFFE2_CORE_NET_ASYNC_TRACING_H_ 18 #define CAFFE2_CORE_NET_ASYNC_TRACING_H_ 20 #include "caffe2/core/common.h" 21 #include "caffe2/core/net_async_base.h" 22 #include "caffe2/core/operator.h" 23 #include "caffe2/core/timer.h" 25 C10_DECLARE_string(caffe2_net_async_tracing_filepath);
26 C10_DECLARE_string(caffe2_net_async_names_to_trace);
27 C10_DECLARE_int(caffe2_net_async_tracing_nth);
36 const char* name_ =
nullptr;
37 const char* category_ =
nullptr;
38 long timestamp_ = -1.0;
39 bool is_beginning_ =
false;
40 long thread_label_ = -1;
53 enum class TracingMode {
59 TracingMode mode{TracingMode::EVERY_K_ITERATIONS};
60 std::string filepath{
"/tmp"};
63 int64_t trace_every_nth_batch = 100;
64 int64_t dump_every_nth_batch = 10000;
67 int64_t trace_every_n_ms = 2 * 60 * 1000;
68 int64_t trace_for_n_ms = 1000;
75 const std::string& net_name,
81 std::string serializeEvent(
const TracerEvent& event);
82 void linearizeEvents();
84 void setEnabled(
bool enabled);
85 bool isEnabled()
const;
90 int bumpDumpingIter();
93 void dumpTracingResultAndClearEvents(
const std::string& file_suffix);
99 std::string filename_;
100 std::vector<TracerEvent> events_;
101 std::mutex tracer_mutex_;
102 bool enabled_ =
false;
115 void init(
Tracer* tracer);
118 void addArgument(TracingField field,
const char* value);
119 void addArgument(TracingField field,
int value);
121 template <
typename T,
typename... Args>
122 void addArgument(TracingField field,
const T& value,
const Args&... args) {
123 addArgument(field, value);
124 addArgument(args...);
127 void recordEventStart();
132 bool enabled_ =
false;
139 CAFFE2_API
int extractShardId(
const std::string& name);
143 CAFFE2_API
bool isTraceableNetName(
const std::string& net_name);
145 CAFFE2_API std::shared_ptr<Tracer> create(
147 const std::string& net_name);
148 CAFFE2_API
bool startIter(
const std::shared_ptr<Tracer>& tracer);
152 #define TRACE_NAME_CONCATENATE(s1, s2) s1##s2 153 #define TRACE_ANONYMOUS_NAME(str) TRACE_NAME_CONCATENATE(str, __LINE__) 155 #define TRACE_EVENT_INIT(...) \ 156 TRACE_ANONYMOUS_NAME(trace_guard).init(tracer_.get()); \ 157 TRACE_ANONYMOUS_NAME(trace_guard).addArgument(__VA_ARGS__); \ 158 TRACE_ANONYMOUS_NAME(trace_guard).recordEventStart(); 161 #define TRACE_EVENT(...) \ 162 tracing::TracerGuard TRACE_ANONYMOUS_NAME(trace_guard); \ 163 if (tracer_ && tracer_->isEnabled()) { \ 164 TRACE_EVENT_INIT(__VA_ARGS__) \ 167 #define TRACE_EVENT_IF(cond, ...) \ 168 tracing::TracerGuard TRACE_ANONYMOUS_NAME(trace_guard); \ 169 if (tracer_ && tracer_->isEnabled() && (cond)) { \ 170 TRACE_EVENT_INIT(__VA_ARGS__) \ 175 #endif // CAFFE2_CORE_NET_ASYNC_TRACING_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
A simple timer object for measuring time.