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.
ctest_notes.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#pragma once
26
32
33#include <memory>
34#include <set>
35#include <sstream>
36#include <string>
37
38namespace tim
39{
40//
41class manager;
42//
43namespace operation
44{
45namespace finalize
46{
47//
48//--------------------------------------------------------------------------------------//
49//
50struct ctest_notes_deleter : public std::default_delete<std::set<std::string>>
51{
52 using strset_t = std::set<std::string>;
53
56
57 TIMEMORY_COLD void operator()(strset_t* data)
58 {
60 if(data->empty() || !_settings || !_settings->get_ctest_notes())
61 {
62 delete data;
63 return;
64 }
65
66 std::stringstream ss;
67 // loop over filenames
68 for(auto&& itr : *data)
69 {
70 std::string str = itr;
71 size_t pos = std::string::npos;
72 while((pos = str.find('\\')) != std::string::npos)
73 str = str.replace(pos, 1, "/");
74 while((pos = str.find("//")) != std::string::npos)
75 str = str.replace(pos, 1, "/");
76 ss << "LIST(APPEND CTEST_NOTES_FILES \"" << str << "\")\n";
77 }
78
79 if(!data->empty())
80 ss << "LIST(REMOVE_DUPLICATES CTEST_NOTES_FILES)\n";
81
82 auto fname = settings::compose_output_filename("CTestNotes", "txt", false, -1,
84 std::ofstream ofs{};
85 if(filepath::open(ofs, fname, std::ios::out | std::ios::app))
86 {
88 {
89 std::cout << "[ctest_notes]> Outputting '" << fname << "'..."
90 << std::endl;
91 }
92 ofs << ss.str() << std::endl;
93 }
94 delete data;
95 }
96};
97
98//
99//--------------------------------------------------------------------------------------//
100//
101template <>
103{
104 using strset_t = std::set<std::string>;
105 using notes_ptr_t = std::unique_ptr<strset_t, ctest_notes_deleter>;
106
108 {
109 static auto _instance = notes_ptr_t(new strset_t);
110 return _instance;
111 }
112
113 TIMEMORY_COLD ctest_notes(std::string&& fname)
114 {
115 get_notes()->insert(std::forward<std::string>(fname));
116 }
117
118 TIMEMORY_COLD ctest_notes(strset_t&& fnames)
119 {
120 for(auto&& itr : fnames)
121 get_notes()->insert(itr);
122 }
123};
124//
125//--------------------------------------------------------------------------------------//
126//
127template <typename Type>
128struct ctest_notes : public ctest_notes<manager>
129{
130 using strset_t = std::set<std::string>;
133
135
136 template <typename Tp>
137 ctest_notes(Tp&& fnames)
138 : base_type(std::forward<Tp>(fnames))
139 {}
140};
141//
142//--------------------------------------------------------------------------------------//
143//
144} // namespace finalize
145} // namespace operation
146} // namespace tim
STL namespace.
bool open(std::ofstream &_ofs, std::string _fpath, Args &&... _args)
Definition: filepath.hpp:207
Definition: kokkosp.cpp:39
output_prefix
Definition: settings.cpp:1662
char argparse::argument_parser tim::settings * _settings
Definition: config.cpp:255
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
size_t pos
Definition: config.cpp:102
void finalize()
Definition: types.hpp:119
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
std::unique_ptr< strset_t, ctest_notes_deleter > notes_ptr_t
typename base_type::notes_ptr_t notes_ptr_t
std::set< std::string > strset_t
static string_t compose_output_filename(string_t _tag, string_t _ext, bool _use_suffix=use_output_suffix(), int32_t _suffix=default_process_suffix(), bool _make_dir=false, std::string _explicit={})
Definition: settings.cpp:322
static settings * instance()
Definition: settings.hpp:536