1a69a01cdSopenharmony_ci/* 2a69a01cdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3a69a01cdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a69a01cdSopenharmony_ci * you may not use this file except in compliance with the License. 5a69a01cdSopenharmony_ci * You may obtain a copy of the License at 6a69a01cdSopenharmony_ci * 7a69a01cdSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a69a01cdSopenharmony_ci * 9a69a01cdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a69a01cdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a69a01cdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a69a01cdSopenharmony_ci * See the License for the specific language governing permissions and 13a69a01cdSopenharmony_ci * limitations under the License. 14a69a01cdSopenharmony_ci */ 15a69a01cdSopenharmony_ci 16a69a01cdSopenharmony_ci#ifndef TEST_WUKONG_CSV_UTILS_H 17a69a01cdSopenharmony_ci#define TEST_WUKONG_CSV_UTILS_H 18a69a01cdSopenharmony_ci 19a69a01cdSopenharmony_ci#include <fstream> 20a69a01cdSopenharmony_ci#include <iostream> 21a69a01cdSopenharmony_ci 22a69a01cdSopenharmony_ci#include "wukong_define.h" 23a69a01cdSopenharmony_ci 24a69a01cdSopenharmony_cinamespace OHOS { 25a69a01cdSopenharmony_cinamespace WuKong { 26a69a01cdSopenharmony_ciclass CsvUtils { 27a69a01cdSopenharmony_cipublic: 28a69a01cdSopenharmony_ci struct OneLineData { 29a69a01cdSopenharmony_ci std::string domain; 30a69a01cdSopenharmony_ci std::string name; 31a69a01cdSopenharmony_ci std::string type; 32a69a01cdSopenharmony_ci uint64_t time; 33a69a01cdSopenharmony_ci std::string timeZone; 34a69a01cdSopenharmony_ci uint64_t pid; 35a69a01cdSopenharmony_ci uint64_t tid; 36a69a01cdSopenharmony_ci uint64_t uid; 37a69a01cdSopenharmony_ci uint64_t traceId; 38a69a01cdSopenharmony_ci uint64_t spanId; 39a69a01cdSopenharmony_ci uint64_t pspanId; 40a69a01cdSopenharmony_ci uint64_t traceFlag; 41a69a01cdSopenharmony_ci }; 42a69a01cdSopenharmony_ci 43a69a01cdSopenharmony_ci static void WriteHeader(std::ofstream &csvFile) 44a69a01cdSopenharmony_ci { 45a69a01cdSopenharmony_ci csvFile << "Domain" << ','; 46a69a01cdSopenharmony_ci csvFile << "EventName" << ','; 47a69a01cdSopenharmony_ci csvFile << "Type" << ','; 48a69a01cdSopenharmony_ci csvFile << "Time" << ','; 49a69a01cdSopenharmony_ci csvFile << "TimeZone" << ','; 50a69a01cdSopenharmony_ci csvFile << "ProcessId" << ','; 51a69a01cdSopenharmony_ci csvFile << "ThreadId" << ','; 52a69a01cdSopenharmony_ci csvFile << "UserId" << ','; 53a69a01cdSopenharmony_ci csvFile << "TraceId" << ','; 54a69a01cdSopenharmony_ci csvFile << "SpanId" << ','; 55a69a01cdSopenharmony_ci csvFile << "PSpanid" << ','; 56a69a01cdSopenharmony_ci csvFile << "TraceFlag" << std::endl; 57a69a01cdSopenharmony_ci } 58a69a01cdSopenharmony_ci 59a69a01cdSopenharmony_ci static void WriteOneLine(std::ofstream &csvFile, const OneLineData &data) 60a69a01cdSopenharmony_ci { 61a69a01cdSopenharmony_ci if (!csvFile.is_open()) { 62a69a01cdSopenharmony_ci return; 63a69a01cdSopenharmony_ci } 64a69a01cdSopenharmony_ci csvFile << data.domain << ','; 65a69a01cdSopenharmony_ci csvFile << data.name << ','; 66a69a01cdSopenharmony_ci csvFile << data.type << ','; 67a69a01cdSopenharmony_ci csvFile << data.time << ','; 68a69a01cdSopenharmony_ci csvFile << data.timeZone << ','; 69a69a01cdSopenharmony_ci csvFile << data.pid << ','; 70a69a01cdSopenharmony_ci csvFile << data.tid << ','; 71a69a01cdSopenharmony_ci csvFile << data.uid << ','; 72a69a01cdSopenharmony_ci csvFile << data.traceId << ','; 73a69a01cdSopenharmony_ci csvFile << data.spanId << ','; 74a69a01cdSopenharmony_ci csvFile << data.pspanId << ','; 75a69a01cdSopenharmony_ci csvFile << data.traceFlag << std::endl; 76a69a01cdSopenharmony_ci } 77a69a01cdSopenharmony_ci}; 78a69a01cdSopenharmony_ci} // namespace WuKong 79a69a01cdSopenharmony_ci} // namespace OHOS 80a69a01cdSopenharmony_ci 81a69a01cdSopenharmony_ci#endif // WUKONG_WUKONG_CSV_UTILS_H 82