• 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 <string>
21 #include <unordered_map>
22 #include "cpu_plugin_result.pb.h"
23 #include "diskio_plugin_result.pb.h"
24 #include "hidump_plugin_result.pb.h"
25 #include "hilog_plugin_result.pb.h"
26 #include "hisysevent_plugin_result.pb.h"
27 #include "memory_plugin_result.pb.h"
28 #include "native_hook_result.pb.h"
29 #include "network_plugin_result.pb.h"
30 #include "process_plugin_result.pb.h"
31 #include "services/common_types.pb.h"
32 #include "trace_plugin_result.pb.h"
33 #include "ts_common.h"
34 
35 namespace SysTuning {
36 namespace TraceStreamer {
37 enum ParseResult { ERROR = 0, SUCCESS };
38 enum RawType { RAW_CPU_IDLE = 1, RAW_SCHED_WAKEUP = 2, RAW_SCHED_WAKING = 3 };
39 enum Stat : uint32_t {
40     RUNNABLE = 0,
41     INTERRUPTABLESLEEP = 1,
42     UNINTERRUPTIBLESLEEP = 2,
43     STOPPED = 4,
44     TRACED = 8, // the process is being debug
45     EXITDEAD = 16,
46     EXITZOMBIE = 32,
47     TASKDEAD = 64,
48     WAKEKILL = 128,
49     WAKING = 256,
50     PARKED = 512,
51     NOLOAD = 1024,
52     TASKNEW = 2048,
53     VALID = 0X8000,
54 };
55 
56 struct BytraceLine {
57     uint64_t ts = 0;
58     uint32_t pid = 0;
59     uint32_t cpu = 0;
60 
61     std::string task;    // thread name
62     std::string pidStr;  // thread str
63     std::string tGidStr; // process thread_group
64     std::string eventName;
65     std::string argsStr;
66 };
67 enum ParseStatus {
68     TS_PARSE_STATUS_INIT = 0,
69     TS_PARSE_STATUS_SEPRATED = 1,
70     TS_PARSE_STATUS_PARSING = 2,
71     TS_PARSE_STATUS_PARSED = 3,
72     TS_PARSE_STATUS_INVALID = 4
73 };
74 struct DataSegment {
75     std::string seg;
76     BytraceLine bufLine;
77     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
78 };
79 // 注意使用完之后恢复初始化状态,保证下次使用不会出现数据混乱。
80 struct HtraceDataSegment {
81     std::string seg;
82     MemoryData memData;
83     HilogInfo logData;
84     BatchNativeHookData batchNativeHookData;
85     HidumpInfo hidumpInfo;
86     CpuData cpuInfo;
87     NetworkDatas networkInfo;
88     DiskioData diskIOInfo;
89     ProcessData processInfo;
90     HisyseventInfo hisyseventInfo;
91     uint64_t timeStamp;
92     std::unique_ptr<TracePluginResult> traceData;
93     BuiltinClocks clockId;
94     DataSourceType dataType;
95     std::atomic<ParseStatus> status{TS_PARSE_STATUS_INIT};
96 };
97 
98 class TracePoint {
99 public:
TracePoint()100     TracePoint() {}
TracePoint(const TracePoint & point)101     TracePoint(const TracePoint& point)
102     {
103         phase_ = point.phase_;
104         tgid_ = point.tgid_;
105         name_ = point.name_;
106         value_ = point.value_;
107         categoryGroup_ = point.categoryGroup_;
108         chainId_ = point.chainId_;
109         spanId_ = point.spanId_;
110         parentSpanId_ = point.parentSpanId_;
111         flag_ = point.flag_;
112         args_ = point.args_;
113     }
114     void operator=(const TracePoint& point)
115     {
116         phase_ = point.phase_;
117         tgid_ = point.tgid_;
118         name_ = point.name_;
119         value_ = point.value_;
120         categoryGroup_ = point.categoryGroup_;
121         chainId_ = point.chainId_;
122         spanId_ = point.spanId_;
123         parentSpanId_ = point.parentSpanId_;
124         flag_ = point.flag_;
125         args_ = point.args_;
126     }
127     char phase_ = '\0';
128     uint32_t tgid_ = 0;
129     std::string name_ = "";
130     uint64_t value_ = 0;
131     std::string categoryGroup_ = "";
132     // Distributed Data
133     std::string chainId_ = "";
134     std::string spanId_ = "";
135     std::string parentSpanId_ = "";
136     std::string flag_ = "";
137     std::string args_ = "";
138 };
139 } // namespace TraceStreamer
140 } // namespace SysTuning
141 #endif // _BYTRACE_COMMON_TYPES_H_
142