SST  15.1.0
StructuralSimulationToolkit
statoutputjson.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
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 SST_CORE_STATAPI_STATOUTPUTJSON_H
13 #define SST_CORE_STATAPI_STATOUTPUTJSON_H
14 
15 #include "sst/core/sst_types.h"
16 #include "sst/core/statapi/statoutput.h"
17 
18 #include <cstdio>
19 #include <string>
20 
21 namespace SST::Statistics {
22 
23 /**
24  \class StatisticOutputJSON
25 
26  The class for statistics output to a JSON formatted file
27 */
29 {
30 public:
31  SST_ELI_REGISTER_DERIVED(
34  "sst",
35  "statoutputjson",
36  SST_ELI_ELEMENT_VERSION(1,0,0),
37  "Output to a JSON file")
38 
39  SST_ELI_DOCUMENT_PARAMS(
40  { "filepath", "Filepath for the output file", "./StatisticOutput.json"},
41  { "outputsimtime", "Whether to print the simulation time in the output", "True" },
42  { "outputrank", "Whether to print the rank in the output", "True" }
43  )
44 
45  /** Construct a StatOutputJSON
46  * @param outputParameters - Parameters used for this Statistic Output
47  */
48  explicit StatisticOutputJSON(Params& outputParameters);
49 
50  void serialize_order(SST::Core::Serialization::serializer& ser) override;
51  ImplementSerializable(SST::Statistics::StatisticOutputJSON)
52 
53 protected:
54  /** Perform a check of provided parameters
55  * @return True if all required parameters and options are acceptable
56  */
57  bool checkOutputParameters() override;
58 
59  /** Indicate to Statistic Output that simulation started.
60  * Statistic output may perform any startup code here as necessary.
61  */
62  void startOfSimulation() override;
63 
64  /** Indicate to Statistic Output that simulation ended.
65  * Statistic output may perform any shutdown code here as necessary.
66  */
67  void endOfSimulation() override;
68 
69  /** Implementation function for the start of output.
70  * This will be called by the Statistic Processing Engine to indicate that
71  * a Statistic is about to send data to the Statistic Output for processing.
72  * @param statistic - Pointer to the statistic object than the output can
73  * retrieve data from.
74  */
75  void implStartOutputEntries(StatisticBase* statistic) override;
76 
77  /** Implementation function for the end of output.
78  * This will be called by the Statistic Processing Engine to indicate that
79  * a Statistic is finished sending data to the Statistic Output for processing.
80  * The Statistic Output can perform any output related functions here.
81  */
82  void implStopOutputEntries() override;
83 
84  /** Implementation functions for output.
85  * These will be called by the statistic to provide Statistic defined
86  * data to be output.
87  * @param fieldHandle - The handle to the registered statistic field.
88  * @param data - The data related to the registered field to be output.
89  */
90  void outputField(fieldHandle_t fieldHandle, int32_t data) override;
91  void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
92  void outputField(fieldHandle_t fieldHandle, int64_t data) override;
93  void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
94  void outputField(fieldHandle_t fieldHandle, float data) override;
95  void outputField(fieldHandle_t fieldHandle, double data) override;
96 
97  void printIndent();
98 
99 protected:
101  m_currentComponentName(""),
102  m_firstEntry(false),
103  m_processedAnyStats(false),
104  m_curIndentLevel(0)
105  {
106  ;
107  } // For serialization
108 
109 private:
110  bool openFile();
111  void closeFile();
112 
113 private:
114  FILE* m_hFile;
115  std::string m_FilePath;
116  std::string m_currentComponentName;
117  std::string m_currentStatisticName;
118  std::string m_currentStatisticSubId;
119  std::string m_currentStatisticType;
120  bool m_outputSimTime;
121  bool m_outputRank;
122  bool m_firstEntry;
123  bool m_firstField;
124  bool m_processedAnyStats;
125  int m_curIndentLevel;
126 };
127 
128 } // namespace SST::Statistics
129 
130 #endif // SST_CORE_STATAPI_STATOUTPUTJSON_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
The class for statistics output to a JSON formatted file.
Definition: statoutputjson.h:28
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:52
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition: statoutputjson.cc:99
Forms the base class for statistics gathering within SST.
Definition: statbase.h:49
virtual bool checkOutputParameters()=0
Have the Statistic Output check its parameters.
void implStopOutputEntries() override
Implementation function for the end of output.
Definition: statoutputjson.cc:151
Definition: statoutput.h:170
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
ImplementSerializable(SST::Statistics::StatisticOutputJSON) protected void startOfSimulation() override
Perform a check of provided parameters.
Definition: statoutputjson.cc:56
Parameter store.
Definition: params.h:63
Definition: elementinfo.h:44
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition: statoutputjson.cc:77