• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef TEST_WUKONG_CSV_UTILS_H
17 #define TEST_WUKONG_CSV_UTILS_H
18 
19 #include <fstream>
20 #include <iostream>
21 
22 #include "wukong_define.h"
23 
24 namespace OHOS {
25 namespace WuKong {
26 class CsvUtils {
27 public:
28     struct OneLineData {
29         std::string domain;
30         std::string name;
31         std::string type;
32         uint64_t time;
33         std::string timeZone;
34         uint64_t pid;
35         uint64_t tid;
36         uint64_t uid;
37         uint64_t traceId;
38         uint64_t spanId;
39         uint64_t pspanId;
40         uint64_t traceFlag;
41     };
42 
WriteHeader(std::ofstream & csvFile)43     static void WriteHeader(std::ofstream &csvFile)
44     {
45         csvFile << "Domain" << ',';
46         csvFile << "EventName" << ',';
47         csvFile << "Type" << ',';
48         csvFile << "Time" << ',';
49         csvFile << "TimeZone" << ',';
50         csvFile << "ProcessId" << ',';
51         csvFile << "ThreadId" << ',';
52         csvFile << "UserId" << ',';
53         csvFile << "TraceId" << ',';
54         csvFile << "SpanId" << ',';
55         csvFile << "PSpanid" << ',';
56         csvFile << "TraceFlag" << std::endl;
57     }
58 
WriteOneLine(std::ofstream & csvFile,const OneLineData & data)59     static void WriteOneLine(std::ofstream &csvFile, const OneLineData &data)
60     {
61         csvFile << data.domain << ',';
62         csvFile << data.name << ',';
63         csvFile << data.type << ',';
64         csvFile << data.time << ',';
65         csvFile << data.timeZone << ',';
66         csvFile << data.pid << ',';
67         csvFile << data.tid << ',';
68         csvFile << data.uid << ',';
69         csvFile << data.traceId << ',';
70         csvFile << data.spanId << ',';
71         csvFile << data.pspanId << ',';
72         csvFile << data.traceFlag << std::endl;
73     }
74 };
75 }  // namespace WuKong
76 }  // namespace OHOS
77 
78 #endif  // WUKONG_WUKONG_CSV_UTILS_H
79