SST 16.0.0
Structural Simulation Toolkit
statoutputcsv.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_STATOUTPUTCSV_H
13#define SST_CORE_STATAPI_STATOUTPUTCSV_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#include <vector>
26
27namespace SST::Statistics {
28
29/**
30 \class StatisticOutputCSV
31
32 The class for statistics output to a comma separated file.
33*/
34class StatisticOutputCSV : public StatisticFieldsOutput
35{
36public:
37 SST_ELI_REGISTER_DERIVED(
39 StatisticOutputCSV,
40 "sst",
41 "statoutputcsv",
42 SST_ELI_ELEMENT_VERSION(1,0,0),
43 "Output directly to console screen"
44 )
45
46 SST_ELI_DOCUMENT_PARAMS(
47 { "separator", "Field separator", ", "},
48 { "filepath", "Filepath for the output file", "./StatisticOutput.csv"},
49 { "outputtopheader", "Whether to print a header at the top of the CSV output", "True" },
50 { "outputsimtime", "Whether to print the simulation time in the output", "True" },
51 { "outputrank", "Whether to print the rank in the output", "True" }
52 )
53
54 /** Construct a StatOutputCSV
55 * @param outputParameters - Parameters used for this Statistic Output
56 */
57 explicit StatisticOutputCSV(Params& outputParameters);
58
59 void serialize_order(SST::Core::Serialization::serializer& ser) override;
60 ImplementSerializable(SST::Statistics::StatisticOutputCSV)
61
62protected:
63 /** Perform a check of provided parameters
64 * @return True if all required parameters and options are acceptable
65 */
66 bool checkOutputParameters() override;
67
68 /** Indicate to Statistic Output that simulation started.
69 * Statistic output may perform any startup code here as necessary.
70 */
71 void startOfSimulation() override;
72
73 /** Indicate to Statistic Output that simulation ended.
74 * Statistic output may perform any shutdown code here as necessary.
75 */
76 void endOfSimulation() override;
77
78 /** Implementation function for the start of output.
79 * This will be called by the Statistic Processing Engine to indicate that
80 * a Statistic is about to send data to the Statistic Output for processing.
81 * @param statistic - Pointer to the statistic object than the output can
82 * retrieve data from.
83 */
84 void implStartOutputEntries(StatisticBase* statistic) override;
85
86 /** Implementation function for the end of output.
87 * This will be called by the Statistic Processing Engine to indicate that
88 * a Statistic is finished sending data to the Statistic Output for processing.
89 * The Statistic Output can perform any output related functions here.
90 */
91 void implStopOutputEntries() override;
92
93 /** Implementation functions for output.
94 * These will be called by the statistic to provide Statistic defined
95 * data to be output.
96 * @param fieldHandle - The handle to the registered statistic field.
97 * @param data - The data related to the registered field to be output.
98 */
99 void outputField(fieldHandle_t fieldHandle, int32_t data) override;
100 void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
101 void outputField(fieldHandle_t fieldHandle, int64_t data) override;
102 void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
103 void outputField(fieldHandle_t fieldHandle, float data) override;
104 void outputField(fieldHandle_t fieldHandle, double data) override;
105
106 /** True if this StatOutput can handle StatisticGroups */
107 virtual bool acceptsGroups() const override { return true; }
108
109protected:
110 StatisticOutputCSV() { ; } // For serialization
111
112private:
113 bool openFile();
114 void closeFile();
115 int print(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
116
117private:
118#ifdef HAVE_LIBZ
119 gzFile m_gzFile;
120#endif
121 FILE* m_hFile;
122 std::vector<std::string> m_OutputBufferArray;
123 std::string m_Separator;
124 std::string m_FilePath;
125 std::string m_currentComponentName;
126 std::string m_currentStatisticName;
127 std::string m_currentStatisticSubId;
128 std::string m_currentStatisticType;
129 bool m_outputTopHeader;
130 bool m_outputSimTime;
131 bool m_outputRank;
132 bool m_useCompression;
133};
134
135} // namespace SST::Statistics
136
137#endif // SST_CORE_STATAPI_STATOUTPUTCSV_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 comma separated file.
Definition statoutputcsv.h:35
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition statoutputcsv.cc:137
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition statoutputcsv.cc:193
virtual bool acceptsGroups() const override
True if this StatOutput can handle StatisticGroups.
Definition statoutputcsv.h:107
ImplementSerializable(SST::Statistics::StatisticOutputCSV) protected void startOfSimulation() override
Perform a check of provided parameters.
Definition statoutputcsv.cc:61
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition statoutputcsv.cc:130
void implStopOutputEntries() override
Implementation function for the end of output.
Definition statoutputcsv.cc:153
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.