]> git.cworth.org Git - apitrace/blob - common/trace_profiler.hpp
CPU Profiling now includes all OpenGL calls (was only draw calls).
[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 Call {
38         unsigned no;
39         int64_t gpuStart;
40         int64_t gpuDuration;
41         int64_t cpuStart;
42         int64_t cpuDuration;
43         int64_t pixels;
44         unsigned program;
45         std::string name;
46
47         typedef std::vector<Call>::iterator iterator;
48         typedef std::vector<Call>::const_iterator const_iterator;
49     };
50
51     struct Frame {
52         unsigned no;
53         int64_t gpuStart;
54         int64_t gpuDuration;
55         int64_t cpuStart;
56         int64_t cpuDuration;
57
58         std::vector<Call> calls;
59
60         typedef std::vector<Frame>::iterator iterator;
61         typedef std::vector<Frame>::const_iterator const_iterator;
62     };
63
64     std::vector<Frame> frames;
65 };
66
67 class Profiler
68 {
69 public:
70     Profiler();
71     ~Profiler();
72
73     void setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_);
74     void setBaseTimes(int64_t gpuStart, int64_t cpuStart);
75     bool hasBaseTimes();
76
77     void addFrameStart(unsigned no, int64_t gpuStart, int64_t cpuStart);
78     void addFrameEnd(int64_t gpuEnd, int64_t cpuEnd);
79
80     void addCall(unsigned no,
81                  const char* name,
82                  unsigned program,
83                  int64_t pixels,
84                  int64_t gpuStart, int64_t gpuDuration,
85                  int64_t cpuStart, int64_t cpuDuration);
86
87     static void parseLine(const char* line, Profile* profile);
88
89 private:
90     int64_t baseGpuTime;
91     int64_t baseCpuTime;
92
93     bool cpuTimes;
94     bool gpuTimes;
95     bool pixelsDrawn;
96
97     struct {
98         unsigned no;
99         int64_t gpuStart;
100         int64_t cpuStart;
101     } lastFrame;
102 };
103 }
104
105 #endif // TRACE_PROFILER_H