geopm 3.1.1.dev410+g40bf96ed
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
CSV.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 - 2024 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef CSV_HPP_INCLUDE
7#define CSV_HPP_INCLUDE
8
9#include <vector>
10#include <functional>
11#include <map>
12#include <string>
13#include <fstream>
14#include <sstream>
15
16namespace geopm
17{
24 class CSV
25 {
26 public:
27 CSV() = default;
28 virtual ~CSV() = default;
34 virtual void add_column(const std::string &name) = 0;
51 virtual void add_column(const std::string &name,
52 const std::string &format) = 0;
61 virtual void add_column(const std::string &name,
62 std::function<std::string(double)> format) = 0;
66 virtual void activate(void) = 0;
71 virtual void update(const std::vector<double> &sample) = 0;
73 virtual void flush(void) = 0;
74 };
75
76 class CSVImp : public CSV
77 {
78 public:
79 CSVImp(const std::string &file_path,
80 const std::string &host_name,
81 const std::string &start_time,
82 size_t buffer_size);
83 CSVImp(const CSVImp &other) = delete;
84 CSVImp & operator=(const CSVImp &other) = delete;
85 virtual ~CSVImp();
86 void add_column(const std::string &name) override;
87 void add_column(const std::string &name,
88 const std::string &format) override;
89 void add_column(const std::string &name,
90 std::function<std::string(double)> format) override;
91 void activate(void) override;
92 void update(const std::vector<double> &sample) override;
93 void flush(void) override;
94 private:
95 void write_header(const std::string &host_name, const std::string &start_time);
96 void write_names(void);
97
98 const std::map<std::string, std::function<std::string(double)> > M_NAME_FORMAT_MAP;
99 const char M_SEPARATOR;
100 std::string m_file_path;
101 std::vector<std::string> m_column_name;
102 std::vector<std::function<std::string(double)> > m_column_format;
103 std::ofstream m_stream;
104 std::ostringstream m_buffer;
105 off_t m_buffer_limit;
106 bool m_is_active;
107 };
108}
109
110#endif
CSV class provides the GEOPM interface for creation of character separated value tabular data files....
Definition CSV.hpp:25
virtual void add_column(const std::string &name)=0
Add a column with the given field name. The formatting of the column values will default to geopm::st...
virtual void add_column(const std::string &name, std::function< std::string(double)> format)=0
Add a column with the given field name. The formatting of the column values is implemented with the f...
virtual ~CSV()=default
virtual void flush(void)=0
Flush all output to the CSV file.
CSV()=default
virtual void update(const std::vector< double > &sample)=0
Add a row to the CSV file.
virtual void activate(void)=0
Calling activate indicates that all columns have been added to the object and calls to update() are e...
virtual void add_column(const std::string &name, const std::string &format)=0
Add a column with the given field name. The formatting of the column values chosen based on the forma...
Definition CSV.hpp:77
CSVImp(const CSVImp &other)=delete
void add_column(const std::string &name) override
Add a column with the given field name. The formatting of the column values will default to geopm::st...
Definition CSV.cpp:47
void activate(void) override
Calling activate indicates that all columns have been added to the object and calls to update() are e...
Definition CSV.cpp:117
void flush(void) override
Flush all output to the CSV file.
Definition CSV.cpp:101
void update(const std::vector< double > &sample) override
Add a row to the CSV file.
Definition CSV.cpp:77
CSVImp & operator=(const CSVImp &other)=delete
virtual ~CSVImp()
Definition CSV.cpp:42
Definition Accumulator.cpp:12