SST 16.0.0
Structural Simulation Toolkit
statoutputtxt.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_STATOUTPUTTXT_H
13#define SST_CORE_STATAPI_STATOUTPUTTXT_H
14
15#include "sst/core/sst_types.h"
16#include "sst/core/statapi/statoutput.h"
17
18#ifdef HAVE_LIBZ
19#include <zlib.h>
20#endif
21
22#include <cstdint>
23#include <cstdio>
24#include <string>
25
26namespace SST::Statistics {
27
29{
30public:
31 /** Construct a StatOutputTxt
32 * @param outputParameters - Parameters used for this Statistic Output
33 */
34 explicit StatisticOutputTextBase(Params& outputParameters);
35
36 /** This output supports adding statistics during runtime if the header is embedded in the output */
37 virtual bool supportsDynamicRegistration() const override { return m_outputInlineHeader; }
38
39 void serialize_order(SST::Core::Serialization::serializer& ser) override;
40
41 ImplementVirtualSerializable(SST::Statistics::StatisticOutputTextBase);
42
43protected:
44
45 /** Perform a check of provided parameters
46 * @return True if all required parameters and options are acceptable
47 */
48 bool checkOutputParameters() override;
49
50 /** Indicate to Statistic Output that simulation started.
51 * Statistic output may perform any startup code here as necessary.
52 */
53 void startOfSimulation() override;
54
55 /** Indicate to Statistic Output that simulation ended.
56 * Statistic output may perform any shutdown code here as necessary.
57 */
58 void endOfSimulation() override;
59
60 /** Implementation function for the start of output.
61 * This will be called by the Statistic Processing Engine to indicate that
62 * a Statistic is about to send data to the Statistic Output for processing.
63 * @param statistic - Pointer to the statistic object than the output can
64 * retrieve data from.
65 */
66 void implStartOutputEntries(StatisticBase* statistic) override;
67
68 /** Implementation function for the end of output.
69 * This will be called by the Statistic Processing Engine to indicate that
70 * a Statistic is finished sending data to the Statistic Output for processing.
71 * The Statistic Output can perform any output related functions here.
72 */
73 void implStopOutputEntries() override;
74
75 /** Implementation functions for output.
76 * These will be called by the statistic to provide Statistic defined
77 * data to be output.
78 * @param fieldHandle - The handle to the registered statistic field.
79 * @param data - The data related to the registered field to be output.
80 */
81 void outputField(fieldHandle_t fieldHandle, int32_t data) override;
82 void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
83 void outputField(fieldHandle_t fieldHandle, int64_t data) override;
84 void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
85 void outputField(fieldHandle_t fieldHandle, float data) override;
86 void outputField(fieldHandle_t fieldHandle, double data) override;
87
88protected:
90
91 bool m_outputTopHeader;
92 bool m_outputInlineHeader;
93 bool m_outputSimTime;
94 bool m_outputRank;
95 bool m_useCompression;
96
97private:
98 bool openFile();
99 void closeFile();
100 int print(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
101
102private:
103#ifdef HAVE_LIBZ
104 gzFile m_gzFile;
105#endif
106 FILE* m_hFile;
107 std::string m_outputBuffer;
108 std::string m_FilePath;
109
110 /**
111 Returns whether or not this outputter outputs to a file
112 */
113 virtual bool outputsToFile() = 0;
114
115 /**
116 Returns whether or not this outputter supports compression.
117 Only checked if the class also writes to a file
118 */
119 virtual bool supportsCompression() = 0;
120
121 /**
122 Returns a prefix that will start each new output entry
123 */
124 virtual std::string getStartOutputPrefix() = 0;
125
126 /**
127 These functions return the default value for the associated
128 flags. These are implemented by the child class so that each
129 final class can control how the defaults work.
130 */
131 virtual bool getOutputTopHeaderDefault() = 0;
132 virtual bool getOutputInlineHeaderDefault() = 0;
133 virtual bool getOutputSimTimeDefault() = 0;
134 virtual bool getOutputRankDefault() = 0;
135
136 virtual std::string getDefaultFileName() { return ""; }
137
138 /** True if this StatOutput can handle StatisticGroups */
139 virtual bool acceptsGroups() const override { return true; }
140};
141
142
143/**
144 \class StatisticOutputTxt
145
146 The class for statistics output to a text file.
147*/
149{
150public:
151 SST_ELI_REGISTER_DERIVED(
154 "sst",
155 "statoutputtxt",
156 SST_ELI_ELEMENT_VERSION(1,0,0),
157 "Output to text file"
158 )
159
160 SST_ELI_DOCUMENT_PARAMS(
161 { "outputtopheader", "Whether to print a header at the top of the output", "False" },
162 { "outputinlineheader", "Whether to print a field names inline with statistic output", "True" },
163 { "outputsimtime", "Whether to print the simulation time in the output", "True" },
164 { "outputrank", "Whether to print the rank in the output", "True" },
165 { "filepath", "Filepath for the output file", "./StatisticOutput.txt" },
166 { "compressed", "Whether to compress the output file", "False" }
167 )
168
169 /** Construct a StatOutputTxt
170 * @param outputParameters - Parameters used for this Statistic Output
171 */
172 explicit StatisticOutputTxt(Params& outputParameters);
173
174 void serialize_order(SST::Core::Serialization::serializer& ser) override;
175 ImplementSerializable(SST::Statistics::StatisticOutputTxt)
176
177
178protected:
179 StatisticOutputTxt() { ; } // For serialization
180
181private:
182 /**
183 Returns whether or not this outputter outputs to a file
184 */
185 bool outputsToFile() override { return true; }
186
187 /**
188 Returns whether or not this outputter supports compression.
189 Only checked if the class also writes to a file
190 */
191 bool supportsCompression() override
192 {
193#ifdef HAVE_LIBZ
194 return true;
195#else
196 return false;
197#endif
198 }
199 /**
200 Returns a prefix that will start each new output entry
201 */
202 std::string getStartOutputPrefix() override { return ""; }
203
204 /**
205 These functions return the default value for the associated
206 flags. These are implemented by the child class so that each
207 final class can control how the defaults work.
208 */
209 bool getOutputTopHeaderDefault() override { return false; }
210 bool getOutputInlineHeaderDefault() override { return true; }
211 bool getOutputSimTimeDefault() override { return true; }
212 bool getOutputRankDefault() override { return true; }
213
214 std::string getDefaultFileName() override { return "StatisticOutput.txt"; }
215};
216
217/**
218 \class StatisticOutputConsole
219
220 The class for statistics output to the console.
221*/
223{
224public:
225 SST_ELI_REGISTER_DERIVED(
228 "sst",
229 "statoutputconsole",
230 SST_ELI_ELEMENT_VERSION(1,0,0),
231 "Output to console"
232 )
233
234 SST_ELI_DOCUMENT_PARAMS(
235 { "outputtopheader", "Whether to print a header at the top of the output", "False" },
236 { "outputinlineheader", "Whether to print a field names inline with statistic output", "True" },
237 { "outputsimtime", "Whether to print the simulation time in the output", "False" },
238 { "outputrank", "Whether to print the rank in the output", "False" },
239 )
240
241 /** Construct a StatOutputTxt
242 * @param outputParameters - Parameters used for this Statistic Output
243 */
244 explicit StatisticOutputConsole(Params& outputParameters);
245
246 void serialize_order(SST::Core::Serialization::serializer& ser) override;
247 ImplementSerializable(SST::Statistics::StatisticOutputConsole)
248
249protected:
250 StatisticOutputConsole() { ; } // For serialization
251
252private:
253 /**
254 Returns whether or not this outputter outputs to a file
255 */
256 bool outputsToFile() override { return false; }
257
258 /**
259 Returns whether or not this outputter supports compression.
260 Only checked if the class also writes to a file
261 */
262 bool supportsCompression() override { return false; }
263
264 /**
265 Returns a prefix that will start each new output entry
266 */
267 std::string getStartOutputPrefix() override { return " "; }
268
269 /**
270 These functions return the default value for the associated
271 flags. These are implemented by the child class so that each
272 final class can control how the defaults work.
273 */
274 bool getOutputTopHeaderDefault() override { return false; }
275 bool getOutputInlineHeaderDefault() override { return true; }
276 bool getOutputSimTimeDefault() override { return false; }
277 bool getOutputRankDefault() override { return false; }
278};
279
280} // namespace SST::Statistics
281
282#endif // SST_CORE_STATAPI_STATOUTPUTTXT_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 the console.
Definition statoutputtxt.h:223
StatisticOutputConsole(Params &outputParameters)
Construct a StatOutputTxt.
Definition statoutputtxt.cc:430
Definition statoutputtxt.h:29
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition statoutputtxt.cc:105
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition statoutputtxt.cc:161
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition statoutputtxt.cc:113
StatisticOutputTextBase(Params &outputParameters)
Construct a StatOutputTxt.
Definition statoutputtxt.cc:26
void startOfSimulation() override
Indicate to Statistic Output that simulation started.
Definition statoutputtxt.cc:60
virtual bool supportsDynamicRegistration() const override
This output supports adding statistics during runtime if the header is embedded in the output.
Definition statoutputtxt.h:37
void implStopOutputEntries() override
Implementation function for the end of output.
Definition statoutputtxt.cc:153
bool checkOutputParameters() override
Perform a check of provided parameters.
Definition statoutputtxt.cc:31
The class for statistics output to a text file.
Definition statoutputtxt.h:149
Forms the base class for statistics output generation within the SST core.
Definition statoutput.h:54
virtual bool acceptsGroups() const
True if this StatOutput can handle StatisticGroups.
Definition statoutput.h:75