timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
print_statistics.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25/**
26 * \file timemory/operations/types/print_statistics.hpp
27 * \brief Definition for various functions for print_statistics in operations
28 */
29
30#pragma once
31
39
40#include <cstdint>
41#include <type_traits>
42#include <vector>
43
44namespace tim
45{
46namespace operation
47{
48//
49//--------------------------------------------------------------------------------------//
50//
51/// \struct tim::operation::print_statistics
52/// \brief prints the statistics for a type
53//
54//--------------------------------------------------------------------------------------//
55//
56template <typename Tp>
58{
59public:
60 using type = Tp;
61 using widths_t = std::vector<int64_t>;
62
63public:
64 template <typename Self, template <typename> class Sp, typename Vp, typename Up = Tp,
66 TIMEMORY_COLD print_statistics(const type&, utility::stream& _os, const Self&,
67 const Sp<Vp>& _stats, uint64_t)
68 {
70 utility::write_entry(_os, "MIN", _stats.get_min());
72 utility::write_entry(_os, "MAX", _stats.get_max());
74 utility::write_entry(_os, "VAR", _stats.get_variance());
76 utility::write_entry(_os, "STDDEV", _stats.get_stddev());
77 }
78
79 template <typename Self, typename Vp, typename Up = Tp,
81 TIMEMORY_COLD print_statistics(const type&, utility::stream&, const Self&, const Vp&,
82 uint64_t)
83 {}
84
85 template <typename Self>
86 TIMEMORY_COLD print_statistics(const type&, utility::stream&, const Self&,
87 const statistics<std::tuple<>>&, uint64_t)
88 {}
89
90public:
91 template <template <typename> class Sp, typename Vp, typename Up = Tp,
93 static TIMEMORY_COLD void get_header(utility::stream& _os, const Sp<Vp>&)
94 {
95 auto _flags = Tp::get_format_flags();
96 auto _width = Tp::get_width();
97 auto _prec = Tp::get_precision();
98
100 utility::write_header(_os, "MIN", _flags, _width, _prec);
102 utility::write_header(_os, "MAX", _flags, _width, _prec);
104 utility::write_header(_os, "VAR", _flags, _width, _prec);
106 utility::write_header(_os, "STDDEV", _flags, _width, _prec);
107 }
108
109 template <typename Vp, typename Up = Tp,
111 static void get_header(utility::stream&, Vp&)
112 {}
113
114 static void get_header(utility::stream&, const statistics<std::tuple<>>&) {}
115};
116//
117//--------------------------------------------------------------------------------------//
118//
119} // namespace operation
120} // namespace tim
auto write_header(Args &&... args)
Definition: stream.hpp:989
auto write_entry(Args &&... args)
Definition: stream.hpp:996
Definition: kokkosp.cpp:39
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
Definition: types.hpp:190
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
common string manipulation utilities
prints the statistics for a type
static void get_header(utility::stream &, const statistics< std::tuple<> > &)
print_statistics(const type &, utility::stream &_os, const Self &, const Sp< Vp > &_stats, uint64_t)
print_statistics(const type &, utility::stream &, const Self &, const statistics< std::tuple<> > &, uint64_t)
static void get_header(utility::stream &_os, const Sp< Vp > &)
print_statistics(const type &, utility::stream &, const Self &, const Vp &, uint64_t)
static void get_header(utility::stream &, Vp &)
A generic class for statistical accumulation. It uses the timemory math overloads to enable statistic...
Definition: statistics.hpp:83
trait that allows runtime configuration of reporting certain types of values. Only applies to text ou...