• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BYTRACE_COMMON_TYPES_H
17 #define BYTRACE_COMMON_TYPES_H
18 
19 #include <atomic>
20 #include <functional>
21 #include <memory>
22 #include <string>
23 #include <unordered_map>
24 #include "proto_reader_help.h"
25 #include "ts_common.h"
26 
27 namespace SysTuning {
28 namespace TraceStreamer {
29 enum ParseResult { PARSE_ERROR = 0, PARSE_SUCCESS = 1 };
30 enum RawType { RAW_CPU_IDLE = 1, RAW_SCHED_WAKEUP = 2, RAW_SCHED_WAKING = 3 };
31 enum ErrorCode { ERROR_CODE_EXIT = -2, ERROR_CODE_NODATA = -1 };
32 struct BytraceLine {
33     uint64_t ts = 0;
34     uint32_t pid = 0;
35     uint32_t cpu = 0;
36 
37     std::string task;    // thread name
38     std::string pidStr;  // thread str
39     std::string tGidStr; // process thread_group
40     uint32_t tgid = 0;
41     std::string eventName;
42     std::string argsStr;
43 };
44 enum ParseStatus {
45     TS_PARSE_STATUS_INIT = 0,
46     TS_PARSE_STATUS_SEPRATED = 1,
47     TS_PARSE_STATUS_PARSING = 2,
48     TS_PARSE_STATUS_PARSED = 3,
49     TS_PARSE_STATUS_INVALID = 4
50 };
51 struct DataSegment {
52     std::string seg;
53     BytraceLine bufLine;
54     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
55 };
56 struct HilogLine {
57     uint64_t lineSeq;
58     uint64_t timeStamp;
59     uint32_t pid;
60     uint32_t tid;
61     std::string level;
62     std::string tag;
63     std::string context;
64 };
65 struct PbreaderDataSegment {
66     std::shared_ptr<std::string> seg;
67     uint64_t timeStamp{INVALID_TIME};
68     std::atomic<BuiltinClocks> clockId;
69     DataSourceType dataType;
70     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
71     ProtoReader::BytesView protoData;
72 };
73 struct RawtraceDataSegment {
74     std::shared_ptr<std::string> seg;
75     uint64_t timeStamp;
76     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
77 };
78 
79 class TracePoint {
80 public:
TracePoint()81     TracePoint() {}
TracePoint(const TracePoint & point)82     TracePoint(const TracePoint &point)
83         : phase_(point.phase_),
84           tgid_(point.tgid_),
85           name_(point.name_),
86           value_(point.value_),
87           categoryGroup_(point.categoryGroup_),
88           chainId_(point.chainId_),
89           spanId_(point.spanId_),
90           parentSpanId_(point.parentSpanId_),
91           flag_(point.flag_),
92           args_(point.args_),
93           funcPrefixId_(point.funcPrefixId_),
94           funcPrefix_(point.funcPrefix_),
95           funcArgs_(point.funcArgs_)
96     {
97     }
98     void operator=(const TracePoint &point)
99     {
100         phase_ = point.phase_;
101         tgid_ = point.tgid_;
102         name_ = point.name_;
103         value_ = point.value_;
104         categoryGroup_ = point.categoryGroup_;
105         chainId_ = point.chainId_;
106         spanId_ = point.spanId_;
107         parentSpanId_ = point.parentSpanId_;
108         flag_ = point.flag_;
109         args_ = point.args_;
110         funcPrefixId_ = point.funcPrefixId_;
111         funcPrefix_ = point.funcPrefix_;
112         funcArgs_ = point.funcArgs_;
113     }
114     char phase_ = '\0';
115     uint32_t tgid_ = 0;
116     std::string name_ = "";
117     int64_t value_ = 0;
118     std::string categoryGroup_ = "";
119     // Distributed Data
120     std::string chainId_ = "";
121     std::string spanId_ = "";
122     std::string parentSpanId_ = "";
123     std::string flag_ = "";
124     std::string args_ = "";
125     uint32_t funcPrefixId_ = 0;
126     std::string funcPrefix_ = "";
127     std::string funcArgs_ = "";
128 };
129 
130 enum class SplitDataDataType { SPLIT_FILE_DATA = 0, SPLIT_FILE_JSON };
131 struct HtraceSplitResult {
132     int32_t type;
133     union {
134         struct {
135             uint8_t *address;
136             uint64_t size;
137         } buffer;
138         struct {
139             uint64_t offset;
140             uint64_t size;
141         } originSeg;
142     };
143 };
144 
145 struct RawTraceFileHeader {
146     uint16_t magicNumber;
147     uint8_t fileType;
148     uint16_t versionNumber;
149     uint32_t reserved;
150 } __attribute__((aligned(4)));
151 
152 enum class RawTraceContentType : uint8_t {
153     CONTENT_TYPE_DEFAULT = 0,
154     CONTENT_TYPE_EVENTS_FORMAT = 1,
155     CONTENT_TYPE_CMDLINES = 2,
156     CONTENT_TYPE_TGIDS = 3,
157     CONTENT_TYPE_CPU_RAW = 4,
158     CONTENT_TYPE_HEADER_PAGE = 30,
159     CONTENT_TYPE_PRINTK_FORMATS = 31,
160     CONTENT_TYPE_KALLSYMS = 32
161 };
162 enum class RawTraceFileType : uint8_t { FILE_RAW_TRACE = 0, HM_FILE_RAW_TRACE = 1 };
163 } // namespace TraceStreamer
164 } // namespace SysTuning
165 #endif // _BYTRACE_COMMON_TYPES_H_
166