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_(""), domain_(""), stringId_(""), msg_("")
24 {
25 }
26
WatchPoint(const WatchPoint::Builder & builder)27 WatchPoint::WatchPoint(const WatchPoint::Builder& builder)
28 : seq_(builder.seq_),
29 timestamp_(builder.timestamp_),
30 pid_(builder.pid_),
31 tid_(builder.tid_),
32 uid_(builder.uid_),
33 terminalThreadStack_(builder.terminalThreadStack_),
34 domain_(builder.domain_),
35 stringId_(builder.stringId_),
36 msg_(builder.msg_),
37 packageName_(builder.packageName_),
38 processName_(builder.processName_),
39 foreGround_(builder.foreGround_),
40 logPath_(builder.logPath_),
41 hitraceTime_(builder.hitraceTime_),
42 sysrqTime_(builder.sysrqTime_)
43 {
44 }
45
Builder()46 WatchPoint::Builder::Builder()
47 : seq_(0), timestamp_(0), pid_(0), tid_(0), uid_(0), terminalThreadStack_(""), domain_(""), stringId_(""), msg_("")
48 {
49 }
50
~Builder()51 WatchPoint::Builder::~Builder() {}
52
InitSeq(long seq)53 WatchPoint::Builder& WatchPoint::Builder::InitSeq(long seq)
54 {
55 seq_ = seq;
56 return *this;
57 }
58
InitTimestamp(unsigned long long timestamp)59 WatchPoint::Builder& WatchPoint::Builder::InitTimestamp(unsigned long long timestamp)
60 {
61 timestamp_ = timestamp;
62 return *this;
63 }
64
InitPid(long pid)65 WatchPoint::Builder& WatchPoint::Builder::InitPid(long pid)
66 {
67 pid_ = pid;
68 return *this;
69 }
70
InitTid(long tid)71 WatchPoint::Builder& WatchPoint::Builder::InitTid(long tid)
72 {
73 tid_ = tid;
74 return *this;
75 }
76
InitUid(long uid)77 WatchPoint::Builder& WatchPoint::Builder::InitUid(long uid)
78 {
79 uid_ = uid;
80 return *this;
81 }
82
InitTerminalThreadStack(const std::string & terminalThreadStack)83 WatchPoint::Builder& WatchPoint::Builder::InitTerminalThreadStack(const std::string& terminalThreadStack)
84 {
85 terminalThreadStack_ = terminalThreadStack;
86 return *this;
87 }
88
InitDomain(const std::string & domain)89 WatchPoint::Builder& WatchPoint::Builder::InitDomain(const std::string& domain)
90 {
91 domain_ = domain;
92 return *this;
93 }
94
InitStringId(const std::string & stringId)95 WatchPoint::Builder& WatchPoint::Builder::InitStringId(const std::string& stringId)
96 {
97 stringId_ = stringId;
98 return *this;
99 }
100
InitMsg(const std::string & msg)101 WatchPoint::Builder& WatchPoint::Builder::InitMsg(const std::string& msg)
102 {
103 msg_ = msg;
104 return *this;
105 }
106
InitProcessName(const std::string & processName)107 WatchPoint::Builder& WatchPoint::Builder::InitProcessName(const std::string& processName)
108 {
109 processName_ = processName;
110 return *this;
111 }
112
InitPackageName(const std::string & packageName)113 WatchPoint::Builder& WatchPoint::Builder::InitPackageName(const std::string& packageName)
114 {
115 packageName_ = packageName;
116 return *this;
117 }
118
InitForeGround(const std::string & foreGround)119 WatchPoint::Builder& WatchPoint::Builder::InitForeGround(const std::string& foreGround)
120 {
121 foreGround_ = foreGround;
122 return *this;
123 }
124
InitLogPath(const std::string & logPath)125 WatchPoint::Builder& WatchPoint::Builder::InitLogPath(const std::string& logPath)
126 {
127 logPath_ = logPath;
128 return *this;
129 }
130
InitHitraceTime(const std::string & hitraceTime)131 WatchPoint::Builder& WatchPoint::Builder::InitHitraceTime(const std::string& hitraceTime)
132 {
133 hitraceTime_ = hitraceTime;
134 return *this;
135 }
136
InitSysrqTime(const std::string & sysrqTime)137 WatchPoint::Builder& WatchPoint::Builder::InitSysrqTime(const std::string& sysrqTime)
138 {
139 sysrqTime_ = sysrqTime;
140 return *this;
141 }
142
Build() const143 WatchPoint WatchPoint::Builder::Build() const
144 {
145 WatchPoint watchPoint = WatchPoint(*this);
146 return watchPoint;
147 }
148
GetSeq() const149 long WatchPoint::GetSeq() const
150 {
151 return seq_;
152 }
153
GetTimestamp() const154 unsigned long long WatchPoint::GetTimestamp() const
155 {
156 return timestamp_;
157 }
158
GetPid() const159 long WatchPoint::GetPid() const
160 {
161 return pid_;
162 }
163
GetTid() const164 long WatchPoint::GetTid() const
165 {
166 return tid_;
167 }
168
GetUid() const169 long WatchPoint::GetUid() const
170 {
171 return uid_;
172 }
173
GetTerminalThreadStack() const174 std::string WatchPoint::GetTerminalThreadStack() const
175 {
176 return terminalThreadStack_;
177 }
178
GetDomain() const179 std::string WatchPoint::GetDomain() const
180 {
181 return domain_;
182 }
183
GetStringId() const184 std::string WatchPoint::GetStringId() const
185 {
186 return stringId_;
187 }
188
GetMsg() const189 std::string WatchPoint::GetMsg() const
190 {
191 return msg_;
192 }
193
GetPackageName() const194 std::string WatchPoint::GetPackageName() const
195 {
196 return packageName_;
197 }
198
GetProcessName() const199 std::string WatchPoint::GetProcessName() const
200 {
201 return processName_;
202 }
203
GetForeGround() const204 std::string WatchPoint::GetForeGround() const
205 {
206 return foreGround_;
207 }
208
GetLogPath() const209 std::string WatchPoint::GetLogPath() const
210 {
211 return logPath_;
212 }
213
GetHitraceTime() const214 std::string WatchPoint::GetHitraceTime() const
215 {
216 return hitraceTime_;
217 }
218
GetSysrqTime() const219 std::string WatchPoint::GetSysrqTime() const
220 {
221 return sysrqTime_;
222 }
223
SetLogPath(const std::string & logPath)224 void WatchPoint::SetLogPath(const std::string& logPath)
225 {
226 logPath_ = logPath;
227 }
228
SetTerminalThreadStack(const std::string & terminalThreadStack)229 void WatchPoint::SetTerminalThreadStack(const std::string& terminalThreadStack)
230 {
231 terminalThreadStack_ = terminalThreadStack;
232 }
233
SetSeq(long seq)234 void WatchPoint::SetSeq(long seq)
235 {
236 seq_ = seq;
237 }
238
operator <(const WatchPoint & node) const239 bool WatchPoint::operator<(const WatchPoint& node) const
240 {
241 if (timestamp_ == node.timestamp_) {
242 return stringId_.compare(node.GetStringId());
243 }
244 return timestamp_ < node.timestamp_;
245 }
246
operator ==(const WatchPoint & node) const247 bool WatchPoint::operator==(const WatchPoint& node) const
248 {
249 return timestamp_ == node.GetTimestamp() && stringId_.compare(node.GetStringId());
250 }
251 } // namespace HiviewDFX
252 } // namespace OHOS
253