HEBench
hebench_report_impl.h
Go to the documentation of this file.
1 
2 // Copyright (C) 2021 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef _HEBench_TimingReport_H_0596d40a3cce4b108a81595c50eb286d
6 #define _HEBench_TimingReport_H_0596d40a3cce4b108a81595c50eb286d
7 
8 #include <cmath>
9 #include <iostream>
10 #include <memory>
11 #include <ratio>
12 #include <string>
13 #include <unordered_map>
14 #include <vector>
15 
16 #include "hebench_report.h"
17 
18 namespace hebench {
19 namespace ReportGen {
20 
22 {
23 public:
24  // section indicators for parsing generated CSV
25 
26  static constexpr const char *TagVersion = "#v,0,1,1";
27  static constexpr const char *TagReportHeader = "#0100"; // header at the start of the test
28  static constexpr const char *TagFailedTest = "#XXXX"; // indicates failed test (validation failed)
29  static constexpr const char *TagReportData = "#0200"; // start of the data
30  static constexpr const char *TagReportFooter = "#8E00"; // start of the footer
31  static constexpr const char *TagReportEnd = "#8FFF"; // end of the report
32 
34 
35  void newEventType(std::uint32_t set_id, const std::string &set_header, bool is_main_event = false);
36  const std::unordered_map<std::uint32_t, std::string> &getEventTypes() const { return m_event_headers; }
37  const std::vector<std::uint32_t> &getEventTypeIDs() const { return m_event_types; }
38 
39  std::uint32_t getMainEventID() const { return m_main_event; }
40 
41  void newEvent(std::shared_ptr<TimingReportEventC> p_event, const std::string &set_header = std::string());
42  const std::vector<std::shared_ptr<TimingReportEventC>> &getEvents() const { return m_events; }
43  void reserveCapacityForEvents(std::size_t new_capacity);
44  void clear();
45 
46  const std::string &getHeader() const { return m_header; }
47  void setHeader(const std::string &header) { m_header = header; }
48  void appendHeader(const std::string &header, bool new_line);
49  void prependHeader(const std::string &header, bool new_line);
50 
51  const std::string &getFooter() const { return m_footer; }
52  void setFooter(const std::string &footer) { m_footer = footer; }
53  void appendFooter(const std::string &footer, bool new_line);
54  void prependFooter(const std::string &footer, bool new_line);
55 
56  std::ostream &convert2CSV(std::ostream &os) const;
57 
58  static TimingReportImpl loadCSV(std::istream &is);
59  static TimingReportImpl loadCSV(const std::string &csv_content);
60 
61  static void setTimingPrefix(TimingPrefixedSeconds &prefix, double seconds, char ch_prefix);
62  static void computeTimingPrefix(TimingPrefixedSeconds &prefix, double seconds);
63 
64 private:
77  static std::string_view findNextValueCSV(std::size_t &out_start_idx,
78  std::size_t &out_count,
79  const char *s);
90  static void parseHeadingValue(std::string &s_out_heading, std::uint64_t &out_value,
91  const std::string &s_line);
102  static void parseHeadingValue(std::string &s_out_heading, double &out_value,
103  const std::string &s_line);
113  static std::istream &getTrimmedLine(std::istream &is, std::string &s_out,
114  const std::string &extra_trim = std::string());
126  static std::istream &getTrimmedLine(std::istream &is, std::string &s_out,
127  const std::string &extra_ltrim, const std::string &extra_rtrim);
136  static std::string readTextBlock(std::istream &is, std::string &s_block,
137  const std::vector<std::string> tags);
138  static void parseTimingEvent(std::string &s_out_event_header,
139  std::shared_ptr<TimingReportEventC> &p_out_event,
140  const std::string &s_line);
141 
142  std::string m_header;
143  std::string m_footer;
144  std::uint32_t m_main_event;
145  std::unordered_map<std::uint32_t, std::string> m_event_headers; // maps event id to event header
146  std::vector<std::uint32_t> m_event_types; // all keys to map m_event_headers
147  std::vector<std::shared_ptr<TimingReportEventC>> m_events;
148 };
149 
150 } // namespace ReportGen
151 } // namespace hebench
152 
153 #endif // defined _HEBench_TimingReport_H_0596d40a3cce4b108a81595c50eb286d
static constexpr const char * TagReportFooter
void appendHeader(const std::string &header, bool new_line)
void prependHeader(const std::string &header, bool new_line)
std::ostream & convert2CSV(std::ostream &os) const
static void setTimingPrefix(TimingPrefixedSeconds &prefix, double seconds, char ch_prefix)
void setHeader(const std::string &header)
void setFooter(const std::string &footer)
const std::vector< std::uint32_t > & getEventTypeIDs() const
const std::unordered_map< std::uint32_t, std::string > & getEventTypes() const
void prependFooter(const std::string &footer, bool new_line)
const std::vector< std::shared_ptr< TimingReportEventC > > & getEvents() const
void appendFooter(const std::string &footer, bool new_line)
static constexpr const char * TagVersion
const std::string & getHeader() const
void newEventType(std::uint32_t set_id, const std::string &set_header, bool is_main_event=false)
static constexpr const char * TagReportEnd
void reserveCapacityForEvents(std::size_t new_capacity)
static constexpr const char * TagReportData
static constexpr const char * TagFailedTest
static constexpr const char * TagReportHeader
static void computeTimingPrefix(TimingPrefixedSeconds &prefix, double seconds)
const std::string & getFooter() const
static TimingReportImpl loadCSV(std::istream &is)
void newEvent(std::shared_ptr< TimingReportEventC > p_event, const std::string &set_header=std::string())