SST/macro
stat_collector.h
Go to the documentation of this file.
1 /*
2  * This file is part of SST/macroscale:
3  * The macroscale architecture simulator from the SST suite.
4  * Copyright (c) 2009 Sandia Corporation.
5  * This software is distributed under the BSD License.
6  * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7  * the U.S. Government retains certain rights in this software.
8  * For more information, see the LICENSE file in the top
9  * SST/macroscale directory.
10  */
11 
12 #ifndef SSTMAC_COMMON_STATS_STAT_LOGGER_H_INCLUDED
13 #define SSTMAC_COMMON_STATS_STAT_LOGGER_H_INCLUDED
14 
15 #include <iostream>
16 #include <fstream>
20 
21 namespace sstmac {
22 
23 
24 /**
25  * A type of logger that collects some kind of statistic
26  * and outputs to a file during or at the end of a simulation.
27  * Usually, a static instance of this class should be used,
28  * because no merging of stat objects takes place, which means
29  * you'll get one file for each stat object.
30  */
31 class stat_collector : virtual public sprockit::factory_type
32 {
33 
34  public:
35  virtual
37 
38  /** This is to notify that the statistics collector is done.
39  * Do any necessary data post-processing, but do NOT dump to file */
40  virtual void
42 
43  /** After post-processing, this notifies the collector to dump data to a file
44  * @param name The root of the filename to dump to */
45  virtual void
46  dump_local_data() = 0;
47 
48  /** After post-processing, this notifies the collector to dump data to a file
49  * @param name The root of the filename to dump to */
50  virtual void
51  dump_global_data() = 0;
52 
53  virtual void
55 
56  virtual void
57  reduce(stat_collector* coll) = 0;
58 
59  virtual void
60  clear() = 0;
61 
62  virtual stat_collector*
63  clone() const = 0;
64 
65  virtual std::string
66  to_string() const {
67  return "stat_collector";
68  }
69 
70  virtual void
71  init_factory_params(sprockit::sim_parameters *params);
72 
73  bool
74  registered() const {
75  return registered_;
76  }
77 
78  virtual void
79  set_id(int id){
80  id_ = id;
81  }
82 
83  int
84  id() const {
85  return id_;
86  }
87 
88  void
89  set_registered(bool reg) {
90  registered_ = reg;
91  }
92 
93  void
94  add_suffix(const std::string& suffix);
95 
96  std::string
97  fileroot() const {
98  return fileroot_;
99  }
100 
101  static stat_collector*
102  optional_build(sprockit::sim_parameters* params,
103  const std::string& ns,
104  const std::string& deflt,
105  const char* suffix);
106 
107 
108  protected:
110  registered_(false),
111  id_(-1)
112  {
113  }
114 
115  void
116  clone_into(stat_collector* cln) const ;
117 
118  /**
119  * Check to see if the file is open. If not, try and open it and set
120  * the current output stream to it, and throw an sprockit::spkt_error if something goes
121  * wrong.
122  * @return
123  */
124  static bool
125  check_open(std::fstream& myfile, const std::string& fname, std::ios::openmode flags = std::ios::out);
126 
127  protected:
129  int id_;
130  std::string fileroot_;
131 
132  private:
133 
134 };
135 
136 template <class T>
137 T*
138 optional_stats(sprockit::sim_parameters* params,
139  const std::string& ns,
140  const std::string& deflt,
141  const char* suffix = 0){
142  stat_collector* coll = stat_collector::optional_build(params,ns,deflt,suffix);
143  if (coll){
144  T* t = dynamic_cast<T*>(coll);
145  if (!t){
147  "failed casting stats objects");
148  }
149  return t;
150  }
151  else return nullptr;
152 }
153 
155 
156 
157 } // end of namespace sstmac
158 #endif
159 
virtual void simulation_finished(timestamp end)=0
This is to notify that the statistics collector is done.
void set_registered(bool reg)
void clone_into(stat_collector *cln) const
static bool check_open(std::fstream &myfile, const std::string &fname, std::ios::openmode flags=std::ios::out)
Check to see if the file is open.
virtual void dump_global_data()=0
After post-processing, this notifies the collector to dump data to a file.
A type of logger that collects some kind of statistic and outputs to a file during or at the end of a...
virtual void set_id(int id)
virtual void clear()=0
A basic container for time (subject to future transplant).
Definition: timestamp.h:29
bool registered() const
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
void add_suffix(const std::string &suffix)
virtual void reduce(stat_collector *coll)=0
virtual void global_reduce(parallel_runtime *rt)=0
virtual stat_collector * clone() const =0
std::string fileroot() const
static stat_collector * optional_build(sprockit::sim_parameters *params, const std::string &ns, const std::string &deflt, const char *suffix)
#define spkt_throw(exc,...)
Definition: errors.h:44
T * optional_stats(sprockit::sim_parameters *params, const std::string &ns, const std::string &deflt, const char *suffix=0)
virtual std::string to_string() const
virtual void init_factory_params(sprockit::sim_parameters *params)
virtual void dump_local_data()=0
After post-processing, this notifies the collector to dump data to a file.
DeclareFactory(parallel_runtime)
Error indicating some internal value was unexpected.
Definition: errors.h:83