]> git.cworth.org Git - apitrace/blob - common/trace_profiler.hpp
78783f5a57653d33a0d0fe99a7fa4aef1b98887d
[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(uint64_t gpuStart, uint64_t cpuStart);
75
76     void addFrameStart(unsigned no, uint64_t gpuStart, uint64_t cpuStart);
77     void addFrameEnd(uint64_t gpuEnd, uint64_t cpuEnd);
78
79     void addCall(unsigned no,
80                  const char* name,
81                  unsigned program,
82                  uint64_t pixels,
83                  uint64_t gpuStart, uint64_t gpuDuration,
84                  uint64_t cpuStart, uint64_t cpuDuration);
85
86     static void parseLine(const char* line, Profile* profile);
87
88 private:
89     uint64_t baseGpuTime;
90     uint64_t baseCpuTime;
91
92     bool cpuTimes;
93     bool gpuTimes;
94     bool pixelsDrawn;
95
96     struct {
97         unsigned no;
98         uint64_t gpuStart;
99         uint64_t cpuStart;
100     } lastFrame;
101 };
102 }
103
104 #endif // TRACE_PROFILER_H