SST  6.1.0
StructuralSimulationToolkit
basestats.h
1 // Copyright 2009-2016 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2016, Sandia Corporation
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef _H_SST_CORE_BASE_STATISTICS
13 #define _H_SST_CORE_BASE_STATISTICS
14 
15 #include <string>
16 #include <cstdio>
17 
18 namespace SST {
19 namespace Statistics {
20 
21 /**
22  \class BaseStatistics
23 
24  Forms the base class for statistics gathering within the SST core. Statistics are
25  gathered by the core and processed into various (extensible) output forms. Statistics
26  are expected to be named so that they can be located in the simulation output files.
27 
28 */
30 
31  public:
32  /**
33  Constructor for the BaseStatistics class. In this for the
34  string provided is copied into a buffer within the class (which
35  consumes memory, for statistics with many components callers may
36  want to use the alternative constructor which provides a pointer
37  that is not copied). Default is for the statistic to be created
38  enabled for use
39 
40  \param[statName] The name of the statistic being collected
41  */
42  BaseStatistic(std::string statName) : enabled(true) {
43  name = (char*) malloc(sizeof(char) * (statName.size() + 1));
44  sprintf(name, "%s", statName.c_str());
45  }
46 
47  /**
48  Constructor for the BaseStatistic class. This form of the
49  constructor takes a pointer and does NOT perform a copy of the
50  string (i.e. assumes that the pointer will remain live for the
51  duration of the statistic's use). Default is for the statistic
52  to be created enabled for use
53 
54  \param[statName] A pointer to a name of the statistic being collected, this pointer must remain live for the duration of the statistic's use but can be modifed since it is read on use.
55  */
56  BaseStatistic(char* statName) : enabled(true) { name = statName; }
57 
58  /**
59  Get the name of the statistic
60  \return The name of the statistic
61  */
62  const char* getName() {
63  return name;
64  }
65 
66  /**
67  Enable the statistic for collection
68  */
69  void enable() {
70  enabled = true;
71  }
72 
73  /**
74  Disable the statistic collection
75  */
76  void disable() {
77  enabled = false;
78  }
79 
80  /**
81  Query whether the statistic is currently enabled
82  \return true if the statistics collection is currently enabled, otherwise false
83  */
84  bool isEnabled() {
85  return enabled;
86  }
87 
88  protected:
89  char* name;
90  bool enabled;
91 
92 };
93 
94 }
95 }
96 
97 #endif
bool isEnabled()
Query whether the statistic is currently enabled.
Definition: basestats.h:84
BaseStatistic(char *statName)
Constructor for the BaseStatistic class.
Definition: basestats.h:56
void disable()
Disable the statistic collection.
Definition: basestats.h:76
Definition: action.cc:17
Definition: basestats.h:29
void enable()
Enable the statistic for collection.
Definition: basestats.h:69
BaseStatistic(std::string statName)
Constructor for the BaseStatistics class.
Definition: basestats.h:42
const char * getName()
Get the name of the statistic.
Definition: basestats.h:62