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