GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
file_reporter.hpp
Go to the documentation of this file.
1 
30 #ifndef DEF_GRAPHCHI_FILE_REPORTER
31 #define DEF_GRAPHCHI_FILE_REPORTER
32 
33 #include <fstream>
34 #include <cstdio>
35 
37 
38 
39 
40 
41 namespace graphchi {
42 
44  private:
45  file_reporter() {}
46 
47  std::string filename;
48  FILE * f;
49  public:
50 
51 
52  file_reporter(std::string fname) : filename(fname) {
53  // Create new file
54  f = fopen(fname.c_str(), "a");
55  assert(f != NULL);
56  }
57 
58  virtual void do_report(std::string name, std::string ident, std::map<std::string, metrics_entry> & entries) {
59  if (ident != name) {
60  fprintf(f, "[%s:%s]\n", name.c_str(), ident.c_str());
61  } else {
62  fprintf(f, "[%s]\n", name.c_str());
63  }
64  std::map<std::string, metrics_entry>::iterator it;
65 
66  for(it = entries.begin(); it != entries.end(); ++it) {
67  metrics_entry ent = it->second;
68  switch(ent.valtype) {
69  case INTEGER:
70 
71  fprintf(f, "%s.%s=%ld\n", ident.c_str(), it->first.c_str(), (long int) (ent.value));
72  fprintf(f, "%s.%s.count=%lu\n", ident.c_str(), it->first.c_str(), ent.count);
73  fprintf(f, "%s.%s.min=%ld\n", ident.c_str(), it->first.c_str(), (long int) (ent.minvalue));
74  fprintf(f, "%s.%s.max=%ld\n", ident.c_str(), it->first.c_str(), (long int) (ent.maxvalue));
75  fprintf(f, "%s.%s.avg=%lf\n", ident.c_str(), it->first.c_str(), ent.cumvalue/ent.count);
76  break;
77  case REAL:
78  case TIME:
79  fprintf(f, "%s.%s=%lf\n", ident.c_str(), it->first.c_str(), (ent.value));
80  fprintf(f, "%s.%s.count=%lu\n", ident.c_str(), it->first.c_str(), ent.count);
81  fprintf(f, "%s.%s.min=%lf\n", ident.c_str(), it->first.c_str(), (ent.minvalue));
82  fprintf(f, "%s.%s.max=%lf\n", ident.c_str(), it->first.c_str(), (ent.maxvalue));
83  fprintf(f, "%s.%s.avg=%lf\n", ident.c_str(), it->first.c_str(), ent.cumvalue/ent.count);
84  break;
85  case STRING:
86  fprintf(f, "%s.%s=%s\n", ident.c_str(), it->first.c_str(), it->second.stringval.c_str());
87  break;
88  }
89  }
90 
91  fflush(f);
92  // Insert to database
93  std::string cmd = "python2.7 benchtodb.py " + filename;
94  system(cmd.c_str());
95  };
96 
97  };
98 
99 };
100 
101 
102 
103 #endif
104 
105