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.
declaration.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/utility/declaration.hpp
27 * \brief The declaration for the types for utility without definitions
28 */
29
30#pragma once
31
32#include "timemory/backends/signals.hpp"
33
34#include <cfenv>
35#include <csignal>
36#include <functional>
37#include <set>
38#include <string>
39
40namespace tim
41{
42// No Name Default Action Description
43// 1 SIGHUP terminate process terminal line hangup
44// 2 SIGINT terminate process interrupt program
45// 3 SIGQUIT create core image quit program
46// 4 SIGILL create core image illegal instruction
47// 5 SIGTRAP create core image trace trap
48// 6 SIGABRT create core image abort program (formerly SIGIOT)
49// 7 SIGEMT create core image emulate instruction executed
50// 8 SIGFPE create core image floating-point exception
51// 9 SIGKILL terminate process kill program
52// 10 SIGBUS create core image bus error
53// 11 SIGSEGV create core image segmentation violation
54// 12 SIGSYS create core image non-existent system call invoked
55// 13 SIGPIPE terminate process write on a pipe with no reader
56// 14 SIGALRM terminate process real-time timer expired
57// 15 SIGTERM terminate process software termination signal
58// 16 SIGURG discard signal urgent condition present on socket
59// 18 SIGTSTP stop process stop signal generated from keyboard
60// 24 SIGXCPU terminate process cpu time limit exceeded (see
61// setrlimit(2)) 25 SIGXFSZ terminate process file size limit
62// exceeded (see setrlimit(2)) 26 SIGVTALRM terminate process virtual
63// time alarm (see setitimer(2)) 27 SIGPROF terminate process profiling
64// timer alarm (see setitimer(2))
65//
66//--------------------------------------------------------------------------------------//
67//
68enum class sys_signal : int
69{
70 Hangup = SIGHUP, // 1
71 Interrupt = SIGINT, // 2
72 Quit = SIGQUIT, // 3
73 Illegal = SIGILL,
74 Trap = SIGTRAP,
75 Abort = SIGABRT,
76 Emulate = SIGEMT,
77 FPE = SIGFPE,
78 Kill = SIGKILL,
79 Bus = SIGBUS,
80 SegFault = SIGSEGV,
81 System = SIGSYS,
82 Pipe = SIGPIPE,
83 Alarm = SIGALRM,
84 Terminate = SIGTERM,
85 Urgent = SIGURG,
86 Stop = SIGTSTP,
87 CPUtime = SIGXCPU,
88 FileSize = SIGXFSZ,
89 VirtualAlarm = SIGVTALRM,
90 ProfileAlarm = SIGPROF,
91 User1 = SIGUSR1,
92 User2 = SIGUSR2
93};
94//
95//----------------------------------------------------------------------------------//
96//
98{
99public:
100 using signal_set_t = std::set<sys_signal>;
101 using signal_function_t = std::function<void(int)>;
102
103public:
104 static bool& allow();
105 static bool is_active();
106 static void set_active(bool val);
107 static void enable(const sys_signal&);
108 static void disable(const sys_signal&);
109 static std::string str(const sys_signal&);
110 static std::string str(bool report_disabled = false);
111 static void check_environment();
112 static void set_exit_action(signal_function_t _f);
113 static void exit_action(int errcode);
114
115 static signal_set_t get_enabled();
116 static signal_set_t get_disabled();
117 static signal_set_t get_default();
118 static bool& enable_all();
119 static bool& disable_all();
120
121protected:
123 {
124 signals_data();
125 ~signals_data() = default;
126 signals_data(const signals_data&) = default;
130
131 bool signals_active = false;
132 bool enable_all = false;
133 bool disable_all = false;
143 };
144 // default signals to catch
148 };
149
151 {
152 static signal_settings::signals_data instance{};
153 return instance;
154 }
155};
156//
157//--------------------------------------------------------------------------------------//
158//
159inline bool&
161{
162 static bool _instance = true;
163 return _instance;
164}
165//
166//----------------------------------------------------------------------------------//
167//
168} // namespace tim
static std::string str(const sys_signal &)
Definition: signals.hpp:147
static void enable(const sys_signal &)
Definition: signals.hpp:74
static void check_environment()
Definition: signals.hpp:90
static void exit_action(int errcode)
Definition: signals.hpp:288
static bool & enable_all()
Definition: signals.hpp:256
static void disable(const sys_signal &)
Definition: signals.hpp:82
static signal_set_t get_enabled()
Definition: signals.hpp:296
std::set< sys_signal > signal_set_t
std::function< void(int)> signal_function_t
static void set_active(bool val)
Definition: signals.hpp:272
static signal_set_t get_disabled()
Definition: signals.hpp:304
static void set_exit_action(signal_function_t _f)
Definition: signals.hpp:280
static bool is_active()
Definition: signals.hpp:248
static bool & allow()
static bool & disable_all()
Definition: signals.hpp:264
static signal_set_t get_default()
Definition: signals.hpp:312
static signals_data & f_signals()
Definition: kokkosp.cpp:39
sys_signal
Definition: declaration.hpp:69
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
signals_data & operator=(const signals_data &)=default
signals_data(const signals_data &)=default
signals_data(signals_data &&)=default
signals_data & operator=(signals_data &&)=default