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