HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
profiler_common.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 
6 #include "core/common/common.h"
7 
8 #include <string>
9 #include <unordered_map>
10 
11 namespace onnxruntime {
12 namespace profiling {
13 
20 };
21 
22 // Event descriptions for the above session events.
23 static constexpr const char* event_category_names_[EVENT_CATEGORY_MAX] = {
24  "Session",
25  "Node",
26  "Kernel",
27  "Api"};
28 
29 // Timing record for all events.
30 struct EventRecord {
31  EventRecord() = default;
33  int process_id,
34  int thread_id,
35  std::string&& event_name,
36  long long time_stamp,
37  long long duration,
38  std::unordered_map<std::string, std::string>&& event_args)
39  : cat(category),
40  pid(process_id),
41  tid(thread_id),
42  name(std::move(event_name)),
43  ts(time_stamp),
44  dur(duration),
45  args(std::move(event_args)) {}
46 
48  int process_id,
49  int thread_id,
50  const std::string& event_name,
51  long long time_stamp,
52  long long duration,
53  const std::unordered_map<std::string, std::string>& event_args)
54  : cat(category),
55  pid(process_id),
56  tid(thread_id),
57  name(event_name),
58  ts(time_stamp),
59  dur(duration),
60  args(event_args) {}
61 
62  EventRecord(const EventRecord& other) = default;
63  EventRecord(EventRecord&& other) noexcept = default;
64  EventRecord& operator=(const EventRecord& other) = default;
65  EventRecord& operator=(EventRecord&& other) = default;
66 
68  int pid = -1;
69  int tid = -1;
70  std::string name{};
71  long long ts = 0;
72  long long dur = 0;
73  std::unordered_map<std::string, std::string> args{};
74 };
75 
76 using Events = std::vector<EventRecord>;
77 
78 // Execution Provider Profiler
79 class EpProfiler {
80  public:
81  virtual ~EpProfiler() = default;
82  virtual bool StartProfiling(TimePoint profiling_start_time) = 0; // called when profiling starts
83  virtual void EndProfiling(TimePoint start_time, Events& events) = 0; // called when profiling ends, save all captures numbers to "events"
84  virtual void Start(uint64_t){}; // called before op start, accept an id as argument to identify the op
85  virtual void Stop(uint64_t){}; // called after op stop, accept an id as argument to identify the op
86 };
87 
88 // Demangle C++ symbols
89 std::string demangle(const char* name);
91 
92 } // namespace profiling
93 } // namespace onnxruntime
EventRecord(EventCategory category, int process_id, int thread_id, const std::string &event_name, long long time_stamp, long long duration, const std::unordered_map< std::string, std::string > &event_args)
virtual bool StartProfiling(TimePoint profiling_start_time)=0
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
std::string demangle(const char *name)
std::chrono::high_resolution_clock::time_point TimePoint
Definition: common.h:42
std::vector< EventRecord > Events
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void EndProfiling(TimePoint start_time, Events &events)=0
std::unordered_map< std::string, std::string > args
**Note that the tasks the thread_id
Definition: thread.h:637
EventRecord(EventCategory category, int process_id, int thread_id, std::string &&event_name, long long time_stamp, long long duration, std::unordered_map< std::string, std::string > &&event_args)