[656] | 1 | // EvalStats.cpp : Defines the entry point for the console application.
|
---|
| 2 | //
|
---|
| 3 | #include "stdafx.h"
|
---|
| 4 |
|
---|
| 5 | #include <string>
|
---|
| 6 | #include <vector>
|
---|
| 7 | #include <istream>
|
---|
| 8 | #include <iostream>
|
---|
| 9 | #include <fstream>
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | using namespace std;
|
---|
| 13 |
|
---|
[667] | 14 | /** This is a small function which takes two log files and computes the
|
---|
| 15 | difference in percent of the weighted render cost.
|
---|
| 16 | */
|
---|
[668] | 17 |
|
---|
| 18 |
|
---|
| 19 | struct RenderStats
|
---|
[656] | 20 | {
|
---|
[668] | 21 | float mRenderCost;
|
---|
| 22 | float mAvgRenderCost;
|
---|
| 23 | };
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | typedef vector<RenderStats> StatsContainer;
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | enum {NO_TAG, RENDER_COST, AVG_RENDER_COST};
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | bool extractRenderStats(ifstream &file, StatsContainer &renderStats)
|
---|
| 33 | {
|
---|
[656] | 34 | if (!file.is_open())
|
---|
| 35 | return false;
|
---|
| 36 |
|
---|
| 37 | string buf;
|
---|
| 38 |
|
---|
[668] | 39 | int currentTag = NO_TAG;
|
---|
[675] | 40 |
|
---|
[656] | 41 | while (!(getline(file, buf)).eof())
|
---|
| 42 | {
|
---|
[668] | 43 | //cout << "buf: " << buf << endl;
|
---|
| 44 |
|
---|
[656] | 45 | if (buf[0] == '#')
|
---|
| 46 | {
|
---|
| 47 | char entry[50];
|
---|
| 48 |
|
---|
| 49 | sscanf(buf.c_str(), "#%s", entry);
|
---|
| 50 |
|
---|
[668] | 51 | // new entry
|
---|
| 52 | if (strcmp(entry, "Pass") == 0)
|
---|
| 53 | {
|
---|
| 54 | //cout << "\nnew render stat " << endl;
|
---|
| 55 | renderStats.push_back(RenderStats());
|
---|
| 56 | }
|
---|
| 57 | else if (strcmp(entry, "TotalRenderCost") == 0)
|
---|
| 58 | {
|
---|
| 59 | currentTag = RENDER_COST;
|
---|
| 60 | }
|
---|
| 61 | else if (strcmp(entry, "AvgRenderCost") == 0)
|
---|
| 62 | {
|
---|
| 63 | currentTag = AVG_RENDER_COST;
|
---|
| 64 | }
|
---|
[656] | 65 | }
|
---|
[668] | 66 | else
|
---|
[656] | 67 | {
|
---|
[668] | 68 | float val;
|
---|
| 69 | sscanf(buf.c_str(), "%f", &val);
|
---|
[656] | 70 |
|
---|
[668] | 71 | switch (currentTag)
|
---|
| 72 | {
|
---|
| 73 | case RENDER_COST:
|
---|
| 74 | //cout << "render cost: " << val << endl;
|
---|
| 75 | renderStats.back().mRenderCost = val;
|
---|
| 76 | break;
|
---|
| 77 | case AVG_RENDER_COST:
|
---|
| 78 | //cout << "avg render cost: " << val << endl;
|
---|
| 79 | renderStats.back().mAvgRenderCost = val;
|
---|
| 80 | break;
|
---|
| 81 | default:
|
---|
| 82 | break;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | currentTag = NO_TAG;
|
---|
[656] | 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | return true;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[668] | 92 |
|
---|
| 93 |
|
---|
| 94 | void ComputeStats(ofstream &statsOut,
|
---|
| 95 | const RenderStats &firstStats,
|
---|
| 96 | const RenderStats ¤tStats,
|
---|
| 97 | const int index)
|
---|
| 98 | {
|
---|
[670] | 99 | float denom = firstStats.mRenderCost ? firstStats.mRenderCost : 0.000001f;
|
---|
| 100 | float costRatio = currentStats.mRenderCost / denom;
|
---|
[668] | 101 |
|
---|
| 102 | denom = firstStats.mAvgRenderCost ? firstStats.mAvgRenderCost : 0.000001f;
|
---|
[670] | 103 | float avgCostRatio = currentStats.mAvgRenderCost / denom;
|
---|
[668] | 104 |
|
---|
| 105 | statsOut << "#ViewCells\n" << index + 1 << endl
|
---|
[670] | 106 | //<< "#TotalRenderCostGain\n" << 100.0f - costRatio * 100.0f << endl
|
---|
| 107 | //<< "#AvgRenderCostGain\n" << 100.0f - avgCostRatio * 100.0f << endl << endl;
|
---|
[675] | 108 | << "#TotalRenderCostRatio\n" << costRatio << endl
|
---|
| 109 | << "#AvgRenderCostRatio\n" << avgCostRatio << endl << endl;
|
---|
[668] | 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
[675] | 113 | int ComputeNoViewCells(const StatsContainer &firstStats,
|
---|
| 114 | const StatsContainer ¤tStats)
|
---|
| 115 | {
|
---|
| 116 | const int n = min((int)firstStats.size(), (int)currentStats.size());
|
---|
[668] | 117 |
|
---|
[675] | 118 | const float renderCost = (int)currentStats[n - 1].mRenderCost;
|
---|
| 119 |
|
---|
| 120 | int i = 0;
|
---|
| 121 | while ((i ++ < (int)firstStats.size()) && (renderCost > (int)firstStats[i].mRenderCost));
|
---|
| 122 |
|
---|
| 123 | return i;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
[656] | 127 | int _tmain(int argc, _TCHAR* argv[])
|
---|
| 128 | {
|
---|
[668] | 129 | vector<StatsContainer> renderStats;
|
---|
[656] | 130 |
|
---|
[668] | 131 | if (argc < 3)
|
---|
[667] | 132 | {
|
---|
[668] | 133 | cerr << "arguments missing. Usage: input1 input2 ... intputn" << endl;
|
---|
[667] | 134 | exit(1);
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[668] | 137 | vector<string> outFilenames;
|
---|
[667] | 138 |
|
---|
[668] | 139 | // read input files from command line
|
---|
| 140 | for (int i = 1; i < argc; ++ i)
|
---|
| 141 | {
|
---|
| 142 | StatsContainer currentStats;
|
---|
| 143 |
|
---|
[675] | 144 | ifstream file;
|
---|
| 145 | file.open(argv[i]);
|
---|
[667] | 146 |
|
---|
[668] | 147 | // extract the render cost
|
---|
| 148 | cout << "extracting render cost of file " << argv[i] << endl;
|
---|
[675] | 149 |
|
---|
| 150 | if (extractRenderStats(file, currentStats))
|
---|
| 151 | {
|
---|
| 152 | renderStats.push_back(currentStats);
|
---|
[656] | 153 |
|
---|
[675] | 154 | // create output file name
|
---|
| 155 | string fn = argv[i];
|
---|
[668] | 156 |
|
---|
[675] | 157 | string::size_type pos = fn.find(".log", 0);
|
---|
| 158 | fn.erase(pos, 4);
|
---|
| 159 | //sscanf(argv[i], "%s.log", fn);
|
---|
| 160 | string outFilename = string(fn) + string("-ratio.log");
|
---|
[656] | 161 |
|
---|
[675] | 162 | outFilenames.push_back(outFilename);
|
---|
| 163 | }
|
---|
| 164 | else
|
---|
| 165 | {
|
---|
| 166 | cout << "could not open file!" << endl;
|
---|
| 167 | }
|
---|
[668] | 168 | }
|
---|
[667] | 169 |
|
---|
[668] | 170 | //statsOut << "rc1 size: " << (int)renderCosts1.size() << " " << (int)renderCosts2.size() << endl << endl;
|
---|
| 171 | vector<StatsContainer>::const_iterator it = renderStats.begin(), it_end = renderStats.end();
|
---|
| 172 | vector<string>::const_iterator sit, sit_end = outFilenames.end();
|
---|
[667] | 173 |
|
---|
[668] | 174 | sit = outFilenames.begin();
|
---|
[656] | 175 |
|
---|
[668] | 176 | // compare all values with this vector
|
---|
| 177 | StatsContainer &firstStats = renderStats[0];
|
---|
[656] | 178 |
|
---|
[668] | 179 | // don't compare with itself
|
---|
[675] | 180 | //++ it;
|
---|
| 181 | //++ sit;
|
---|
[668] | 182 |
|
---|
| 183 | for (it; it != it_end; ++ it)
|
---|
[656] | 184 | {
|
---|
[675] | 185 | cout << "now writing output to file " << *sit << endl;
|
---|
| 186 | ofstream statsOut;
|
---|
| 187 | statsOut.open((*sit).c_str());
|
---|
[668] | 188 |
|
---|
| 189 | // compute size of output vector
|
---|
| 190 | const int n = min((int)firstStats.size(), (int)(*it).size());
|
---|
| 191 |
|
---|
| 192 | for (int i = 0; i < n; ++ i)
|
---|
| 193 | {
|
---|
| 194 | ComputeStats(statsOut, firstStats[i], (*it)[i], i);
|
---|
| 195 | }
|
---|
[670] | 196 |
|
---|
[675] | 197 | int vc = ComputeNoViewCells(firstStats, *it);
|
---|
| 198 | cout << "need " << vc << " view cells to reach rendercost of method " << i << " with " << n << " view cells" << endl;
|
---|
| 199 |
|
---|
[668] | 200 | statsOut.close();
|
---|
[675] | 201 |
|
---|
| 202 | ++ sit;
|
---|
[656] | 203 | }
|
---|
| 204 |
|
---|
| 205 | return 0;
|
---|
| 206 | }
|
---|
| 207 |
|
---|