1 /*
2 * Copyright (c) 2021-2022 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 <sys/time.h>
23 #include <unistd.h>
24 #include <vector>
25
26 #include "hilog/log.h"
27
28 namespace OHOS {
29 namespace HiviewDFX {
30 namespace {
31 const HiLogLabel LABEL = { LOG_CORE, HIAPPEVENT_DOMAIN, "HiAppEvent_base" };
32 constexpr int SEC_TO_HOUR = 3600;
33 constexpr int SEC_TO_MIN = 60;
34 const std::string DEFAULT_DOMAIN = "default";
35
TrimRightZero(const std::string & str)36 std::string TrimRightZero(const std::string& str)
37 {
38 auto endIndex = str.find_last_not_of("0");
39 if (endIndex == std::string::npos) {
40 return str;
41 }
42
43 return (str[endIndex] == '.') ? str.substr(0, endIndex) : str.substr(0, endIndex + 1);
44 }
45
GetTimeInfo()46 std::string GetTimeInfo()
47 {
48 // get system timestamp
49 struct timeval tv;
50 if (gettimeofday(&tv, nullptr) != 0) {
51 HiLog::Error(LABEL, "failed to execute the gettimeofday function.");
52 return "";
53 }
54 int64_t timeMillSec = static_cast<int64_t>(tv.tv_sec) * 1000 + tv.tv_usec / 1000; // 1000 means milliseconds
55 std::stringstream ss;
56 ss << "\"" << "time_" << "\":" << std::to_string(timeMillSec) << ",";
57
58 // Get system time zone
59 time_t sysSec = tv.tv_sec;
60 struct tm tmLocal;
61 if (localtime_r(&sysSec, &tmLocal) == nullptr) {
62 HiLog::Error(LABEL, "failed to get local time.");
63 return ss.str();
64 }
65 struct tm tmUtc;
66 if (gmtime_r(&sysSec, &tmUtc) == nullptr) {
67 HiLog::Error(LABEL, "failed to get GMT time.");
68 return ss.str();
69 }
70 time_t diffSec = mktime(&tmLocal) - mktime(&tmUtc);
71 ss << "\"tz_\":\"" << ((diffSec < 0) ? "-" : "+");
72
73 int tzHour = std::abs(diffSec) / SEC_TO_HOUR;
74 if (tzHour > 12) { // max time zone is 12
75 HiLog::Error(LABEL, "failed to get hours for time zone, set to 0.");
76 tzHour = 0;
77 }
78 int tzMin = (std::abs(diffSec) % SEC_TO_HOUR) / SEC_TO_MIN;
79 ss << std::setw(2) << std::setfill('0') << tzHour; // the number of digits in the hour is 2
80 ss << std::setw(2) << std::setfill('0') << tzMin << "\","; // the number of digits in the min is 2
81
82 return ss.str();
83 }
84
InitValueByBaseType(AppEventParamValue * value,const AppEventParamValue & other)85 void InitValueByBaseType(AppEventParamValue* value, const AppEventParamValue& other)
86 {
87 if (value == nullptr) {
88 return;
89 }
90
91 switch (other.type) {
92 case AppEventParamType::BOOL:
93 value->valueUnion.b_ = other.valueUnion.b_;
94 break;
95 case AppEventParamType::CHAR:
96 value->valueUnion.c_ = other.valueUnion.c_;
97 break;
98 case AppEventParamType::SHORT:
99 value->valueUnion.sh_ = other.valueUnion.sh_;
100 break;
101 case AppEventParamType::INTEGER:
102 value->valueUnion.i_ = other.valueUnion.i_;
103 break;
104 case AppEventParamType::LONGLONG:
105 value->valueUnion.ll_ = other.valueUnion.ll_;
106 break;
107 case AppEventParamType::FLOAT:
108 value->valueUnion.f_ = other.valueUnion.f_;
109 break;
110 case AppEventParamType::DOUBLE:
111 value->valueUnion.d_ = other.valueUnion.d_;
112 break;
113 default:
114 break;
115 }
116 }
117
InitValueByReferType(AppEventParamValue * value,const AppEventParamValue & other)118 void InitValueByReferType(AppEventParamValue* value, const AppEventParamValue& other)
119 {
120 if (value == nullptr) {
121 return;
122 }
123
124 switch (other.type) {
125 case AppEventParamType::STRING:
126 new (&value->valueUnion.str_) auto(other.valueUnion.str_);
127 break;
128 case AppEventParamType::BVECTOR:
129 new (&value->valueUnion.bs_) auto(other.valueUnion.bs_);
130 break;
131 case AppEventParamType::CVECTOR:
132 new (&value->valueUnion.cs_) auto(other.valueUnion.cs_);
133 break;
134 case AppEventParamType::SHVECTOR:
135 new (&value->valueUnion.shs_) auto(other.valueUnion.shs_);
136 break;
137 case AppEventParamType::IVECTOR:
138 new (&value->valueUnion.is_) auto(other.valueUnion.is_);
139 break;
140 case AppEventParamType::LLVECTOR:
141 new (&value->valueUnion.lls_) auto(other.valueUnion.lls_);
142 break;
143 case AppEventParamType::FVECTOR:
144 new (&value->valueUnion.fs_) auto(other.valueUnion.fs_);
145 break;
146 case AppEventParamType::DVECTOR:
147 new (&value->valueUnion.ds_) auto(other.valueUnion.ds_);
148 break;
149 case AppEventParamType::STRVECTOR:
150 new (&value->valueUnion.strs_) auto(other.valueUnion.strs_);
151 break;
152 default:
153 break;
154 }
155 }
156 }
157
AppEventParamValue(AppEventParamType t)158 AppEventParamValue::AppEventParamValue(AppEventParamType t) : type(t), valueUnion(t)
159 {}
160
AppEventParamValue(const AppEventParamValue & other)161 AppEventParamValue::AppEventParamValue(const AppEventParamValue& other) : type(other.type)
162 {
163 if (other.type < AppEventParamType::STRING) {
164 InitValueByBaseType(this, other);
165 } else {
166 InitValueByReferType(this, other);
167 }
168 }
169
~AppEventParamValue()170 AppEventParamValue::~AppEventParamValue()
171 {
172 switch (type) {
173 case AppEventParamType::STRING:
174 valueUnion.str_.~basic_string();
175 break;
176 case AppEventParamType::BVECTOR:
177 valueUnion.bs_.~vector();
178 break;
179 case AppEventParamType::CVECTOR:
180 valueUnion.cs_.~vector();
181 break;
182 case AppEventParamType::SHVECTOR:
183 valueUnion.shs_.~vector();
184 break;
185 case AppEventParamType::IVECTOR:
186 valueUnion.is_.~vector();
187 break;
188 case AppEventParamType::LLVECTOR:
189 valueUnion.lls_.~vector();
190 break;
191 case AppEventParamType::FVECTOR:
192 valueUnion.fs_.~vector();
193 break;
194 case AppEventParamType::DVECTOR:
195 valueUnion.ds_.~vector();
196 break;
197 case AppEventParamType::STRVECTOR:
198 valueUnion.strs_.~vector();
199 break;
200 default:
201 break;
202 }
203 }
204
AppEventParam(std::string n,AppEventParamType t)205 AppEventParam::AppEventParam(std::string n, AppEventParamType t) : name(n), type(t), value(t)
206 {}
207
AppEventParam(const AppEventParam & param)208 AppEventParam::AppEventParam(const AppEventParam& param) : name(param.name), type(param.type), value(param.value)
209 {}
210
~AppEventParam()211 AppEventParam::~AppEventParam()
212 {}
213
AppEventPack(const std::string & name,int type)214 AppEventPack::AppEventPack(const std::string& name, int type) : AppEventPack(DEFAULT_DOMAIN, name, type)
215 {}
216
AppEventPack(const std::string & domain,const std::string & name,int type)217 AppEventPack::AppEventPack(const std::string& domain, const std::string& name, int type)
218 : domain_(domain), name_(name), type_(type)
219 {}
220
AddParam(const std::string & key)221 void AppEventPack::AddParam(const std::string& key)
222 {
223 AppEventParam appEventParam(key, AppEventParamType::EMPTY);
224 baseParams_.emplace_back(appEventParam);
225 }
226
AddParam(const std::string & key,bool b)227 void AppEventPack::AddParam(const std::string& key, bool b)
228 {
229 AppEventParam appEventParam(key, AppEventParamType::BOOL);
230 appEventParam.value.valueUnion.b_ = b;
231 baseParams_.emplace_back(appEventParam);
232 }
233
AddParam(const std::string & key,char c)234 void AppEventPack::AddParam(const std::string& key, char c)
235 {
236 AppEventParam appEventParam(key, AppEventParamType::CHAR);
237 appEventParam.value.valueUnion.c_ = c;
238 baseParams_.emplace_back(appEventParam);
239 }
240
AddParam(const std::string & key,int8_t num)241 void AppEventPack::AddParam(const std::string& key, int8_t num)
242 {
243 AppEventParam appEventParam(key, AppEventParamType::SHORT);
244 appEventParam.value.valueUnion.sh_ = static_cast<int16_t>(num);
245 baseParams_.emplace_back(appEventParam);
246 }
247
AddParam(const std::string & key,int16_t s)248 void AppEventPack::AddParam(const std::string& key, int16_t s)
249 {
250 AppEventParam appEventParam(key, AppEventParamType::SHORT);
251 appEventParam.value.valueUnion.sh_ = s;
252 baseParams_.emplace_back(appEventParam);
253 }
254
AddParam(const std::string & key,int i)255 void AppEventPack::AddParam(const std::string& key, int i)
256 {
257 AppEventParam appEventParam(key, AppEventParamType::INTEGER);
258 appEventParam.value.valueUnion.i_ = i;
259 baseParams_.emplace_back(appEventParam);
260 }
261
AddParam(const std::string & key,int64_t ll)262 void AppEventPack::AddParam(const std::string& key, int64_t ll)
263 {
264 AppEventParam appEventParam(key, AppEventParamType::LONGLONG);
265 appEventParam.value.valueUnion.ll_ = ll;
266 baseParams_.emplace_back(appEventParam);
267 }
268
AddParam(const std::string & key,float f)269 void AppEventPack::AddParam(const std::string& key, float f)
270 {
271 AppEventParam appEventParam(key, AppEventParamType::FLOAT);
272 appEventParam.value.valueUnion.f_ = f;
273 baseParams_.emplace_back(appEventParam);
274 }
275
AddParam(const std::string & key,double d)276 void AppEventPack::AddParam(const std::string& key, double d)
277 {
278 AppEventParam appEventParam(key, AppEventParamType::DOUBLE);
279 appEventParam.value.valueUnion.d_ = d;
280 baseParams_.emplace_back(appEventParam);
281 }
282
AddParam(const std::string & key,const char * s)283 void AppEventPack::AddParam(const std::string& key, const char *s)
284 {
285 AppEventParam appEventParam(key, AppEventParamType::STRING);
286 appEventParam.value.valueUnion.str_ = s;
287 baseParams_.push_back(appEventParam);
288 }
289
AddParam(const std::string & key,const std::string & s)290 void AppEventPack::AddParam(const std::string& key, const std::string& s)
291 {
292 AppEventParam appEventParam(key, AppEventParamType::STRING);
293 appEventParam.value.valueUnion.str_ = s;
294 baseParams_.push_back(appEventParam);
295 }
296
AddParam(const std::string & key,const std::vector<bool> & bs)297 void AppEventPack::AddParam(const std::string& key, const std::vector<bool>& bs)
298 {
299 AppEventParam appEventParam(key, AppEventParamType::BVECTOR);
300 appEventParam.value.valueUnion.bs_.assign(bs.begin(), bs.end());
301 baseParams_.push_back(appEventParam);
302 }
303
AddParam(const std::string & key,const std::vector<char> & cs)304 void AppEventPack::AddParam(const std::string& key, const std::vector<char>& cs)
305 {
306 AppEventParam appEventParam(key, AppEventParamType::CVECTOR);
307 appEventParam.value.valueUnion.cs_.assign(cs.begin(), cs.end());
308 baseParams_.push_back(appEventParam);
309 }
310
AddParam(const std::string & key,const std::vector<int8_t> & shs)311 void AppEventPack::AddParam(const std::string& key, const std::vector<int8_t>& shs)
312 {
313 AppEventParam appEventParam(key, AppEventParamType::SHVECTOR);
314 appEventParam.value.valueUnion.shs_.assign(shs.begin(), shs.end());
315 baseParams_.push_back(appEventParam);
316 }
317
AddParam(const std::string & key,const std::vector<int16_t> & shs)318 void AppEventPack::AddParam(const std::string& key, const std::vector<int16_t>& shs)
319 {
320 AppEventParam appEventParam(key, AppEventParamType::SHVECTOR);
321 appEventParam.value.valueUnion.shs_.assign(shs.begin(), shs.end());
322 baseParams_.push_back(appEventParam);
323 }
324
AddParam(const std::string & key,const std::vector<int> & is)325 void AppEventPack::AddParam(const std::string& key, const std::vector<int>& is)
326 {
327 AppEventParam appEventParam(key, AppEventParamType::IVECTOR);
328 appEventParam.value.valueUnion.is_.assign(is.begin(), is.end());
329 baseParams_.push_back(appEventParam);
330 }
331
AddParam(const std::string & key,const std::vector<int64_t> & lls)332 void AppEventPack::AddParam(const std::string& key, const std::vector<int64_t>& lls)
333 {
334 AppEventParam appEventParam(key, AppEventParamType::LLVECTOR);
335 appEventParam.value.valueUnion.lls_.assign(lls.begin(), lls.end());
336 baseParams_.push_back(appEventParam);
337 }
338
AddParam(const std::string & key,const std::vector<float> & fs)339 void AppEventPack::AddParam(const std::string& key, const std::vector<float>& fs)
340 {
341 AppEventParam appEventParam(key, AppEventParamType::FVECTOR);
342 appEventParam.value.valueUnion.fs_.assign(fs.begin(), fs.end());
343 baseParams_.push_back(appEventParam);
344 }
345
AddParam(const std::string & key,const std::vector<double> & ds)346 void AppEventPack::AddParam(const std::string& key, const std::vector<double>& ds)
347 {
348 AppEventParam appEventParam(key, AppEventParamType::DVECTOR);
349 appEventParam.value.valueUnion.ds_.assign(ds.begin(), ds.end());
350 baseParams_.push_back(appEventParam);
351 }
352
AddParam(const std::string & key,const std::vector<const char * > & cps)353 void AppEventPack::AddParam(const std::string& key, const std::vector<const char*>& cps)
354 {
355 AppEventParam appEventParam(key, AppEventParamType::STRVECTOR);
356 std::vector<std::string> strs;
357 if (cps.size() != 0) {
358 for (auto cp : cps) {
359 if (cp != nullptr) {
360 strs.push_back(cp);
361 }
362 }
363 }
364 appEventParam.value.valueUnion.strs_.assign(strs.begin(), strs.end());
365 baseParams_.push_back(appEventParam);
366 }
367
AddParam(const std::string & key,const std::vector<std::string> & strs)368 void AppEventPack::AddParam(const std::string& key, const std::vector<std::string>& strs)
369 {
370 AppEventParam appEventParam(key, AppEventParamType::STRVECTOR);
371 appEventParam.value.valueUnion.strs_.assign(strs.begin(), strs.end());
372 baseParams_.push_back(appEventParam);
373 }
374
AddBaseInfoToJsonString(std::stringstream & jsonStr) const375 void AppEventPack::AddBaseInfoToJsonString(std::stringstream& jsonStr) const
376 {
377 jsonStr << "\"" << "domain_" << "\":" << "\"" << domain_ << "\",";
378 jsonStr << "\"" << "name_" << "\":" << "\"" << name_ << "\",";
379 jsonStr << "\"" << "type_" << "\":" << type_ << ",";
380 jsonStr << GetTimeInfo();
381 jsonStr << "\"" << "pid_" << "\":" << getpid() << ",";
382 jsonStr << "\"" << "tid_" << "\":" << gettid() << ",";
383 }
384
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<bool> & bs) const385 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<bool>& bs) const
386 {
387 jsonStr << "[";
388 size_t len = bs.size();
389 if (len == 0) {
390 jsonStr << "],";
391 HiLog::Info(LABEL, "The vector<bool> value added to JsonString is empty.");
392 return;
393 }
394
395 for (size_t i = 0; i < len - 1; i++) {
396 jsonStr << (bs[i] ? "true" : "false") << ",";
397 }
398 jsonStr << (bs[len - 1] ? "true" : "false") << "],";
399 }
400
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<char> & cs) const401 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<char>& cs) const
402 {
403 jsonStr << "[";
404 size_t len = cs.size();
405 if (len == 0) {
406 jsonStr << "],";
407 HiLog::Info(LABEL, "The vector<char> value added to JsonString is empty.");
408 return;
409 }
410
411 for (size_t i = 0; i < len - 1; i++) {
412 jsonStr << "\"" << cs[i] << "\"" << ",";
413 }
414 jsonStr << "\"" << cs[len - 1] << "\"" << "],";
415 }
416
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<int16_t> & shs) const417 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<int16_t>& shs) const
418 {
419 jsonStr << "[";
420 size_t len = shs.size();
421 if (len == 0) {
422 jsonStr << "],";
423 HiLog::Info(LABEL, "The vector<int16_t> value added to JsonString is empty.");
424 return;
425 }
426
427 for (size_t i = 0; i < len - 1; i++) {
428 jsonStr << shs[i] << ",";
429 }
430 jsonStr << shs[len - 1] << "],";
431 }
432
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<int> & is) const433 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<int>& is) const
434 {
435 jsonStr << "[";
436 size_t len = is.size();
437 if (len == 0) {
438 jsonStr << "],";
439 HiLog::Info(LABEL, "The vector<int> value added to JsonString is empty.");
440 return;
441 }
442
443 for (size_t i = 0; i < len - 1; i++) {
444 jsonStr << is[i] << ",";
445 }
446 jsonStr << is[len - 1] << "],";
447 }
448
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<int64_t> & lls) const449 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<int64_t>& lls) const
450 {
451 jsonStr << "[";
452 size_t len = lls.size();
453 if (len == 0) {
454 jsonStr << "],";
455 HiLog::Info(LABEL, "The vector<int64_t> value added to JsonString is empty.");
456 return;
457 }
458
459 for (size_t i = 0; i < len - 1; i++) {
460 jsonStr << lls[i] << ",";
461 }
462 jsonStr << lls[len - 1] << "],";
463 }
464
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<float> & fs) const465 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<float>& fs) const
466 {
467 jsonStr << "[";
468 size_t len = fs.size();
469 if (len == 0) {
470 jsonStr << "],";
471 HiLog::Info(LABEL, "The vector<float> value added to JsonString is empty.");
472 return;
473 }
474
475 for (size_t i = 0; i < len - 1; i++) {
476 jsonStr << TrimRightZero(std::to_string(fs[i])) << ",";
477 }
478 jsonStr << TrimRightZero(std::to_string(fs[len - 1])) << "],";
479 }
480
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<double> & ds) const481 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<double>& ds) const
482 {
483 jsonStr << "[";
484 size_t len = ds.size();
485 if (len == 0) {
486 jsonStr << "],";
487 HiLog::Info(LABEL, "The vector<double> value added to JsonString is empty.");
488 return;
489 }
490
491 for (size_t i = 0; i < len - 1; i++) {
492 jsonStr << TrimRightZero(std::to_string(ds[i])) << ",";
493 }
494 jsonStr << TrimRightZero(std::to_string(ds[len - 1])) << "],";
495 }
496
AddVectorToJsonString(std::stringstream & jsonStr,const std::vector<std::string> & strs) const497 void AppEventPack::AddVectorToJsonString(std::stringstream& jsonStr, const std::vector<std::string>& strs) const
498 {
499 jsonStr << "[";
500 size_t len = strs.size();
501 if (len == 0) {
502 jsonStr << "],";
503 HiLog::Info(LABEL, "The vector<string> value added to JsonString is empty.");
504 return;
505 }
506
507 for (size_t i = 0; i < len - 1; i++) {
508 jsonStr << "\"" << strs[i] << "\",";
509 }
510 jsonStr << "\"" << strs[len - 1] << "\"],";
511 }
512
AddOthersToJsonString(std::stringstream & jsonStr,const AppEventParam param) const513 void AppEventPack::AddOthersToJsonString(std::stringstream& jsonStr, const AppEventParam param) const
514 {
515 if (param.type == AppEventParamType::BVECTOR) {
516 AddVectorToJsonString(jsonStr, param.value.valueUnion.bs_);
517 } else if (param.type == AppEventParamType::CVECTOR) {
518 AddVectorToJsonString(jsonStr, param.value.valueUnion.cs_);
519 } else if (param.type == AppEventParamType::SHVECTOR) {
520 AddVectorToJsonString(jsonStr, param.value.valueUnion.shs_);
521 } else if (param.type == AppEventParamType::IVECTOR) {
522 AddVectorToJsonString(jsonStr, param.value.valueUnion.is_);
523 } else if (param.type == AppEventParamType::LLVECTOR) {
524 AddVectorToJsonString(jsonStr, param.value.valueUnion.lls_);
525 } else if (param.type == AppEventParamType::FVECTOR) {
526 AddVectorToJsonString(jsonStr, param.value.valueUnion.fs_);
527 } else if (param.type == AppEventParamType::DVECTOR) {
528 AddVectorToJsonString(jsonStr, param.value.valueUnion.ds_);
529 } else if (param.type == AppEventParamType::STRVECTOR) {
530 AddVectorToJsonString(jsonStr, param.value.valueUnion.strs_);
531 } else if (param.type == AppEventParamType::EMPTY) {
532 jsonStr << "[]" << ",";
533 } else {
534 jsonStr << "\"\",";
535 }
536 }
537
GetEventDomain() const538 const std::string AppEventPack::GetEventDomain() const
539 {
540 return domain_;
541 }
542
GetEventName() const543 const std::string AppEventPack::GetEventName() const
544 {
545 return name_;
546 }
547
GetType() const548 int AppEventPack::GetType() const
549 {
550 return type_;
551 }
552
GetJsonString() const553 std::string AppEventPack::GetJsonString() const
554 {
555 std::stringstream jsonStr;
556 jsonStr << "{";
557 AddBaseInfoToJsonString(jsonStr);
558 for (auto it = baseParams_.begin(); it != baseParams_.end(); it++) {
559 jsonStr << "\"" << it->name << "\":";
560 if (it->type == AppEventParamType::BOOL) {
561 jsonStr << ((it->value.valueUnion.b_) ? "true" : "false") << ",";
562 } else if (it->type == AppEventParamType::CHAR) {
563 jsonStr << "\"" << it->value.valueUnion.c_ << "\"" << ",";
564 } else if (it->type == AppEventParamType::SHORT) {
565 jsonStr << it->value.valueUnion.sh_ << ",";
566 } else if (it->type == AppEventParamType::INTEGER) {
567 jsonStr << it->value.valueUnion.i_ << ",";
568 } else if (it->type == AppEventParamType::LONGLONG) {
569 jsonStr << it->value.valueUnion.ll_ << ",";
570 } else if (it->type == AppEventParamType::FLOAT) {
571 jsonStr << TrimRightZero(std::to_string(it->value.valueUnion.f_)) << ",";
572 } else if (it->type == AppEventParamType::DOUBLE) {
573 jsonStr << TrimRightZero(std::to_string(it->value.valueUnion.d_)) << ",";
574 } else if (it->type == AppEventParamType::STRING) {
575 jsonStr << "\"" << it->value.valueUnion.str_ << "\",";
576 } else {
577 AddOthersToJsonString(jsonStr, *it);
578 }
579 }
580
581 jsonStr.seekp(-1, std::ios_base::end);
582 jsonStr << "}" << std::endl;
583 return jsonStr.str();
584 }
585 } // namespace HiviewDFX
586 } // namespace OHOS
587