1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef TOOLS_TRACE_PROCESSOR_VTSTRACEPROCESSOR_H_
18 #define TOOLS_TRACE_PROCESSOR_VTSTRACEPROCESSOR_H_
19 
20 #include <android-base/macros.h>
21 #include <test/vts/proto/VtsProfilingMessage.pb.h>
22 
23 namespace android {
24 namespace vts {
25 
26 class VtsTraceProcessor {
27  public:
28   VtsTraceProcessor() {};
29   virtual ~VtsTraceProcessor() {};
30 
31   // Cleanups the given trace file to be used for replaying.
32   // Current cleanup includes:
33   // 1. remove duplicate trace item (e.g. passthrough event on the server side)
34   // 2. remove trace item that could not be replayed (e.g. client event on the
35   //    server side).
36   void CleanupTraceForReplay(const std::string& trace_file);
37   // Parses the given trace file and outputs the latency for each API call.
38   void ProcessTraceForLatencyProfiling(const std::string& trace_file);
39   // Parses all trace files under the the given trace directory and remove
40   // duplicate trace file.
41   void DedupTraces(const std::string& trace_dir);
42 
43  private:
44   // Reads the trace file and parse each trace event into VtsProfilingRecord.
45   bool ParseTrace(const std::string& trace_file, bool ignore_timestamp,
46       bool entry_only, VtsProfilingMessage* profiling_msg);
47   // Writes the given list of VtsProfilingRecord into an output file.
48   bool WriteRecords(const std::string& output_file,
49       const std::vector<VtsProfilingRecord>& records);
50 
51   DISALLOW_COPY_AND_ASSIGN (VtsTraceProcessor);
52 };
53 
54 }  // namespace vts
55 }  // namespace android
56 #endif  // TOOLS_TRACE_PROCESSOR_VTSTRACEPROCESSOR_H_
57