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