// EvalStats.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include using namespace std; /** This is a small function which takes two log files and computes the difference in percent of the weighted render cost. */ struct RenderStats { float mRenderCost; float mAvgRenderCost; }; typedef vector StatsContainer; enum {NO_TAG, RENDER_COST, AVG_RENDER_COST}; bool extractRenderStats(ifstream &file, StatsContainer &renderStats) { if (!file.is_open()) return false; string buf; int currentTag = NO_TAG; while (!(getline(file, buf)).eof()) { //cout << "buf: " << buf << endl; if (buf[0] == '#') { char entry[50]; sscanf(buf.c_str(), "#%s", entry); // new entry if (strcmp(entry, "Pass") == 0) { //cout << "\nnew render stat " << endl; renderStats.push_back(RenderStats()); } else if (strcmp(entry, "TotalRenderCost") == 0) { currentTag = RENDER_COST; } else if (strcmp(entry, "AvgRenderCost") == 0) { currentTag = AVG_RENDER_COST; } } else { float val; sscanf(buf.c_str(), "%f", &val); switch (currentTag) { case RENDER_COST: //cout << "render cost: " << val << endl; renderStats.back().mRenderCost = val; break; case AVG_RENDER_COST: //cout << "avg render cost: " << val << endl; renderStats.back().mAvgRenderCost = val; break; default: break; } currentTag = NO_TAG; } } return true; } void ComputeStats(ofstream &statsOut, const RenderStats &firstStats, const RenderStats ¤tStats, const int index) { float denom = firstStats.mRenderCost ? firstStats.mRenderCost : 0.000001f; float costRatio = currentStats.mRenderCost / denom; denom = firstStats.mAvgRenderCost ? firstStats.mAvgRenderCost : 0.000001f; float avgCostRatio = currentStats.mAvgRenderCost / denom; statsOut << "#ViewCells\n" << index + 1 << endl //<< "#TotalRenderCostGain\n" << 100.0f - costRatio * 100.0f << endl //<< "#AvgRenderCostGain\n" << 100.0f - avgCostRatio * 100.0f << endl << endl; << "#TotalRenderCostRatio\n" << costRatio << endl << "#AvgRenderCostRatio\n" << avgCostRatio << endl << endl; } int ComputeNoViewCells(const StatsContainer &firstStats, const StatsContainer ¤tStats) { const int n = min((int)firstStats.size(), (int)currentStats.size()); const float renderCost = (int)currentStats[n - 1].mRenderCost; int i = 0; while ((i ++ < (int)firstStats.size()) && (renderCost > (int)firstStats[i].mRenderCost)); return i; } int _tmain(int argc, _TCHAR* argv[]) { vector renderStats; if (argc < 3) { cerr << "arguments missing. Usage: input1 input2 ... intputn" << endl; exit(1); } vector outFilenames; // read input files from command line for (int i = 1; i < argc; ++ i) { StatsContainer currentStats; ifstream file; file.open(argv[i]); // extract the render cost cout << "extracting render cost of file " << argv[i] << endl; if (extractRenderStats(file, currentStats)) { renderStats.push_back(currentStats); // create output file name string fn = argv[i]; string::size_type pos = fn.find(".log", 0); fn.erase(pos, 4); //sscanf(argv[i], "%s.log", fn); string outFilename = string(fn) + string("-ratio.log"); outFilenames.push_back(outFilename); } else { cout << "could not open file!" << endl; } } //statsOut << "rc1 size: " << (int)renderCosts1.size() << " " << (int)renderCosts2.size() << endl << endl; vector::const_iterator it = renderStats.begin(), it_end = renderStats.end(); vector::const_iterator sit, sit_end = outFilenames.end(); sit = outFilenames.begin(); // compare all values with this vector StatsContainer &firstStats = renderStats[0]; // don't compare with itself //++ it; //++ sit; for (it; it != it_end; ++ it) { cout << "now writing output to file " << *sit << endl; ofstream statsOut; statsOut.open((*sit).c_str()); // compute size of output vector const int n = min((int)firstStats.size(), (int)(*it).size()); for (int i = 0; i < n; ++ i) { ComputeStats(statsOut, firstStats[i], (*it)[i], i); } int vc = ComputeNoViewCells(firstStats, *it); cout << "need " << vc << " view cells to reach rendercost of method " << i << " with " << n << " view cells" << endl; statsOut.close(); ++ sit; } return 0; }