• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef TRACE_CONVERTER_H
16 #define TRACE_CONVERTER_H
17 
18 #include <map>
19 #include "trace_file_reader.h"
20 #include "trace_plugin_result.pb.h"
21 
22 class TracePluginResult;
23 
24 class TraceConverter {
25 public:
26     void SetInput(const std::string& input);
27     void SetOutput(const std::string& output);
28     bool Convert();
29     void SetParseGid(bool parseGid);
30     void SetParseFlags(bool parseFlags);
31 
32 private:
33     bool WriteInitialHeader();
34     bool WriteFinalHeader();
35     bool WriteEvent(const FtraceEvent& event, int cpu);
36     std::string FormatEvent(const FtraceEvent& event, int cpu);
37     void ParseCpuStats(const FtraceCpuStatsMsg& cpuStats);
38     void SummarizeStats();
39     bool ReadAndParseEvents();
40     bool ConvertAndWriteEvents();
41 
42     void PrintTextHeader(const std::string& msg);
43     static void PrintCpuStats(const FtraceCpuStatsMsg& cpuStats);
44     static void PrintTraceFileHeader(const TraceFileHeader& header);
45     static std::string TraceFlagsToString(uint32_t flags, uint32_t preemptCount);
46 
47     std::string GenerateNewEntriesValue(uint32_t orginLength);
48     std::string GenerateNewNumProcsValue(uint32_t originLength);
49 
50 private:
51     bool parseGid_ = false;
52     bool parseFlags_ = false;
53     int numProcessors_ = 0;
54     std::vector<PerCpuStatsMsg> startStats_ = {};
55     std::vector<PerCpuStatsMsg> endStats_ = {};
56     PerCpuStatsMsg startSum_ = {};
57     PerCpuStatsMsg endSum_ = {};
58     uint32_t entriesInBuffer_ = 0;
59     uint32_t entriesWritten_ = 0;
60     uint32_t numberResults_ = 0;
61     TraceFileReader reader_ = {};
62     int outputFd_ = -1;
63     std::string output_ = "";
64     std::string input_ = "";
65     std::string textHeader_ = "";
66     std::vector<int> resultsIndex_ = {};
67     std::map<uint64_t, std::string> kernelSymbols_ = {};
68     std::vector<std::vector<FtraceEvent>> cpuEventQeueue_;
69 };
70 #endif // TRACE_CONVERTER_H