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 #include "watch_point.h"
17
18 #include <iostream>
19
20 namespace OHOS {
21 namespace HiviewDFX {
WatchPoint()22 WatchPoint::WatchPoint()
23 : seq_(0), timestamp_(0), pid_(0), tid_(0), uid_(0), terminalThreadStack_(""), telemetryId_(""), traceName_(""),
24 domain_(""), stringId_(""), msg_(""), hitraceIdInfo_(""), procStatm_(""), hostResourceWarning_("")
25 {
26 }
27
WatchPoint(const WatchPoint::Builder & builder)28 WatchPoint::WatchPoint(const WatchPoint::Builder& builder)
29 : seq_(builder.seq_),
30 timestamp_(builder.timestamp_),
31 pid_(builder.pid_),
32 tid_(builder.tid_),
33 uid_(builder.uid_),
34 terminalThreadStack_(builder.terminalThreadStack_),
35 telemetryId_(builder.telemetryId_),
36 traceName_(builder.traceName_),
37 domain_(builder.domain_),
38 stringId_(builder.stringId_),
39 msg_(builder.msg_),
40 packageName_(builder.packageName_),
41 processName_(builder.processName_),
42 foreGround_(builder.foreGround_),
43 logPath_(builder.logPath_),
44 hitraceTime_(builder.hitraceTime_),
45 sysrqTime_(builder.sysrqTime_),
46 hitraceIdInfo_(builder.hitraceIdInfo_),
47 procStatm_(builder.procStatm_),
48 hostResourceWarning_(builder.hostResourceWarning_)
49 {
50 }
51
Builder()52 WatchPoint::Builder::Builder()
53 : seq_(0), timestamp_(0), pid_(0), tid_(0), uid_(0), terminalThreadStack_(""), telemetryId_(""), traceName_(""),
54 domain_(""), stringId_(""), msg_(""), hitraceIdInfo_(""), procStatm_(""), hostResourceWarning_("")
55 {
56 }
57
~Builder()58 WatchPoint::Builder::~Builder() {}
59
InitSeq(long seq)60 WatchPoint::Builder& WatchPoint::Builder::InitSeq(long seq)
61 {
62 seq_ = seq;
63 return *this;
64 }
65
InitTimestamp(unsigned long long timestamp)66 WatchPoint::Builder& WatchPoint::Builder::InitTimestamp(unsigned long long timestamp)
67 {
68 timestamp_ = timestamp;
69 return *this;
70 }
71
InitPid(long pid)72 WatchPoint::Builder& WatchPoint::Builder::InitPid(long pid)
73 {
74 pid_ = pid;
75 return *this;
76 }
77
InitTid(long tid)78 WatchPoint::Builder& WatchPoint::Builder::InitTid(long tid)
79 {
80 tid_ = tid;
81 return *this;
82 }
83
InitUid(long uid)84 WatchPoint::Builder& WatchPoint::Builder::InitUid(long uid)
85 {
86 uid_ = uid;
87 return *this;
88 }
89
InitTerminalThreadStack(const std::string & terminalThreadStack)90 WatchPoint::Builder& WatchPoint::Builder::InitTerminalThreadStack(const std::string& terminalThreadStack)
91 {
92 terminalThreadStack_ = terminalThreadStack;
93 return *this;
94 }
95
InitTelemetryId(const std::string & telemetryId)96 WatchPoint::Builder& WatchPoint::Builder::InitTelemetryId(const std::string& telemetryId)
97 {
98 telemetryId_ = telemetryId;
99 return *this;
100 }
101
InitTraceName(const std::string & traceName)102 WatchPoint::Builder& WatchPoint::Builder::InitTraceName(const std::string& traceName)
103 {
104 traceName_ = traceName;
105 return *this;
106 }
107
InitDomain(const std::string & domain)108 WatchPoint::Builder& WatchPoint::Builder::InitDomain(const std::string& domain)
109 {
110 domain_ = domain;
111 return *this;
112 }
113
InitStringId(const std::string & stringId)114 WatchPoint::Builder& WatchPoint::Builder::InitStringId(const std::string& stringId)
115 {
116 stringId_ = stringId;
117 return *this;
118 }
119
InitMsg(const std::string & msg)120 WatchPoint::Builder& WatchPoint::Builder::InitMsg(const std::string& msg)
121 {
122 msg_ = msg;
123 return *this;
124 }
125
InitProcessName(const std::string & processName)126 WatchPoint::Builder& WatchPoint::Builder::InitProcessName(const std::string& processName)
127 {
128 processName_ = processName;
129 return *this;
130 }
131
InitPackageName(const std::string & packageName)132 WatchPoint::Builder& WatchPoint::Builder::InitPackageName(const std::string& packageName)
133 {
134 packageName_ = packageName;
135 return *this;
136 }
137
InitForeGround(const std::string & foreGround)138 WatchPoint::Builder& WatchPoint::Builder::InitForeGround(const std::string& foreGround)
139 {
140 foreGround_ = foreGround;
141 return *this;
142 }
143
InitLogPath(const std::string & logPath)144 WatchPoint::Builder& WatchPoint::Builder::InitLogPath(const std::string& logPath)
145 {
146 logPath_ = logPath;
147 return *this;
148 }
149
InitHitraceTime(const std::string & hitraceTime)150 WatchPoint::Builder& WatchPoint::Builder::InitHitraceTime(const std::string& hitraceTime)
151 {
152 hitraceTime_ = hitraceTime;
153 return *this;
154 }
155
InitSysrqTime(const std::string & sysrqTime)156 WatchPoint::Builder& WatchPoint::Builder::InitSysrqTime(const std::string& sysrqTime)
157 {
158 sysrqTime_ = sysrqTime;
159 return *this;
160 }
161
InitHitraceIdInfo(const std::string & hitraceIdInfo)162 WatchPoint::Builder& WatchPoint::Builder::InitHitraceIdInfo(const std::string& hitraceIdInfo)
163 {
164 hitraceIdInfo_ = hitraceIdInfo;
165 return *this;
166 }
167
InitProcStatm(const std::string & procStatm)168 WatchPoint::Builder& WatchPoint::Builder::InitProcStatm(const std::string& procStatm)
169 {
170 procStatm_ = procStatm;
171 return *this;
172 }
173
InitHostResourceWarning(const std::string & hostResourceWarning)174 WatchPoint::Builder& WatchPoint::Builder::InitHostResourceWarning(const std::string& hostResourceWarning)
175 {
176 hostResourceWarning_ = hostResourceWarning;
177 return *this;
178 }
179
Build() const180 WatchPoint WatchPoint::Builder::Build() const
181 {
182 WatchPoint watchPoint = WatchPoint(*this);
183 return watchPoint;
184 }
185
GetSeq() const186 long WatchPoint::GetSeq() const
187 {
188 return seq_;
189 }
190
GetTimestamp() const191 unsigned long long WatchPoint::GetTimestamp() const
192 {
193 return timestamp_;
194 }
195
GetPid() const196 long WatchPoint::GetPid() const
197 {
198 return pid_;
199 }
200
GetTid() const201 long WatchPoint::GetTid() const
202 {
203 return tid_;
204 }
205
GetUid() const206 long WatchPoint::GetUid() const
207 {
208 return uid_;
209 }
210
GetTerminalThreadStack() const211 std::string WatchPoint::GetTerminalThreadStack() const
212 {
213 return terminalThreadStack_;
214 }
215
GetTelemetryId() const216 std::string WatchPoint::GetTelemetryId() const
217 {
218 return telemetryId_;
219 }
220
GetTraceName() const221 std::string WatchPoint::GetTraceName() const
222 {
223 return traceName_;
224 }
225
GetDomain() const226 std::string WatchPoint::GetDomain() const
227 {
228 return domain_;
229 }
230
GetStringId() const231 std::string WatchPoint::GetStringId() const
232 {
233 return stringId_;
234 }
235
GetMsg() const236 std::string WatchPoint::GetMsg() const
237 {
238 return msg_;
239 }
240
GetPackageName() const241 std::string WatchPoint::GetPackageName() const
242 {
243 return packageName_;
244 }
245
GetProcessName() const246 std::string WatchPoint::GetProcessName() const
247 {
248 return processName_;
249 }
250
GetForeGround() const251 std::string WatchPoint::GetForeGround() const
252 {
253 return foreGround_;
254 }
255
GetLogPath() const256 std::string WatchPoint::GetLogPath() const
257 {
258 return logPath_;
259 }
260
GetHitraceTime() const261 std::string WatchPoint::GetHitraceTime() const
262 {
263 return hitraceTime_;
264 }
265
GetSysrqTime() const266 std::string WatchPoint::GetSysrqTime() const
267 {
268 return sysrqTime_;
269 }
270
GetHitraceIdInfo() const271 std::string WatchPoint::GetHitraceIdInfo() const
272 {
273 return hitraceIdInfo_;
274 }
275
GetProcStatm() const276 std::string WatchPoint::GetProcStatm() const
277 {
278 return procStatm_;
279 }
280
GetHostResourceWarning() const281 std::string WatchPoint::GetHostResourceWarning() const
282 {
283 return hostResourceWarning_;
284 }
285
SetLogPath(const std::string & logPath)286 void WatchPoint::SetLogPath(const std::string& logPath)
287 {
288 logPath_ = logPath;
289 }
290
SetTerminalThreadStack(const std::string & terminalThreadStack)291 void WatchPoint::SetTerminalThreadStack(const std::string& terminalThreadStack)
292 {
293 terminalThreadStack_ = terminalThreadStack;
294 }
295
SetSeq(long seq)296 void WatchPoint::SetSeq(long seq)
297 {
298 seq_ = seq;
299 }
300
operator <(const WatchPoint & node) const301 bool WatchPoint::operator<(const WatchPoint& node) const
302 {
303 if (timestamp_ == node.timestamp_) {
304 return stringId_.compare(node.GetStringId());
305 }
306 return timestamp_ < node.timestamp_;
307 }
308
operator ==(const WatchPoint & node) const309 bool WatchPoint::operator==(const WatchPoint& node) const
310 {
311 return timestamp_ == node.GetTimestamp() && stringId_.compare(node.GetStringId());
312 }
313 } // namespace HiviewDFX
314 } // namespace OHOS
315