[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>
|
---|
[744] | 10 | #include <math.h>
|
---|
| 11 | #include <algorithm>
|
---|
[656] | 12 |
|
---|
| 13 | using namespace std;
|
---|
| 14 |
|
---|
[1291] | 15 |
|
---|
| 16 |
|
---|
[667] | 17 | /** This is a small function which takes two log files and computes the
|
---|
| 18 | difference in percent of the weighted render cost.
|
---|
| 19 | */
|
---|
[668] | 20 | struct RenderStats
|
---|
[656] | 21 | {
|
---|
[668] | 22 | float mRenderCost;
|
---|
| 23 | float mAvgRenderCost;
|
---|
| 24 | };
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | typedef vector<RenderStats> StatsContainer;
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | enum {NO_TAG, RENDER_COST, AVG_RENDER_COST};
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | bool extractRenderStats(ifstream &file, StatsContainer &renderStats)
|
---|
| 34 | {
|
---|
[656] | 35 | if (!file.is_open())
|
---|
| 36 | return false;
|
---|
| 37 |
|
---|
| 38 | string buf;
|
---|
| 39 |
|
---|
[668] | 40 | int currentTag = NO_TAG;
|
---|
[675] | 41 |
|
---|
[656] | 42 | while (!(getline(file, buf)).eof())
|
---|
| 43 | {
|
---|
[668] | 44 | //cout << "buf: " << buf << endl;
|
---|
| 45 |
|
---|
[656] | 46 | if (buf[0] == '#')
|
---|
| 47 | {
|
---|
| 48 | char entry[50];
|
---|
| 49 |
|
---|
| 50 | sscanf(buf.c_str(), "#%s", entry);
|
---|
| 51 |
|
---|
[668] | 52 | // new entry
|
---|
| 53 | if (strcmp(entry, "Pass") == 0)
|
---|
| 54 | {
|
---|
| 55 | //cout << "\nnew render stat " << endl;
|
---|
| 56 | renderStats.push_back(RenderStats());
|
---|
| 57 | }
|
---|
| 58 | else if (strcmp(entry, "TotalRenderCost") == 0)
|
---|
| 59 | {
|
---|
| 60 | currentTag = RENDER_COST;
|
---|
| 61 | }
|
---|
| 62 | else if (strcmp(entry, "AvgRenderCost") == 0)
|
---|
| 63 | {
|
---|
| 64 | currentTag = AVG_RENDER_COST;
|
---|
| 65 | }
|
---|
[656] | 66 | }
|
---|
[668] | 67 | else
|
---|
[656] | 68 | {
|
---|
[668] | 69 | float val;
|
---|
| 70 | sscanf(buf.c_str(), "%f", &val);
|
---|
[656] | 71 |
|
---|
[668] | 72 | switch (currentTag)
|
---|
| 73 | {
|
---|
| 74 | case RENDER_COST:
|
---|
| 75 | //cout << "render cost: " << val << endl;
|
---|
| 76 | renderStats.back().mRenderCost = val;
|
---|
| 77 | break;
|
---|
| 78 | case AVG_RENDER_COST:
|
---|
| 79 | //cout << "avg render cost: " << val << endl;
|
---|
| 80 | renderStats.back().mAvgRenderCost = val;
|
---|
| 81 | break;
|
---|
| 82 | default:
|
---|
| 83 | break;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | currentTag = NO_TAG;
|
---|
[656] | 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return true;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
[668] | 93 |
|
---|
| 94 |
|
---|
| 95 | void ComputeStats(ofstream &statsOut,
|
---|
| 96 | const RenderStats &firstStats,
|
---|
| 97 | const RenderStats ¤tStats,
|
---|
| 98 | const int index)
|
---|
| 99 | {
|
---|
[670] | 100 | float denom = firstStats.mRenderCost ? firstStats.mRenderCost : 0.000001f;
|
---|
| 101 | float costRatio = currentStats.mRenderCost / denom;
|
---|
[668] | 102 |
|
---|
| 103 | denom = firstStats.mAvgRenderCost ? firstStats.mAvgRenderCost : 0.000001f;
|
---|
[670] | 104 | float avgCostRatio = currentStats.mAvgRenderCost / denom;
|
---|
[668] | 105 |
|
---|
| 106 | statsOut << "#ViewCells\n" << index + 1 << endl
|
---|
[675] | 107 | << "#TotalRenderCostRatio\n" << costRatio << endl
|
---|
| 108 | << "#AvgRenderCostRatio\n" << avgCostRatio << endl << endl;
|
---|
[668] | 109 | }
|
---|
| 110 |
|
---|
[736] | 111 |
|
---|
[744] | 112 | inline bool vlt(const RenderStats &c1, const RenderStats &c2)
|
---|
| 113 | {
|
---|
| 114 | return c1.mRenderCost > c2.mRenderCost;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | // evaluate number of view cells needed for same rendercost
|
---|
[733] | 119 | void EvalNumViewCells(ofstream &outstream,
|
---|
[725] | 120 | const StatsContainer &firstStats,
|
---|
[736] | 121 | const StatsContainer ¤tStats)
|
---|
[675] | 122 | {
|
---|
[733] | 123 |
|
---|
[737] | 124 | const int n = min((int)firstStats.size(), (int)currentStats.size());
|
---|
| 125 | //const int n = (int)firstStats.size();
|
---|
| 126 |
|
---|
[725] | 127 | StatsContainer::const_iterator it, it_end = currentStats.end();
|
---|
[675] | 128 |
|
---|
| 129 | int i = 0;
|
---|
[725] | 130 |
|
---|
[737] | 131 | // currentStats would be the other (necessarily worse?) method, firstStats would be our method
|
---|
| 132 | // loop through view cells of currentStats
|
---|
| 133 | // Compare render cost with render cost of other view cell
|
---|
| 134 | // compute ratio of view cells
|
---|
[736] | 135 | for (it = currentStats.begin(); it != it_end; ++ it, ++ i)
|
---|
[725] | 136 | {
|
---|
[737] | 137 |
|
---|
[725] | 138 | const float renderCost = (*it).mRenderCost;
|
---|
| 139 |
|
---|
[733] | 140 | // find equivalent render cost in the other stats container.
|
---|
| 141 | // don't stop until cursor is placed one element behind
|
---|
| 142 | // or end of vector is reached
|
---|
[1586] | 143 | StatsContainer::const_iterator equalCostIt =
|
---|
| 144 | std::upper_bound(firstStats.begin(), firstStats.end(), *it, vlt);
|
---|
[737] | 145 |
|
---|
[744] | 146 | int j = (int)(equalCostIt - firstStats.begin());
|
---|
| 147 |
|
---|
[737] | 148 | float val;
|
---|
| 149 |
|
---|
[1291] | 150 | // special cases
|
---|
[737] | 151 | if (j == 0)
|
---|
| 152 | {
|
---|
| 153 | val = (float)j;
|
---|
| 154 | }
|
---|
[744] | 155 | else if (j >= n)
|
---|
[737] | 156 | {
|
---|
| 157 | val = (float)(j - 1);
|
---|
| 158 | }
|
---|
[744] | 159 | else
|
---|
| 160 | // interpolate linearly. NOTE: probably big error because of steep curve
|
---|
| 161 | // => intepolate logarithmically
|
---|
[737] | 162 | {
|
---|
[744] | 163 | #if 1
|
---|
| 164 | const float rcu = log(firstStats[j - 1].mRenderCost);
|
---|
| 165 | const float rcl = log(firstStats[j].mRenderCost);
|
---|
| 166 | const float rc = log(renderCost);
|
---|
| 167 | #else
|
---|
[737] | 168 | const float rcu = firstStats[j - 1].mRenderCost;
|
---|
| 169 | const float rcl = firstStats[j].mRenderCost;
|
---|
[744] | 170 | const float rc = renderCost;
|
---|
| 171 | #endif
|
---|
[737] | 172 | const float factor = (rcu - rcl != 0) ?
|
---|
[744] | 173 | (rcu - rc) / (rcu - rcl) : 1;
|
---|
[737] | 174 |
|
---|
[744] | 175 | // view cells needed for same render cost
|
---|
[737] | 176 | val = (float)j - 1 + factor;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | float ratio = (i && val) ? (float)i / val : 1;
|
---|
[733] | 180 |
|
---|
[736] | 181 | outstream << "#Pass\n" << i << endl;
|
---|
| 182 | outstream << "#RenderCost\n" << renderCost << endl;
|
---|
| 183 | outstream << "#ViewCellsRatio\n" << ratio << endl << endl;
|
---|
[725] | 184 | }
|
---|
[675] | 185 | }
|
---|
| 186 |
|
---|
[733] | 187 |
|
---|
[827] | 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | // evaluate number of view cells needed for same rendercost
|
---|
| 192 | int EvalSingleNumViewCells(const StatsContainer ¤tStats,
|
---|
| 193 | const float cost)
|
---|
| 194 | {
|
---|
| 195 |
|
---|
| 196 | StatsContainer::const_iterator it, it_end = currentStats.end();
|
---|
| 197 |
|
---|
| 198 | RenderStats dummy; dummy.mRenderCost = cost;
|
---|
| 199 |
|
---|
| 200 | // find equivalent render cost in the other stats container.
|
---|
| 201 | // don't stop until cursor is placed one element behind
|
---|
| 202 | // or end of vector is reached
|
---|
| 203 | StatsContainer::const_iterator equalCostIt = std::upper_bound(currentStats.begin(),currentStats.end(), dummy, vlt);
|
---|
| 204 |
|
---|
| 205 | int j = (int)(equalCostIt - currentStats.begin());
|
---|
| 206 |
|
---|
| 207 | return j;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 |
|
---|
| 211 |
|
---|
[656] | 212 | int _tmain(int argc, _TCHAR* argv[])
|
---|
| 213 | {
|
---|
[668] | 214 | vector<StatsContainer> renderStats;
|
---|
[656] | 215 |
|
---|
[668] | 216 | if (argc < 3)
|
---|
[667] | 217 | {
|
---|
[668] | 218 | cerr << "arguments missing. Usage: input1 input2 ... intputn" << endl;
|
---|
[667] | 219 | exit(1);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[668] | 222 | vector<string> outFilenames;
|
---|
[736] | 223 | vector<string> outFilenames2;
|
---|
[827] | 224 | vector<string> methodnames;
|
---|
[668] | 225 | // read input files from command line
|
---|
| 226 | for (int i = 1; i < argc; ++ i)
|
---|
| 227 | {
|
---|
| 228 | StatsContainer currentStats;
|
---|
| 229 |
|
---|
[675] | 230 | ifstream file;
|
---|
| 231 | file.open(argv[i]);
|
---|
[667] | 232 |
|
---|
[668] | 233 | // extract the render cost
|
---|
| 234 | cout << "extracting render cost of file " << argv[i] << endl;
|
---|
[675] | 235 |
|
---|
| 236 | if (extractRenderStats(file, currentStats))
|
---|
| 237 | {
|
---|
| 238 | renderStats.push_back(currentStats);
|
---|
[656] | 239 |
|
---|
[675] | 240 | // create output file name
|
---|
| 241 | string fn = argv[i];
|
---|
[668] | 242 |
|
---|
[675] | 243 | string::size_type pos = fn.find(".log", 0);
|
---|
| 244 | fn.erase(pos, 4);
|
---|
| 245 | //sscanf(argv[i], "%s.log", fn);
|
---|
| 246 | string outFilename = string(fn) + string("-ratio.log");
|
---|
[736] | 247 | string outFilename2 = string(fn) + string("-reverse.log");
|
---|
[827] | 248 |
|
---|
[675] | 249 | outFilenames.push_back(outFilename);
|
---|
[736] | 250 | outFilenames2.push_back(outFilename2);
|
---|
[827] | 251 | methodnames.push_back(fn);
|
---|
| 252 |
|
---|
[736] | 253 | cout << "new filen: " << outFilename2 << endl;
|
---|
[675] | 254 | }
|
---|
| 255 | else
|
---|
| 256 | {
|
---|
| 257 | cout << "could not open file!" << endl;
|
---|
| 258 | }
|
---|
[668] | 259 | }
|
---|
[667] | 260 |
|
---|
[668] | 261 | //statsOut << "rc1 size: " << (int)renderCosts1.size() << " " << (int)renderCosts2.size() << endl << endl;
|
---|
| 262 | vector<StatsContainer>::const_iterator it = renderStats.begin(), it_end = renderStats.end();
|
---|
[736] | 263 |
|
---|
[668] | 264 | vector<string>::const_iterator sit, sit_end = outFilenames.end();
|
---|
[736] | 265 | vector<string>::const_iterator sit2, sit2_end = outFilenames2.end();
|
---|
[827] | 266 | vector<string>::const_iterator sit3, sit3_end = methodnames.end();
|
---|
[667] | 267 |
|
---|
[827] | 268 |
|
---|
[668] | 269 | sit = outFilenames.begin();
|
---|
[736] | 270 | sit2 = outFilenames2.begin();
|
---|
[827] | 271 | sit3 = methodnames.begin();
|
---|
[736] | 272 |
|
---|
[668] | 273 | // compare all values with this vector
|
---|
| 274 | StatsContainer &firstStats = renderStats[0];
|
---|
[656] | 275 |
|
---|
[668] | 276 | // don't compare with itself
|
---|
[675] | 277 | //++ it;
|
---|
| 278 | //++ sit;
|
---|
[827] | 279 | ofstream statsOut3;
|
---|
| 280 | statsOut3.open("numviewcells.log");
|
---|
[668] | 281 |
|
---|
[827] | 282 | for (it; it != it_end; ++ it, ++ sit, ++ sit2, ++sit3)
|
---|
[656] | 283 | {
|
---|
[675] | 284 | cout << "now writing output to file " << *sit << endl;
|
---|
[827] | 285 |
|
---|
[675] | 286 | ofstream statsOut;
|
---|
| 287 | statsOut.open((*sit).c_str());
|
---|
[827] | 288 |
|
---|
[736] | 289 | ofstream statsOut2;
|
---|
| 290 | statsOut2.open((*sit2).c_str());
|
---|
[668] | 291 |
|
---|
[736] | 292 | cout << "opening new file: " << (*sit2).c_str() << endl;
|
---|
[668] | 293 | // compute size of output vector
|
---|
| 294 | const int n = min((int)firstStats.size(), (int)(*it).size());
|
---|
| 295 |
|
---|
| 296 | for (int i = 0; i < n; ++ i)
|
---|
| 297 | {
|
---|
[744] | 298 | //cout << "rc: " << (*it)[i].mRenderCost << endl;
|
---|
[668] | 299 | ComputeStats(statsOut, firstStats[i], (*it)[i], i);
|
---|
| 300 | }
|
---|
[744] | 301 |
|
---|
| 302 | // evaluate number of view cells needed for same rendercost
|
---|
[736] | 303 | EvalNumViewCells(statsOut2, firstStats, (*it));
|
---|
| 304 |
|
---|
[827] | 305 | const float rendercost = 100;
|
---|
| 306 | const int j = EvalSingleNumViewCells(*it, rendercost);
|
---|
| 307 |
|
---|
| 308 | statsOut3 << (*sit3).c_str() << " " << j << endl;
|
---|
| 309 |
|
---|
[668] | 310 | statsOut.close();
|
---|
[736] | 311 | statsOut2.close();
|
---|
[656] | 312 | }
|
---|
| 313 |
|
---|
[827] | 314 | statsOut3.close();
|
---|
| 315 |
|
---|
| 316 |
|
---|
| 317 |
|
---|
[656] | 318 | return 0;
|
---|
| 319 | }
|
---|
| 320 |
|
---|