GraphChi 0.1

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
36 #include "metrics/metrics.hpp"
37
38
39
40
41 namespace graphchi {
42
43 class file_reporter : public imetrics_reporter {
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(), "w");
55 assert(f != NULL);
56 }
57
58 virtual ~file_reporter() {}
59
60 virtual void do_report(std::string name, std::string ident, std::map<std::string, metrics_entry> & entries) {
61 if (ident != name) {
62 fprintf(f, "[%s:%s]\n", name.c_str(), ident.c_str());
63 } else {
64 fprintf(f, "[%s]\n", name.c_str());
65 }
66 std::map<std::string, metrics_entry>::iterator it;
67
68 for(it = entries.begin(); it != entries.end(); ++it) {
69 metrics_entry ent = it->second;
70 switch(ent.valtype) {
71 case INTEGER:
72
73 fprintf(f, "%s.%s=%ld\n", ident.c_str(), it->first.c_str(), (long int) (ent.value));
74 fprintf(f, "%s.%s.count=%lu\n", ident.c_str(), it->first.c_str(), ent.count);
75 fprintf(f, "%s.%s.min=%ld\n", ident.c_str(), it->first.c_str(), (long int) (ent.minvalue));
76 fprintf(f, "%s.%s.max=%ld\n", ident.c_str(), it->first.c_str(), (long int) (ent.maxvalue));
77 fprintf(f, "%s.%s.avg=%lf\n", ident.c_str(), it->first.c_str(), ent.cumvalue/ent.count);
78 break;
79 case REAL:
80 case TIME:
81 fprintf(f, "%s.%s=%lf\n", ident.c_str(), it->first.c_str(), (ent.value));
82 fprintf(f, "%s.%s.count=%lu\n", ident.c_str(), it->first.c_str(), ent.count);
83 fprintf(f, "%s.%s.min=%lf\n", ident.c_str(), it->first.c_str(), (ent.minvalue));
84 fprintf(f, "%s.%s.max=%lf\n", ident.c_str(), it->first.c_str(), (ent.maxvalue));
85 fprintf(f, "%s.%s.avg=%lf\n", ident.c_str(), it->first.c_str(), ent.cumvalue/ent.count);
86 break;
87 case STRING:
88 fprintf(f, "%s.%s=%s\n", ident.c_str(), it->first.c_str(), it->second.stringval.c_str());
89 break;
90 case VECTOR:
91 break;
92 }
93 }
94
95 fflush(f);
96 fclose(f);
97 };
98
99 };
100
101 };
102
103
104
105 #endif
106
107