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