GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
html_reporter.hpp
Go to the documentation of this file.
1 
31 #ifndef GRAPHCHI_HTML_REPORTER
32 #define GRAPHCHI_HTML_REPORTER
33 
34 #include <cstdio>
35 
36 #include "metrics/metrics.hpp"
37 
38 
43 namespace graphchi {
44 
45  class html_reporter : public imetrics_reporter {
46  private:
47  html_reporter() {}
48 
49  std::string filename;
50  FILE * f;
51  public:
52 
53 
54  html_reporter(std::string fname) : filename(fname) {
55  // Create new file
56  f = fopen(fname.c_str(), "w");
57  assert(f != NULL);
58  fprintf(f, "<html><head><title>GraphCHI Metrics Report</title>");
59  fprintf(f, "<style>\n");
60  fprintf(f, "table { border: 1px solid #999999; font: normal 80%%/140%% arial, helvetica, sans-serif; color: #555; background: #fff;} td, th {border: 1px dotted #bbb; padding: .5em; width:100px} ");
61  fprintf(f, "</style></head><body>");
62  }
63 
64  virtual ~html_reporter() {
65  fprintf(f, "</body></html>");
66  fclose(f);
67  }
68 
69  virtual void do_report(std::string name, std::string ident, std::map<std::string, metrics_entry> & entries) {
70  if (ident != name) {
71  fprintf(f, "<h3>%s:%s</h3>\n", name.c_str(), ident.c_str());
72  } else {
73  fprintf(f, "<h3>%s</h3>\n", name.c_str());
74  }
75 
76 
77  // First write numeral, then timings, then string entries
78  for(int round=0; round<4; round++) {
79  std::map<std::string, metrics_entry>::iterator it;
80  int c = 0;
81  fprintf(f, "<!-- Round %d -->\n", round);
82  fprintf(f, "\n<p>");
83  for(it = entries.begin(); it != entries.end(); ++it) {
84  metrics_entry ent = it->second;
85  switch(ent.valtype) {
86  case INTEGER:
87  if (round == 0) {
88  if (c++ == 0)
89  fprintf(f, "<table><tr><th>Key</th><th>Value</th><th>Count</th><th>Min</th><th>Max</th><th>Average</th></tr>");
90 
91  fprintf(f, "<tr><td>%s</td>\n", it->first.c_str());
92 
93  fprintf(f, "<td>%ld</td>\n", (long int) ent.value);
94  if (ent.count > 1) {
95  fprintf(f, "<td>%ld</td>\n", (long int) ent.count);
96  fprintf(f, "<td>%ld</td>\n", (long int) ent.minvalue);
97  fprintf(f, "<td>%ld</td>\n", (long int) ent.maxvalue);
98  fprintf(f, "<td>%.3lf</td>\n", ent.cumvalue/(double)ent.count);
99  } else fprintf(f, "<td colspan=4>&nbsp;</td>");
100  fprintf(f, "</tr>");
101  }
102  break;
103  case REAL:
104  if (round == 0) {
105  if (c++ == 0)
106  fprintf(f, "<table><tr><th>Key</th><th>Value</th><th>Count</th><th>Min</th><th>Max</th><th>Average</th></tr>");
107  }
108  case TIME:
109  if (ent.valtype == TIME && round == 1) {
110  if (c++ == 0)
111  fprintf(f, "<table><tr><th>Key</th><th>Value (sec)</th><th>Count</th><th>Min (sec)</th><th>Max (sec)</th><th>Average (sec)</th></tr>\n");
112  }
113  if ((round == 0 && ent.valtype == REAL)||(round == 1 && ent.valtype == TIME)) {
114  fprintf(f, "<tr><td>%s</td>\n", it->first.c_str());
115 
116  fprintf(f, "<td>%lf</td>\n", ent.value);
117  if (ent.count > 1) {
118  fprintf(f, "<td>%ld</td>\n", (long int) ent.count);
119  fprintf(f, "<td>%.3lf</td>\n", ent.minvalue);
120  fprintf(f, "<td>%.3lf</td>\n", ent.maxvalue);
121  fprintf(f, "<td>%.3lf</td>\n", ent.cumvalue/(double)ent.count);
122  } else fprintf(f, "<td colspan=4>&nbsp;</td>");
123  fprintf(f, "</tr>");
124  }
125  break;
126  case STRING:
127  if (round == 2) {
128  if (c++ == 0)
129  fprintf(f, "<table><tr><th>Key</th><th>Value</th></tr>\n");
130  fprintf(f, "<tr><td>%s</td><td width=400>%s</td>\n", it->first.c_str(), ent.stringval.c_str());
131  fprintf(f, "</tr>");
132  }
133 
134  break;
135  case VECTOR:
136  if (round == 3) {
137  // TODO
138  }
139  break;
140  }
141  }
142  if (c>0) fprintf(f, "</table>");
143  fprintf(f, " </p>");
144  }
145 
146  fflush(f);
147  };
148 
149  };
150 
151 };
152 
153 
154 
155 #endif
156 
157 
158