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 #pragma once 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 40 unsigned program; 41 42 int64_t gpuStart; 43 int64_t gpuDuration; 44 45 int64_t cpuStart; 46 int64_t cpuDuration; 47 48 int64_t vsizeStart; 49 int64_t vsizeDuration; 50 int64_t rssStart; 51 int64_t rssDuration; 52 53 int64_t pixels; 54 55 std::string name; 56 }; 57 58 struct Frame { 59 unsigned no; 60 61 int64_t gpuStart; 62 int64_t gpuDuration; 63 64 int64_t cpuStart; 65 int64_t cpuDuration; 66 67 int64_t vsizeStart; 68 int64_t vsizeDuration; 69 int64_t rssStart; 70 int64_t rssDuration; 71 72 /* Indices to profile->calls array */ 73 struct { 74 unsigned begin; 75 unsigned end; 76 } calls; 77 }; 78 79 struct Program { Programtrace::Profile::Program80 Program() : gpuTotal(0), cpuTotal(0), pixelTotal(0) {} 81 82 uint64_t gpuTotal; 83 uint64_t cpuTotal; 84 uint64_t pixelTotal; 85 int64_t vsizeTotal; 86 int64_t rssTotal; 87 88 /* Indices to profile->calls array */ 89 std::vector<unsigned> calls; 90 }; 91 92 std::vector<Call> calls; 93 std::vector<Frame> frames; 94 std::vector<Program> programs; 95 }; 96 97 class Profiler 98 { 99 public: 100 Profiler(); 101 ~Profiler(); 102 103 void setup(bool cpuTimes_, bool gpuTimes_, bool pixelsDrawn_, bool memoryUsage_, int64_t minCpuTime_); 104 105 void addCall(unsigned no, 106 const char* name, 107 unsigned program, 108 int64_t pixels, 109 int64_t gpuStart, int64_t gpuDuration, 110 int64_t cpuStart, int64_t cpuDuration, 111 int64_t vsizeStart, int64_t vsizeDuration, 112 int64_t rssStart, int64_t rssDuration); 113 114 void addFrameEnd(); 115 116 bool hasBaseTimes(); 117 118 void setBaseCpuTime(int64_t cpuStart); 119 void setBaseGpuTime(int64_t gpuStart); 120 void setBaseVsizeUsage(int64_t vsizeStart); 121 void setBaseRssUsage(int64_t rssStart); 122 123 int64_t getBaseCpuTime(); 124 int64_t getBaseGpuTime(); 125 int64_t getBaseVsizeUsage(); 126 int64_t getBaseRssUsage(); 127 128 static void parseLine(const char* line, Profile* profile); 129 130 private: 131 int64_t baseGpuTime; 132 int64_t baseCpuTime; 133 int64_t minCpuTime; 134 int64_t baseVsizeUsage; 135 int64_t baseRssUsage; 136 137 bool cpuTimes; 138 bool gpuTimes; 139 bool pixelsDrawn; 140 bool memoryUsage; 141 }; 142 } 143 144