Apollo 10.0
自动驾驶开放平台
perf_event.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
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 CYBER_EVENT_PERF_EVENT_H_
18#define CYBER_EVENT_PERF_EVENT_H_
19
20#include <cstdint>
21#include <limits>
22#include <sstream>
23#include <string>
24
26#include "cyber/common/macros.h"
27
28namespace apollo {
29namespace cyber {
30namespace event {
31
32enum class EventType { SCHED_EVENT = 0, TRANS_EVENT = 1, TRY_FETCH_EVENT = 3 };
33
34enum class TransPerf {
36 SERIALIZE = 1,
37 SEND = 2,
39 OBTAIN = 4, // only for shm
40 DESERIALIZE = 5,
41 DISPATCH = 6,
42 NOTIFY = 7,
43 FETCH = 8,
44 CALLBACK = 9,
46};
47
48enum class SchedPerf {
49 SWAP_IN = 1,
50 SWAP_OUT = 2,
51 NOTIFY_IN = 3,
52 NEXT_RT = 4,
53 RT_CREATE = 5,
54};
55
56class EventBase {
57 public:
58 virtual std::string SerializeToString() = 0;
59
60 void set_eid(int eid) { eid_ = eid; }
61 void set_etype(int etype) { etype_ = etype; }
62 void set_stamp(uint64_t stamp) { stamp_ = stamp; }
63
64 virtual void set_cr_id(uint64_t cr_id) { UNUSED(cr_id); }
65 virtual void set_cr_state(int cr_state) { UNUSED(cr_state); }
66 virtual void set_proc_id(int proc_id) { UNUSED(proc_id); }
67 virtual void set_fetch_res(int fetch_res) { UNUSED(fetch_res); }
68
69 virtual void set_msg_seq(uint64_t msg_seq) { UNUSED(msg_seq); }
70 virtual void set_channel_id(uint64_t channel_id) { UNUSED(channel_id); }
71 virtual void set_adder(const std::string& adder) { UNUSED(adder); }
72
73 protected:
74 int etype_;
75 int eid_;
76 uint64_t stamp_;
77};
78
79// event_id
80// 1 swap_in
81// 2 swap_out
82// 3 notify_in
83// 4 next_routine
84class SchedEvent : public EventBase {
85 public:
86 SchedEvent() { etype_ = static_cast<int>(EventType::SCHED_EVENT); }
87
88 std::string SerializeToString() override {
89 std::stringstream ss;
90 ss << etype_ << "\t";
91 ss << eid_ << "\t";
92 ss << common::GlobalData::GetTaskNameById(cr_id_) << "\t";
93 ss << proc_id_ << "\t";
94 ss << cr_state_ << "\t";
95 ss << stamp_;
96 return ss.str();
97 }
98
99 void set_cr_id(uint64_t cr_id) override { cr_id_ = cr_id; }
100 void set_cr_state(int cr_state) override { cr_state_ = cr_state; }
101 void set_proc_id(int proc_id) override { proc_id_ = proc_id; }
102
103 private:
104 int cr_state_ = 1;
105 int proc_id_ = 0;
106 uint64_t cr_id_ = 0;
107};
108
109// event_id = 1 transport
110// 1 transport time
111// 2 write_data_cache & notify listener
112class TransportEvent : public EventBase {
113 public:
115
116 std::string SerializeToString() override {
117 std::stringstream ss;
118 ss << etype_ << "\t";
119 ss << eid_ << "\t";
120 ss << common::GlobalData::GetChannelById(channel_id_) << "\t";
121 ss << msg_seq_ << "\t";
122 ss << stamp_ << "\t";
123 ss << adder_;
124 return ss.str();
125 }
126
127 void set_msg_seq(uint64_t msg_seq) override { msg_seq_ = msg_seq; }
128 void set_channel_id(uint64_t channel_id) override {
129 channel_id_ = channel_id;
130 }
131 void set_adder(const std::string& adder) override { adder_ = adder; }
132
133 static std::string ShowTransPerf(TransPerf type) {
134 if (type == TransPerf::TRANSMIT_BEGIN) {
135 return "TRANSMIT_BEGIN";
136 } else if (type == TransPerf::SERIALIZE) {
137 return "SERIALIZE";
138 } else if (type == TransPerf::SEND) {
139 return "SEND";
140 } else if (type == TransPerf::MESSAGE_ARRIVE) {
141 return "MESSAGE_ARRIVE";
142 } else if (type == TransPerf::OBTAIN) {
143 return "OBTAIN";
144 } else if (type == TransPerf::DESERIALIZE) {
145 return "DESERIALIZE";
146 } else if (type == TransPerf::DISPATCH) {
147 return "DISPATCH";
148 } else if (type == TransPerf::NOTIFY) {
149 return "NOTIFY";
150 } else if (type == TransPerf::FETCH) {
151 return "FETCH";
152 } else if (type == TransPerf::CALLBACK) {
153 return "CALLBACK";
154 }
155 return "";
156 }
157
158 private:
159 std::string adder_ = "";
160 uint64_t msg_seq_ = 0;
161 uint64_t channel_id_ = std::numeric_limits<uint64_t>::max();
162};
163
164} // namespace event
165} // namespace cyber
166} // namespace apollo
167
168#endif // CYBER_EVENT_PERF_EVENT_H_
static std::string GetChannelById(uint64_t id)
static std::string GetTaskNameById(uint64_t id)
virtual void set_adder(const std::string &adder)
Definition perf_event.h:71
virtual void set_fetch_res(int fetch_res)
Definition perf_event.h:67
void set_stamp(uint64_t stamp)
Definition perf_event.h:62
virtual std::string SerializeToString()=0
virtual void set_proc_id(int proc_id)
Definition perf_event.h:66
virtual void set_cr_state(int cr_state)
Definition perf_event.h:65
virtual void set_cr_id(uint64_t cr_id)
Definition perf_event.h:64
virtual void set_msg_seq(uint64_t msg_seq)
Definition perf_event.h:69
virtual void set_channel_id(uint64_t channel_id)
Definition perf_event.h:70
void set_cr_id(uint64_t cr_id) override
Definition perf_event.h:99
std::string SerializeToString() override
Definition perf_event.h:88
void set_proc_id(int proc_id) override
Definition perf_event.h:101
void set_cr_state(int cr_state) override
Definition perf_event.h:100
void set_msg_seq(uint64_t msg_seq) override
Definition perf_event.h:127
void set_channel_id(uint64_t channel_id) override
Definition perf_event.h:128
std::string SerializeToString() override
Definition perf_event.h:116
void set_adder(const std::string &adder) override
Definition perf_event.h:131
static std::string ShowTransPerf(TransPerf type)
Definition perf_event.h:133
#define UNUSED(param)
Definition macros.h:46
class register implement
Definition arena_queue.h:37