1 /*
2 * Copyright (c) 2021-2023 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 "hiappevent_base.h"
17
18 #include <ctime>
19 #include <iomanip>
20 #include <sstream>
21 #include <string>
22 #include <unistd.h>
23 #include <vector>
24
25 #include "hilog/log.h"
26 #include "hitrace/trace.h"
27 #include "time_util.h"
28
29 namespace OHOS {
30 namespace HiviewDFX {
31 namespace {
32 const HiLogLabel LABEL = { LOG_CORE, HIAPPEVENT_DOMAIN, "HiAppEvent_base" };
33 const std::string DEFAULT_DOMAIN = "default";
34
TrimRightZero(const std::string & str)35 std::string TrimRightZero(const std::string& str)
36 {
37 auto endIndex = str.find_last_not_of("0");
38 if (endIndex == std::string::npos) {
39 return str;
40 }
41
42 return (str[endIndex] == '.') ? str.substr(0, endIndex) : str.substr(0, endIndex + 1);
43 }
44
InitValueByBaseType(AppEventParamValue * value,const AppEventParamValue & other)45 void InitValueByBaseType(AppEventParamValue* value, const AppEventParamValue& other)
46 {
47 if (value == nullptr) {
48 return;
49 }
50
51 switch (other.type) {
52 case AppEventParamType::BOOL:
53 value->valueUnion.b_ = other.valueUnion.b_;
54 break;
55 case AppEventParamType::CHAR:
56 value->valueUnion.c_ = other.valueUnion.c_;
57 break;
58 case AppEventParamType::SHORT:
59 value->valueUnion.sh_ = other.valueUnion.sh_;
60 break;
61 case AppEventParamType::INTEGER:
62 value->valueUnion.i_ = other.valueUnion.i_;
63 break;
64 case AppEventParamType::LONGLONG:
65 value->valueUnion.ll_ = other.valueUnion.ll_;
66 break;
67 case AppEventParamType::FLOAT:
68 value->valueUnion.f_ = other.valueUnion.f_;
69 break;
70 case AppEventParamType::DOUBLE:
71 value->valueUnion.d_ = other.valueUnion.d_;
72 break;
73 default:
74 break;
75 }
76 }
77
InitValueByReferType(AppEventParamValue * value,const AppEventParamValue & other)78 void InitValueByReferType(AppEventParamValue* value, const AppEventParamValue& other)
79 {
80 if (value == nullptr) {
81 return;
82 }
83
84 switch (other.type) {
85 case AppEventParamType::STRING:
86 new (&value->valueUnion.str_) auto(other.valueUnion.str_);
87 break;
88 case AppEventParamType::BVECTOR:
89 new (&value->valueUnion.bs_) auto(other.valueUnion.bs_);
90 break;
91 case AppEventParamType::CVECTOR:
92 new (&value->valueUnion.cs_) auto(other.valueUnion.cs_);
93 break;
94 case AppEventParamType::SHVECTOR:
95 new (&value->valueUnion.shs_) auto(other.valueUnion.shs_);
96 break;
97 case AppEventParamType::IVECTOR:
98 new (&value->valueUnion.is_) auto(other.valueUnion.is_);
99 break;
100 case AppEventParamType::LLVECTOR:
101 new (&value->valueUnion.lls_) auto(other.valueUnion.lls_);
102 break;
103 case AppEventParamType::FVECTOR:
104 new (&value->valueUnion.fs_) auto(other.valueUnion.fs_);
105 break;
106 case AppEventParamType::DVECTOR:
107 new (&value->valueUnion.ds_) auto(other.valueUnion.ds_);
108 break;
109 case AppEventParamType::STRVECTOR:
110 new (&value->valueUnion.strs_) auto(other.valueUnion.strs_);
111 break;
112 default:
113 break;
114 }
115 }
116
117 template<typename T>
GetValueStr(const T & value)118 std::string GetValueStr(const T& value)
119 {
120 return std::to_string(value);
121 }
122
GetValueStr(bool value)123 std::string GetValueStr(bool value)
124 {
125 return value ? "true" : "false";
126 }
127
GetValueStr(char value)128 std::string GetValueStr(char value)
129 {
130 return "\"" + std::to_string(value) + "\"";
131 }
132
GetValueStr(float value)133 std::string GetValueStr(float value)
134 {
135 return TrimRightZero(std::to_string(value));
136 }
137
GetValueStr(double value)138 std::string GetValueStr(double value)
139 {
140 return TrimRightZero(std::to_string(value));
141 }
142
GetValueStr(const std::string & value)143 std::string GetValueStr(const std::string& value)
144 {
145 return "\"" + value + "\"";
146 }
147
148 template<typename T>
GetValuesStr(const std::vector<T> & values)149 std::string GetValuesStr(const std::vector<T>& values)
150 {
151 std::string valuesStr;
152 valuesStr.append("[");
153 size_t valuesSize = values.size();
154 for (size_t i = 0; i < valuesSize; ++i) {
155 if constexpr (std::is_same_v<std::decay_t<T>, bool>) { // vector<bool> is stored as bit type
156 bool bValue = values[i];
157 valuesStr.append(GetValueStr(bValue));
158 } else {
159 valuesStr.append(GetValueStr(values[i]));
160 }
161 if (i != (valuesSize - 1)) { // -1 for last value
162 valuesStr.append(",");
163 }
164 }
165 valuesStr.append("]");
166 return valuesStr;
167 }
168
GetEmptyParamValueStr(const AppEventParamValue & value)169 std::string GetEmptyParamValueStr(const AppEventParamValue& value)
170 {
171 return "\"\"";
172 }
173
GetBoolParamValueStr(const AppEventParamValue & value)174 std::string GetBoolParamValueStr(const AppEventParamValue& value)
175 {
176 return GetValueStr(value.valueUnion.b_);
177 }
178
GetCharParamValueStr(const AppEventParamValue & value)179 std::string GetCharParamValueStr(const AppEventParamValue& value)
180 {
181 return GetValueStr(value.valueUnion.c_);
182 }
183
GetShortParamValueStr(const AppEventParamValue & value)184 std::string GetShortParamValueStr(const AppEventParamValue& value)
185 {
186 return GetValueStr(value.valueUnion.sh_);
187 }
188
GetIntParamValueStr(const AppEventParamValue & value)189 std::string GetIntParamValueStr(const AppEventParamValue& value)
190 {
191 return GetValueStr(value.valueUnion.i_);
192 }
193
GetLongParamValueStr(const AppEventParamValue & value)194 std::string GetLongParamValueStr(const AppEventParamValue& value)
195 {
196 return GetValueStr(value.valueUnion.ll_);
197 }
198
GetFloatParamValueStr(const AppEventParamValue & value)199 std::string GetFloatParamValueStr(const AppEventParamValue& value)
200 {
201 return GetValueStr(value.valueUnion.f_);
202 }
203
GetDoubleParamValueStr(const AppEventParamValue & value)204 std::string GetDoubleParamValueStr(const AppEventParamValue& value)
205 {
206 return GetValueStr(value.valueUnion.d_);
207 }
208
GetStrParamValueStr(const AppEventParamValue & value)209 std::string GetStrParamValueStr(const AppEventParamValue& value)
210 {
211 return GetValueStr(value.valueUnion.str_);
212 }
213
GetBoolsParamValueStr(const AppEventParamValue & value)214 std::string GetBoolsParamValueStr(const AppEventParamValue& value)
215 {
216 return GetValuesStr(value.valueUnion.bs_);
217 }
218
GetCharsParamValueStr(const AppEventParamValue & value)219 std::string GetCharsParamValueStr(const AppEventParamValue& value)
220 {
221 return GetValuesStr(value.valueUnion.cs_);
222 }
223
GetShortsParamValueStr(const AppEventParamValue & value)224 std::string GetShortsParamValueStr(const AppEventParamValue& value)
225 {
226 return GetValuesStr(value.valueUnion.shs_);
227 }
228
GetIntsParamValueStr(const AppEventParamValue & value)229 std::string GetIntsParamValueStr(const AppEventParamValue& value)
230 {
231 return GetValuesStr(value.valueUnion.is_);
232 }
233
GetLongsParamValueStr(const AppEventParamValue & value)234 std::string GetLongsParamValueStr(const AppEventParamValue& value)
235 {
236 return GetValuesStr(value.valueUnion.lls_);
237 }
238
GetFloatsParamValueStr(const AppEventParamValue & value)239 std::string GetFloatsParamValueStr(const AppEventParamValue& value)
240 {
241 return GetValuesStr(value.valueUnion.fs_);
242 }
243
GetDoublesParamValueStr(const AppEventParamValue & value)244 std::string GetDoublesParamValueStr(const AppEventParamValue& value)
245 {
246 return GetValuesStr(value.valueUnion.ds_);
247 }
248
GetStrsParamValueStr(const AppEventParamValue & value)249 std::string GetStrsParamValueStr(const AppEventParamValue& value)
250 {
251 return GetValuesStr(value.valueUnion.strs_);
252 }
253
254 using GetParamValueFunc = std::string (*)(const AppEventParamValue& value);
255 const std::unordered_map<AppEventParamType, GetParamValueFunc> GET_PARAM_VALUE_FUNCS = {
256 {EMPTY, &GetEmptyParamValueStr},
257 {BOOL, &GetBoolParamValueStr},
258 {CHAR, &GetCharParamValueStr},
259 {SHORT, &GetShortParamValueStr},
260 {INTEGER, &GetIntParamValueStr},
261 {LONGLONG, &GetLongParamValueStr},
262 {FLOAT, &GetFloatParamValueStr},
263 {DOUBLE, &GetDoubleParamValueStr},
264 {STRING, &GetStrParamValueStr},
265 {BVECTOR, &GetBoolsParamValueStr},
266 {CVECTOR, &GetCharsParamValueStr},
267 {SHVECTOR, &GetShortsParamValueStr},
268 {IVECTOR, &GetIntsParamValueStr},
269 {LLVECTOR, &GetLongsParamValueStr},
270 {FVECTOR, &GetFloatsParamValueStr},
271 {DVECTOR, &GetDoublesParamValueStr},
272 {STRVECTOR, &GetStrsParamValueStr},
273 };
274
GetParamValueStr(const AppEventParam & param)275 std::string GetParamValueStr(const AppEventParam& param)
276 {
277 if (GET_PARAM_VALUE_FUNCS.find(param.value.type) == GET_PARAM_VALUE_FUNCS.end()) {
278 HiLog::Warn(LABEL, "Invalid param value, name=%{public}s", param.name.c_str());
279 return "";
280 }
281 return GET_PARAM_VALUE_FUNCS.at(param.value.type)(param.value);
282 }
283 }
284
AppEventParamValue(AppEventParamType t)285 AppEventParamValue::AppEventParamValue(AppEventParamType t) : type(t), valueUnion(t)
286 {}
287
AppEventParamValue(const AppEventParamValue & other)288 AppEventParamValue::AppEventParamValue(const AppEventParamValue& other) : type(other.type)
289 {
290 if (other.type < AppEventParamType::STRING) {
291 InitValueByBaseType(this, other);
292 } else {
293 InitValueByReferType(this, other);
294 }
295 }
296
~AppEventParamValue()297 AppEventParamValue::~AppEventParamValue()
298 {
299 switch (type) {
300 case AppEventParamType::STRING:
301 valueUnion.str_.~basic_string();
302 break;
303 case AppEventParamType::BVECTOR:
304 valueUnion.bs_.~vector();
305 break;
306 case AppEventParamType::CVECTOR:
307 valueUnion.cs_.~vector();
308 break;
309 case AppEventParamType::SHVECTOR:
310 valueUnion.shs_.~vector();
311 break;
312 case AppEventParamType::IVECTOR:
313 valueUnion.is_.~vector();
314 break;
315 case AppEventParamType::LLVECTOR:
316 valueUnion.lls_.~vector();
317 break;
318 case AppEventParamType::FVECTOR:
319 valueUnion.fs_.~vector();
320 break;
321 case AppEventParamType::DVECTOR:
322 valueUnion.ds_.~vector();
323 break;
324 case AppEventParamType::STRVECTOR:
325 valueUnion.strs_.~vector();
326 break;
327 default:
328 break;
329 }
330 }
331
AppEventParam(std::string n,AppEventParamType t)332 AppEventParam::AppEventParam(std::string n, AppEventParamType t) : name(n), type(t), value(t)
333 {}
334
AppEventParam(const AppEventParam & param)335 AppEventParam::AppEventParam(const AppEventParam& param) : name(param.name), type(param.type), value(param.value)
336 {}
337
~AppEventParam()338 AppEventParam::~AppEventParam()
339 {}
340
AppEventPack(const std::string & name,int type)341 AppEventPack::AppEventPack(const std::string& name, int type) : AppEventPack(DEFAULT_DOMAIN, name, type)
342 {}
343
AppEventPack(const std::string & domain,const std::string & name,int type)344 AppEventPack::AppEventPack(const std::string& domain, const std::string& name, int type)
345 : domain_(domain), name_(name), type_(type)
346 {
347 InitTime();
348 InitTimeZone();
349 InitProcessInfo();
350 InitTraceInfo();
351 }
352
InitTime()353 void AppEventPack::InitTime()
354 {
355 time_ = TimeUtil::GetMilliseconds();
356 }
357
InitTimeZone()358 void AppEventPack::InitTimeZone()
359 {
360 timeZone_ = TimeUtil::GetTimeZone();
361 }
362
InitProcessInfo()363 void AppEventPack::InitProcessInfo()
364 {
365 pid_ = getpid();
366 tid_ = gettid();
367 }
368
InitTraceInfo()369 void AppEventPack::InitTraceInfo()
370 {
371 HiTraceId hitraceId = HiTraceChain::GetId();
372 if (!hitraceId.IsValid()) {
373 return;
374 }
375 traceId_ = static_cast<int64_t>(hitraceId.GetChainId());
376 spanId_ = static_cast<int64_t>(hitraceId.GetSpanId());
377 pspanId_ = static_cast<int64_t>(hitraceId.GetParentSpanId());
378 traceFlag_ = hitraceId.GetFlags();
379 }
380
AddParam(const std::string & key)381 void AppEventPack::AddParam(const std::string& key)
382 {
383 AppEventParam appEventParam(key, AppEventParamType::EMPTY);
384 baseParams_.emplace_back(appEventParam);
385 }
386
AddParam(const std::string & key,bool b)387 void AppEventPack::AddParam(const std::string& key, bool b)
388 {
389 AppEventParam appEventParam(key, AppEventParamType::BOOL);
390 appEventParam.value.valueUnion.b_ = b;
391 baseParams_.emplace_back(appEventParam);
392 }
393
AddParam(const std::string & key,char c)394 void AppEventPack::AddParam(const std::string& key, char c)
395 {
396 AppEventParam appEventParam(key, AppEventParamType::CHAR);
397 appEventParam.value.valueUnion.c_ = c;
398 baseParams_.emplace_back(appEventParam);
399 }
400
AddParam(const std::string & key,int8_t num)401 void AppEventPack::AddParam(const std::string& key, int8_t num)
402 {
403 AppEventParam appEventParam(key, AppEventParamType::SHORT);
404 appEventParam.value.valueUnion.sh_ = static_cast<int16_t>(num);
405 baseParams_.emplace_back(appEventParam);
406 }
407
AddParam(const std::string & key,int16_t s)408 void AppEventPack::AddParam(const std::string& key, int16_t s)
409 {
410 AppEventParam appEventParam(key, AppEventParamType::SHORT);
411 appEventParam.value.valueUnion.sh_ = s;
412 baseParams_.emplace_back(appEventParam);
413 }
414
AddParam(const std::string & key,int i)415 void AppEventPack::AddParam(const std::string& key, int i)
416 {
417 AppEventParam appEventParam(key, AppEventParamType::INTEGER);
418 appEventParam.value.valueUnion.i_ = i;
419 baseParams_.emplace_back(appEventParam);
420 }
421
AddParam(const std::string & key,int64_t ll)422 void AppEventPack::AddParam(const std::string& key, int64_t ll)
423 {
424 AppEventParam appEventParam(key, AppEventParamType::LONGLONG);
425 appEventParam.value.valueUnion.ll_ = ll;
426 baseParams_.emplace_back(appEventParam);
427 }
428
AddParam(const std::string & key,float f)429 void AppEventPack::AddParam(const std::string& key, float f)
430 {
431 AppEventParam appEventParam(key, AppEventParamType::FLOAT);
432 appEventParam.value.valueUnion.f_ = f;
433 baseParams_.emplace_back(appEventParam);
434 }
435
AddParam(const std::string & key,double d)436 void AppEventPack::AddParam(const std::string& key, double d)
437 {
438 AppEventParam appEventParam(key, AppEventParamType::DOUBLE);
439 appEventParam.value.valueUnion.d_ = d;
440 baseParams_.emplace_back(appEventParam);
441 }
442
AddParam(const std::string & key,const char * s)443 void AppEventPack::AddParam(const std::string& key, const char *s)
444 {
445 AppEventParam appEventParam(key, AppEventParamType::STRING);
446 appEventParam.value.valueUnion.str_ = s;
447 baseParams_.push_back(appEventParam);
448 }
449
AddParam(const std::string & key,const std::string & s)450 void AppEventPack::AddParam(const std::string& key, const std::string& s)
451 {
452 AppEventParam appEventParam(key, AppEventParamType::STRING);
453 appEventParam.value.valueUnion.str_ = s;
454 baseParams_.push_back(appEventParam);
455 }
456
AddParam(const std::string & key,const std::vector<bool> & bs)457 void AppEventPack::AddParam(const std::string& key, const std::vector<bool>& bs)
458 {
459 AppEventParam appEventParam(key, AppEventParamType::BVECTOR);
460 appEventParam.value.valueUnion.bs_.assign(bs.begin(), bs.end());
461 baseParams_.push_back(appEventParam);
462 }
463
AddParam(const std::string & key,const std::vector<char> & cs)464 void AppEventPack::AddParam(const std::string& key, const std::vector<char>& cs)
465 {
466 AppEventParam appEventParam(key, AppEventParamType::CVECTOR);
467 appEventParam.value.valueUnion.cs_.assign(cs.begin(), cs.end());
468 baseParams_.push_back(appEventParam);
469 }
470
AddParam(const std::string & key,const std::vector<int8_t> & shs)471 void AppEventPack::AddParam(const std::string& key, const std::vector<int8_t>& shs)
472 {
473 AppEventParam appEventParam(key, AppEventParamType::SHVECTOR);
474 appEventParam.value.valueUnion.shs_.assign(shs.begin(), shs.end());
475 baseParams_.push_back(appEventParam);
476 }
477
AddParam(const std::string & key,const std::vector<int16_t> & shs)478 void AppEventPack::AddParam(const std::string& key, const std::vector<int16_t>& shs)
479 {
480 AppEventParam appEventParam(key, AppEventParamType::SHVECTOR);
481 appEventParam.value.valueUnion.shs_.assign(shs.begin(), shs.end());
482 baseParams_.push_back(appEventParam);
483 }
484
AddParam(const std::string & key,const std::vector<int> & is)485 void AppEventPack::AddParam(const std::string& key, const std::vector<int>& is)
486 {
487 AppEventParam appEventParam(key, AppEventParamType::IVECTOR);
488 appEventParam.value.valueUnion.is_.assign(is.begin(), is.end());
489 baseParams_.push_back(appEventParam);
490 }
491
AddParam(const std::string & key,const std::vector<int64_t> & lls)492 void AppEventPack::AddParam(const std::string& key, const std::vector<int64_t>& lls)
493 {
494 AppEventParam appEventParam(key, AppEventParamType::LLVECTOR);
495 appEventParam.value.valueUnion.lls_.assign(lls.begin(), lls.end());
496 baseParams_.push_back(appEventParam);
497 }
498
AddParam(const std::string & key,const std::vector<float> & fs)499 void AppEventPack::AddParam(const std::string& key, const std::vector<float>& fs)
500 {
501 AppEventParam appEventParam(key, AppEventParamType::FVECTOR);
502 appEventParam.value.valueUnion.fs_.assign(fs.begin(), fs.end());
503 baseParams_.push_back(appEventParam);
504 }
505
AddParam(const std::string & key,const std::vector<double> & ds)506 void AppEventPack::AddParam(const std::string& key, const std::vector<double>& ds)
507 {
508 AppEventParam appEventParam(key, AppEventParamType::DVECTOR);
509 appEventParam.value.valueUnion.ds_.assign(ds.begin(), ds.end());
510 baseParams_.push_back(appEventParam);
511 }
512
AddParam(const std::string & key,const std::vector<const char * > & cps)513 void AppEventPack::AddParam(const std::string& key, const std::vector<const char*>& cps)
514 {
515 AppEventParam appEventParam(key, AppEventParamType::STRVECTOR);
516 std::vector<std::string> strs;
517 if (cps.size() != 0) {
518 for (auto cp : cps) {
519 if (cp != nullptr) {
520 strs.push_back(cp);
521 }
522 }
523 }
524 appEventParam.value.valueUnion.strs_.assign(strs.begin(), strs.end());
525 baseParams_.push_back(appEventParam);
526 }
527
AddParam(const std::string & key,const std::vector<std::string> & strs)528 void AppEventPack::AddParam(const std::string& key, const std::vector<std::string>& strs)
529 {
530 AppEventParam appEventParam(key, AppEventParamType::STRVECTOR);
531 appEventParam.value.valueUnion.strs_.assign(strs.begin(), strs.end());
532 baseParams_.push_back(appEventParam);
533 }
534
GetEventStr() const535 std::string AppEventPack::GetEventStr() const
536 {
537 std::stringstream jsonStr;
538 jsonStr << "{";
539 AddBaseInfoToJsonString(jsonStr);
540 AddParamsInfoToJsonString(jsonStr);
541 jsonStr << "}" << std::endl;
542 return jsonStr.str();
543 }
544
GetParamStr() const545 std::string AppEventPack::GetParamStr() const
546 {
547 if (!paramStr_.empty()) {
548 return paramStr_;
549 }
550
551 std::stringstream jsonStr;
552 jsonStr << "{";
553 AddParamsToJsonString(jsonStr);
554 jsonStr << "}" << std::endl;
555 return jsonStr.str();
556 }
557
AddBaseInfoToJsonString(std::stringstream & jsonStr) const558 void AppEventPack::AddBaseInfoToJsonString(std::stringstream& jsonStr) const
559 {
560 jsonStr << "\"" << "domain_" << "\":" << "\"" << domain_ << "\",";
561 jsonStr << "\"" << "name_" << "\":" << "\"" << name_ << "\",";
562 jsonStr << "\"" << "type_" << "\":" << type_ << ",";
563 jsonStr << "\"" << "time_" << "\":" << std::to_string(time_) << ",";
564 jsonStr << "\"tz_\":\"" << timeZone_ << "\",";
565 jsonStr << "\"" << "pid_" << "\":" << pid_ << ",";
566 jsonStr << "\"" << "tid_" << "\":" << tid_;
567 AddTraceInfoToJsonString(jsonStr);
568 }
569
AddTraceInfoToJsonString(std::stringstream & jsonStr) const570 void AppEventPack::AddTraceInfoToJsonString(std::stringstream& jsonStr) const
571 {
572 if (traceId_ == 0) {
573 return;
574 }
575 jsonStr << "," << "\"" << "traceid_" << "\":" << traceId_;
576 jsonStr << "," << "\"" << "spanid_" << "\":" << spanId_;
577 jsonStr << "," << "\"" << "pspanid_" << "\":" << pspanId_;
578 jsonStr << "," << "\"" << "trace_flag_" << "\":" << traceFlag_;
579 }
580
AddParamsInfoToJsonString(std::stringstream & jsonStr) const581 void AppEventPack::AddParamsInfoToJsonString(std::stringstream& jsonStr) const
582 {
583 // for event from writing
584 if (baseParams_.size() != 0) {
585 jsonStr << ",";
586 AddParamsToJsonString(jsonStr);
587 return;
588 }
589
590 // for event from the db
591 size_t paramStrLen = paramStr_.length();
592 constexpr size_t minParamStrLen = 3; // 3: '{}\0'
593 if (paramStrLen > minParamStrLen) {
594 jsonStr << "," << paramStr_.substr(1, paramStrLen - minParamStrLen); // 1: '{' for next char
595 }
596 }
597
AddParamsToJsonString(std::stringstream & jsonStr) const598 void AppEventPack::AddParamsToJsonString(std::stringstream& jsonStr) const
599 {
600 if (baseParams_.empty()) {
601 return;
602 }
603 for (const auto& param : baseParams_) {
604 jsonStr << "\"" << param.name << "\":" << GetParamValueStr(param) << ",";
605 }
606 jsonStr.seekp(-1, std::ios_base::end); // -1 for delete ','
607 }
608
GetSeq() const609 int64_t AppEventPack::GetSeq() const
610 {
611 return seq_;
612 }
613
GetDomain() const614 std::string AppEventPack::GetDomain() const
615 {
616 return domain_;
617 }
618
GetName() const619 std::string AppEventPack::GetName() const
620 {
621 return name_;
622 }
623
GetType() const624 int AppEventPack::GetType() const
625 {
626 return type_;
627 }
628
GetTime() const629 uint64_t AppEventPack::GetTime() const
630 {
631 return time_;
632 }
633
GetTimeZone() const634 std::string AppEventPack::GetTimeZone() const
635 {
636 return timeZone_;
637 }
638
GetPid() const639 int AppEventPack::GetPid() const
640 {
641 return pid_;
642 }
643
GetTid() const644 int AppEventPack::GetTid() const
645 {
646 return tid_;
647 }
648
GetTraceId() const649 int64_t AppEventPack::GetTraceId() const
650 {
651 return traceId_;
652 }
653
GetSpanId() const654 int64_t AppEventPack::GetSpanId() const
655 {
656 return spanId_;
657 }
658
GetPspanId() const659 int64_t AppEventPack::GetPspanId() const
660 {
661 return pspanId_;
662 }
663
GetTraceFlag() const664 int AppEventPack::GetTraceFlag() const
665 {
666 return traceFlag_;
667 }
668
SetSeq(int64_t seq)669 void AppEventPack::SetSeq(int64_t seq)
670 {
671 seq_ = seq;
672 }
673
SetDomain(const std::string & domain)674 void AppEventPack::SetDomain(const std::string& domain)
675 {
676 domain_ = domain;
677 }
678
SetName(const std::string & name)679 void AppEventPack::SetName(const std::string& name)
680 {
681 name_ = name;
682 }
683
SetType(int type)684 void AppEventPack::SetType(int type)
685 {
686 type_ = type;
687 }
688
SetTime(uint64_t time)689 void AppEventPack::SetTime(uint64_t time)
690 {
691 time_ = time;
692 }
693
SetTimeZone(const std::string & timeZone)694 void AppEventPack::SetTimeZone(const std::string& timeZone)
695 {
696 timeZone_ = timeZone;
697 }
698
SetPid(int pid)699 void AppEventPack::SetPid(int pid)
700 {
701 pid_ = pid;
702 }
703
SetTid(int tid)704 void AppEventPack::SetTid(int tid)
705 {
706 tid_ = tid;
707 }
708
SetTraceId(int64_t traceId)709 void AppEventPack::SetTraceId(int64_t traceId)
710 {
711 traceId_ = traceId;
712 }
713
SetSpanId(int64_t spanId)714 void AppEventPack::SetSpanId(int64_t spanId)
715 {
716 spanId_ = spanId;
717 }
718
SetPspanId(int64_t pspanId)719 void AppEventPack::SetPspanId(int64_t pspanId)
720 {
721 pspanId_ = pspanId;
722 }
723
SetTraceFlag(int traceFlag)724 void AppEventPack::SetTraceFlag(int traceFlag)
725 {
726 traceFlag_ = traceFlag;
727 }
728
SetParamStr(const std::string & paramStr)729 void AppEventPack::SetParamStr(const std::string& paramStr)
730 {
731 paramStr_ = paramStr;
732 }
733 } // namespace HiviewDFX
734 } // namespace OHOS
735