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.
enumerate.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/** \file runtime/enumerate.hpp
26 * \headerfile runtime/enumerate.hpp "timemory/runtime/enumerate.hpp"
27 * Provides implementation for initialize, enumerate_components which regularly
28 * change as more features are added
29 *
30 */
31
32#pragma once
33
35#include "timemory/enum.h"
39
40#include <initializer_list>
41#include <set>
42#include <vector>
43
44namespace tim
45{
46//--------------------------------------------------------------------------------------//
47//
48/// description:
49/// use this function to generate an array of enumerations from a list of string
50/// that can be subsequently used to initialize an auto_list or a component_list
51///
52/// usage:
53/// using namespace tim::component;
54/// using optional_t = tim::auto_list<wall_clock, cpu_clock, cpu_util, cuda_event>;
55///
56/// auto obj = new optional_t(__FUNCTION__, __LINE__);
57/// tim::initialize(*obj, tim::enumerate_components({ "cpu_clock", "cpu_util"}));
58///
59template <typename StringT, typename... ExtraArgs,
60 template <typename, typename...> class Container>
61std::vector<TIMEMORY_COMPONENT>
62enumerate_components(const Container<StringT, ExtraArgs...>& component_names)
63{
64 std::set<TIMEMORY_COMPONENT> _set;
65 for(const auto& itr : component_names)
66 _set.insert(runtime::enumerate(std::string(itr)));
67 std::vector<TIMEMORY_COMPONENT> _vec;
68 _vec.reserve(_set.size());
69 for(auto&& itr : _set)
70 _vec.emplace_back(itr);
71 return _vec;
72}
73
74//--------------------------------------------------------------------------------------//
75
76inline std::set<TIMEMORY_COMPONENT>
77enumerate_components(const std::initializer_list<std::string>& component_names)
78{
79 return enumerate_components(std::set<std::string>(component_names));
80}
81
82//--------------------------------------------------------------------------------------//
83
84template <typename StringT = std::string>
85std::vector<TIMEMORY_COMPONENT>
86enumerate_components(const std::string& names, const StringT& env_id = "")
87{
88 if(std::string(env_id).length() > 0)
89 {
90 return enumerate_components(tim::delimit(get_env<std::string>(env_id, names)));
91 }
92 {
94 }
95}
96
97//======================================================================================//
98
99template <typename... ExtraArgs>
100std::set<TIMEMORY_COMPONENT>
101enumerate_components(const std::set<std::string, ExtraArgs...>& component_names)
102{
103 std::set<TIMEMORY_COMPONENT> vec;
104 for(const auto& itr : component_names)
105 vec.insert(runtime::enumerate(itr));
106 return vec;
107}
108
109//======================================================================================//
110
111} // namespace tim
112
113//======================================================================================//
int enumerate(const std::string &key)
Definition: properties.hpp:258
Definition: kokkosp.cpp:39
std::vector< TIMEMORY_COMPONENT > enumerate_components(const Container< StringT, ExtraArgs... > &component_names)
description: use this function to generate an array of enumerations from a list of string that can be...
Definition: enumerate.hpp:62
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
ContainerT delimit(const std::string &line, const std::string &delimiters="\"',;: ", PredicateT &&predicate=[](const std::string &s) -> std::string { return s;})
Definition: delimit.hpp:68