xref: /aosp_15_r20/test/dittosuite/include/ditto/tracer.h (revision 6fa2df46f119dce7527f5beb2814eca0e6f886ac)
1 // Copyright (C) 2023 The Android Open Source Project
2 //
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 #pragma once
16 
17 #include <memory>
18 #include <fstream>
19 
20 #include <benchmark.pb.h>
21 
22 
23 namespace dittosuite {
24 
25 class Tracer {
26  public:
27   Tracer();
28   ~Tracer();
29   Tracer(Tracer& other) = delete;
30 
31   void StartSession(std::unique_ptr<dittosuiteproto::Benchmark> benchmark);
32   void Start(const std::string &splice);
33   void End(const std::string &splice);
34 
35  private:
36   std::ofstream trace_marker_;
37   std::string id_;
38 };
39 
40 template <class T>
trace_format__(const T & id)41 std::string trace_format__(const T& id) {
42   return std::string("|") + id;
43 }
44 
45 template <class T, class... Args>
trace_format__(const T & id,Args...vars)46 std::string trace_format__(const T& id, Args... vars) {
47   return std::string("|") + id + trace_format__(vars...);
48 }
49 
50 template <class T>
trace_format(const T & id)51 std::string trace_format(const T& id) {
52   return id;
53 }
54 
55 template <class T, class... Args>
trace_format(const T & id,Args...vars)56 std::string trace_format(const T& id, Args... vars) {
57   std::string result;
58 
59   result = trace_format(id);
60 
61   return result + trace_format__(vars...);
62 }
63 
64 
65 }  // namespace dittosuite
66