• 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     uint32_t tgid = 0;
39     std::string eventName;
40     std::string argsStr;
41 };
42 enum ParseStatus {
43     TS_PARSE_STATUS_INIT = 0,
44     TS_PARSE_STATUS_SEPRATED = 1,
45     TS_PARSE_STATUS_PARSING = 2,
46     TS_PARSE_STATUS_PARSED = 3,
47     TS_PARSE_STATUS_INVALID = 4
48 };
49 struct DataSegment {
50     std::string seg;
51     BytraceLine bufLine;
52     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
53 };
54 struct HilogLine {
55     uint64_t lineSeq;
56     uint64_t timeStamp;
57     uint32_t pid;
58     uint32_t tid;
59     std::string level;
60     std::string tag;
61     std::string context;
62 };
63 struct PbreaderDataSegment {
64     std::shared_ptr<std::string> seg;
65     uint64_t timeStamp{INVALID_TIME};
66     std::atomic<BuiltinClocks> clockId;
67     DataSourceType dataType;
68     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
69     ProtoReader::BytesView protoData;
70 };
71 struct RawtraceDataSegment {
72     std::shared_ptr<std::string> seg;
73     uint64_t timeStamp;
74     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
75 };
76 
77 class TracePoint {
78 public:
TracePoint()79     TracePoint() {}
TracePoint(const TracePoint & point)80     TracePoint(const TracePoint &point)
81         : phase_(point.phase_),
82           tgid_(point.tgid_),
83           name_(point.name_),
84           value_(point.value_),
85           categoryGroup_(point.categoryGroup_),
86           chainId_(point.chainId_),
87           spanId_(point.spanId_),
88           parentSpanId_(point.parentSpanId_),
89           flag_(point.flag_),
90           args_(point.args_),
91           funcPrefixId_(point.funcPrefixId_),
92           funcPrefix_(point.funcPrefix_),
93           funcArgs_(point.funcArgs_),
94           traceLevel_(point.traceLevel_),
95           traceTagId_(point.traceTagId_),
96           customCategoryId_(point.customCategoryId_),
97           customArgsId_(point.customArgsId_)
98     {
99     }
100     void operator=(const TracePoint &point)
101     {
102         phase_ = point.phase_;
103         tgid_ = point.tgid_;
104         name_ = point.name_;
105         value_ = point.value_;
106         categoryGroup_ = point.categoryGroup_;
107         chainId_ = point.chainId_;
108         spanId_ = point.spanId_;
109         parentSpanId_ = point.parentSpanId_;
110         flag_ = point.flag_;
111         args_ = point.args_;
112         funcPrefixId_ = point.funcPrefixId_;
113         funcPrefix_ = point.funcPrefix_;
114         funcArgs_ = point.funcArgs_;
115         traceLevel_ = point.traceLevel_;
116         traceTagId_ = point.traceTagId_;
117         customCategoryId_ = point.customCategoryId_;
118         customArgsId_ = point.customArgsId_;
119     }
120     char phase_ = '\0';
121     uint32_t tgid_ = 0;
122     std::string name_ = "";
123     int64_t value_ = 0;
124     std::string categoryGroup_ = "";
125     // Distributed Data
126     std::string chainId_ = "";
127     std::string spanId_ = "";
128     std::string parentSpanId_ = "";
129     std::string flag_ = "";
130     std::string args_ = "";
131     uint32_t funcPrefixId_ = 0;
132     std::string funcPrefix_ = "";
133     std::string funcArgs_ = "";
134     std::string traceLevel_ = "";
135     DataIndex traceTagId_ = INVALID_UINT64;
136     DataIndex customCategoryId_ = INVALID_UINT64;
137     DataIndex customArgsId_ = INVALID_UINT64;
138 };
139 
140 enum class SplitDataDataType { SPLIT_FILE_DATA = 0, SPLIT_FILE_JSON };
141 struct HtraceSplitResult {
142     int32_t type;
143     union {
144         struct {
145             uint8_t *address;
146             uint64_t size;
147         } buffer;
148         struct {
149             uint64_t offset;
150             uint64_t size;
151         } originSeg;
152     };
153 };
154 
155 struct RawTraceFileHeader {
156     uint16_t magicNumber;
157     uint8_t fileType;
158     uint16_t versionNumber;
159     uint32_t reserved;
160 } __attribute__((aligned(4)));
161 
162 enum class RawTraceContentType : uint8_t {
163     CONTENT_TYPE_DEFAULT = 0,
164     CONTENT_TYPE_EVENTS_FORMAT = 1,
165     CONTENT_TYPE_CMDLINES = 2,
166     CONTENT_TYPE_TGIDS = 3,
167     CONTENT_TYPE_CPU_RAW = 4,
168     CONTENT_TYPE_HEADER_PAGE = 30,
169     CONTENT_TYPE_PRINTK_FORMATS = 31,
170     CONTENT_TYPE_KALLSYMS = 32
171 };
172 enum class RawTraceFileType : uint8_t { FILE_RAW_TRACE = 0, HM_FILE_RAW_TRACE = 1 };
173 } // namespace TraceStreamer
174 } // namespace SysTuning
175 #endif // _BYTRACE_COMMON_TYPES_H_
176