]> git.cworth.org Git - apitrace/blob - common/trace_profiler.hpp
42fd032008ca668b4fe3767947b092005996f426
[apitrace] / common / trace_profiler.hpp
1 /**************************************************************************
2  *
3  * Copyright 2012 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 #ifndef TRACE_PROFILER_H
27 #define TRACE_PROFILER_H
28
29 #include <string>
30 #include <vector>
31 #include <stdint.h>
32
33 namespace trace
34 {
35
36 struct Profile {
37     struct CpuCall {
38         unsigned no;
39
40         int64_t cpuStart;
41         int64_t cpuDuration;
42
43         std::string name;
44     };
45
46     struct DrawCall {
47         unsigned no;
48
49         int64_t gpuStart;
50         int64_t gpuDuration;
51
52         int64_t cpuStart;
53         int64_t cpuDuration;
54
55         int64_t pixels;
56
57         std::string name;
58     };
59
60     struct Frame {
61         unsigned no;
62
63         int64_t gpuStart;
64         int64_t gpuDuration;
65
66         int64_t cpuStart;
67         int64_t cpuDuration;
68     };
69
70     struct Program {
71         Program() : gpuTotal(0), cpuTotal(0), pixelTotal(0) {}
72
73         uint64_t gpuTotal;
74         uint64_t cpuTotal;
75         uint64_t pixelTotal;
76         std::vector<DrawCall> drawCalls;
77     };
78
79     std::vector<Frame> frames;
80     std::vector<Program> programs;
81     std::vector<CpuCall> cpuCalls;
82 };
83
84 class Profiler
85 {
86 public:
87     Profiler();
88     ~Profiler();
89
90     void setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_);
91
92     void addCall(unsigned no,
93                  const char* name,
94                  unsigned program,
95                  int64_t pixels,
96                  int64_t gpuStart, int64_t gpuDuration,
97                  int64_t cpuStart, int64_t cpuDuration);
98
99     void addFrameEnd();
100
101     bool hasBaseTimes();
102
103     void setBaseCpuTime(int64_t cpuStart);
104     void setBaseGpuTime(int64_t gpuStart);
105
106     int64_t getBaseCpuTime();
107     int64_t getBaseGpuTime();
108
109     static void parseLine(const char* line, Profile* profile);
110
111 private:
112     int64_t baseGpuTime;
113     int64_t baseCpuTime;
114     int64_t minCpuTime;
115
116     bool cpuTimes;
117     bool gpuTimes;
118     bool pixelsDrawn;
119 };
120 }
121
122 #endif // TRACE_PROFILER_H