00001 // Copyright 2009-2015 Sandia Corporation. Under the terms 00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. 00003 // Government retains certain rights in this software. 00004 // 00005 // Copyright (c) 2009-2015, Sandia Corporation 00006 // All rights reserved. 00007 // 00008 // This file is part of the SST software package. For license 00009 // information, see the LICENSE file in the top level directory of the 00010 // distribution. 00011 00012 #ifndef _H_SST_CORE_BASE_STATISTICS 00013 #define _H_SST_CORE_BASE_STATISTICS 00014 00015 #include <string> 00016 #include <cstdio> 00017 00018 namespace SST { 00019 namespace Statistics { 00020 00021 /** 00022 \class BaseStatistics 00023 00024 Forms the base class for statistics gathering within the SST core. Statistics are 00025 gathered by the core and processed into various (extensible) output forms. Statistics 00026 are expected to be named so that they can be located in the simulation output files. 00027 00028 */ 00029 class BaseStatistic { 00030 00031 public: 00032 /** 00033 Constructor for the BaseStatistics class. In this for the 00034 string provided is copied into a buffer within the class (which 00035 consumes memory, for statistics with many components callers may 00036 want to use the alternative constructor which provides a pointer 00037 that is not copied). Default is for the statistic to be created 00038 enabled for use 00039 00040 \param[statName] The name of the statistic being collected 00041 */ 00042 BaseStatistic(std::string statName) : enabled(true) { 00043 name = (char*) malloc(sizeof(char) * (statName.size() + 1)); 00044 sprintf(name, "%s", statName.c_str()); 00045 } 00046 00047 /** 00048 Constructor for the BaseStatistic class. This form of the 00049 constructor takes a pointer and does NOT perform a copy of the 00050 string (i.e. assumes that the pointer will remain live for the 00051 duration of the statistic's use). Default is for the statistic 00052 to be created enabled for use 00053 00054 \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. 00055 */ 00056 BaseStatistic(char* statName) : enabled(true) { name = statName; } 00057 00058 /** 00059 Get the name of the statistic 00060 \return The name of the statistic 00061 */ 00062 const char* getName() { 00063 return name; 00064 } 00065 00066 /** 00067 Enable the statistic for collection 00068 */ 00069 void enable() { 00070 enabled = true; 00071 } 00072 00073 /** 00074 Disable the statistic collection 00075 */ 00076 void disable() { 00077 enabled = false; 00078 } 00079 00080 /** 00081 Query whether the statistic is currently enabled 00082 \return true if the statistics collection is currently enabled, otherwise false 00083 */ 00084 bool isEnabled() { 00085 return enabled; 00086 } 00087 00088 protected: 00089 char* name; 00090 bool enabled; 00091 00092 }; 00093 00094 } 00095 } 00096 00097 #endif