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