HPCToolkit
TextUtil.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #ifndef Analysis_TextUtil_hpp
61 #define Analysis_TextUtil_hpp
62 
63 //************************* System Include Files ****************************
64 
65 #include <iostream>
66 #include <iomanip>
67 
68 #include <string>
69 #include <vector>
70 
71 //*************************** User Include Files ****************************
72 
73 #include <include/uint.h>
74 
75 #include <lib/prof/Metric-Mgr.hpp>
76 
77 //*************************** Forward Declarations ***************************
78 
79 //****************************************************************************
80 
81 namespace Analysis {
82 
83 namespace TextUtil {
84 
85 
86 //****************************************************************************
87 //
88 //****************************************************************************
89 
91 public:
92  // NOTE: Since computed metrics may be of any unit, forcing is only
93  // allowed for raw metrics.
94  enum Flag {
95  Flag_NULL = 0,
96  Flag_ForcePct, // force percent column formatting
97  Flag_ForceVal // force value column formatting
98  };
99 
100 public:
101  ColumnFormatter(const Prof::Metric::Mgr& metricMgr,
102  std::ostream& os,
103  int numDecPct, int numDecVal);
104 
106  { }
107 
108  // generates a summary of the formatted column for all metrics
109  void
111 
112  // generates a formatted column for metric id 'mid' (if displayed).
113  // The flag can force the column to be displayed as a value
114  // (non-percentage) even if it was formatted as a percent and vice versa
115  void
116  genCol(uint mid, double metricVal, double metricTot, Flag flg = Flag_NULL);
117 
118  void
119  genCol(uint mid, double metricVal, Flag flg = Flag_ForceVal)
120  {
121  genCol(mid, metricVal, 0, flg);
122  }
123 
124 
125  // generate a blank column for metric 'mid'
126  void
127  genBlankCol(uint mid);
128 
129  // generates 'formatted blanks' for all 'displayed' metrics
130  void
132  {
133  m_os << std::setw(m_annotWidthTot) << std::setfill(' ') << " ";
134  }
135 
136 private:
137  bool
139  {
140  // m_mMgr.metric(mId)->Display()
141  return (m_annotWidth[mId] != 0);
142  }
143 
144 
145 private:
147  std::ostream& m_os;
148 
149  // number of decimals in non-scientific format
150  int m_numDecPct; // for percents
151  int m_numDecVal; // for values
152 
153  std::vector<int> m_annotWidth;
155 
156  std::vector<double> m_sciFmtLoThrsh_pct; // x < thrsh => scientific format
157  std::vector<double> m_sciFmtHiThrsh_pct; // x >= thrsh => scientific format
158 
159  std::vector<double> m_sciFmtLoThrsh_val; // x < thrsh => scientific format
160  std::vector<double> m_sciFmtHiThrsh_val; // x >= thrsh => scientific format
161 
162  std::vector<bool> m_dispPercent;
163  std::vector<bool> m_isForceable;
164 };
165 
166 
167 } // namespace TextUtil
168 
169 } // namespace Analysis
170 
171 //****************************************************************************
172 
173 #endif // Analysis_TextUtil_hpp
std::vector< double > m_sciFmtLoThrsh_pct
Definition: TextUtil.hpp:156
std::vector< bool > m_dispPercent
Definition: TextUtil.hpp:162
void genCol(uint mid, double metricVal, double metricTot, Flag flg=Flag_NULL)
Definition: TextUtil.cpp:183
std::vector< double > m_sciFmtLoThrsh_val
Definition: TextUtil.hpp:159
void genCol(uint mid, double metricVal, Flag flg=Flag_ForceVal)
Definition: TextUtil.hpp:119
ColumnFormatter(const Prof::Metric::Mgr &metricMgr, std::ostream &os, int numDecPct, int numDecVal)
Definition: TextUtil.cpp:93
unsigned int uint
Definition: uint.h:124
const Prof::Metric::Mgr & m_mMgr
Definition: TextUtil.hpp:146
std::vector< bool > m_isForceable
Definition: TextUtil.hpp:163
std::vector< double > m_sciFmtHiThrsh_pct
Definition: TextUtil.hpp:157
std::vector< double > m_sciFmtHiThrsh_val
Definition: TextUtil.hpp:160