SST 15.0
Structural Simulation Toolkit
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
21namespace SST::Statistics {
22
23/**
24 \class StatisticOutputJSON
25
26 The class for statistics output to a JSON formatted file
27*/
28class StatisticOutputJSON : public StatisticFieldsOutput
29{
30public:
33 StatisticOutputJSON,
34 "sst",
35 "statoutputjson",
36 SST_ELI_ELEMENT_VERSION(1,0,0),
37 "Output to a JSON file")
38
39 /** Construct a StatOutputJSON
40 * @param outputParameters - Parameters used for this Statistic Output
41 */
42 explicit StatisticOutputJSON(Params& outputParameters);
43
44 void serialize_order(SST::Core::Serialization::serializer& ser) override;
45 ImplementSerializable(SST::Statistics::StatisticOutputJSON)
46
47protected:
48 /** Perform a check of provided parameters
49 * @return True if all required parameters and options are acceptable
50 */
51 bool checkOutputParameters() override;
52
53 /** Print out usage for this Statistic Output */
54 void printUsage() override;
55
56 /** Indicate to Statistic Output that simulation started.
57 * Statistic output may perform any startup code here as necessary.
58 */
59 void startOfSimulation() override;
60
61 /** Indicate to Statistic Output that simulation ended.
62 * Statistic output may perform any shutdown code here as necessary.
63 */
64 void endOfSimulation() override;
65
66 /** Implementation function for the start of output.
67 * This will be called by the Statistic Processing Engine to indicate that
68 * a Statistic is about to send data to the Statistic Output for processing.
69 * @param statistic - Pointer to the statistic object than the output can
70 * retrieve data from.
71 */
72 void implStartOutputEntries(StatisticBase* statistic) override;
73
74 /** Implementation function for the end of output.
75 * This will be called by the Statistic Processing Engine to indicate that
76 * a Statistic is finished sending data to the Statistic Output for processing.
77 * The Statistic Output can perform any output related functions here.
78 */
79 void implStopOutputEntries() override;
80
81 /** Implementation functions for output.
82 * These will be called by the statistic to provide Statistic defined
83 * data to be output.
84 * @param fieldHandle - The handle to the registered statistic field.
85 * @param data - The data related to the registered field to be output.
86 */
87 void outputField(fieldHandle_t fieldHandle, int32_t data) override;
88 void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
89 void outputField(fieldHandle_t fieldHandle, int64_t data) override;
90 void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
91 void outputField(fieldHandle_t fieldHandle, float data) override;
92 void outputField(fieldHandle_t fieldHandle, double data) override;
93
94 void printIndent();
95
96protected:
97 StatisticOutputJSON() :
98 m_currentComponentName(""),
99 m_firstEntry(false),
100 m_processedAnyStats(false),
101 m_curIndentLevel(0)
102 {
103 ;
104 } // For serialization
105
106private:
107 bool openFile();
108 void closeFile();
109
110private:
111 FILE* m_hFile;
112 std::string m_FilePath;
113 std::string m_currentComponentName;
114 std::string m_currentStatisticName;
115 std::string m_currentStatisticSubId;
116 std::string m_currentStatisticType;
117 bool m_outputSimTime;
118 bool m_outputRank;
119 bool m_firstEntry;
120 bool m_firstField;
121 bool m_processedAnyStats;
122 int m_curIndentLevel;
123};
124
125} // namespace SST::Statistics
126
127#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:45
Parameter store.
Definition params.h:58
Forms the base class for statistics gathering within SST.
Definition statbase.h:49
ImplementVirtualSerializable(SST::Statistics::StatisticFieldsOutput) protected StatisticFieldsOutput()
Construct a base StatisticOutput.
Definition statoutput.h:292
void startOfSimulation() override
Indicate to Statistic Output that simulation started.
Definition statoutputjson.cc:79
ImplementSerializable(SST::Statistics::StatisticOutputJSON) protected void printUsage() override
Perform a check of provided parameters.
Definition statoutputjson.cc:66
SST_ELI_REGISTER_DERIVED(StatisticOutput, StatisticOutputJSON, "sst", "statoutputjson", SST_ELI_ELEMENT_VERSION(1, 0, 0), "Output to a JSON file") explicit StatisticOutputJSON(Params &outputParameters)
Construct a StatOutputJSON.
void implStopOutputEntries() override
Implementation function for the end of output.
Definition statoutputjson.cc:174
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition statoutputjson.cc:100
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition statoutputjson.cc:122
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:52
virtual bool checkOutputParameters()=0
Have the Statistic Output check its parameters.