Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
graph_signal_handler.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19
20#ifndef HEDGEHOG_GRAPH_SIGNAL_HANDLER_H
21#define HEDGEHOG_GRAPH_SIGNAL_HANDLER_H
22#pragma once
23
24#include <csignal>
25#include <cstring>
26
27#include "graph.h"
29namespace hh {
38template<size_t Separator, class ...AllTypes>
40 private:
41 static Graph<Separator, AllTypes...> *graphInstance_;
42 static bool signalHandled_;
46
47 public:
53 static void handleSignal(int signum = SIGTERM) {
54#ifdef _WIN32
55 std::string signalString(std::to_string(signum));
56#else
57 std::string signalString(strsignal(signum));
58#endif
59
60 if (!signalHandled_) {
61 signalHandled_ = true;
62 std::cout << "signal caught: " << signum << ": (" << signalString << ")" << std::endl;
64 signalString + "-graph-output.dot", colorScheme, structureOptions, debugOptions);
65 }
66 }
67
69 static void atExit() {
71 graphInstance_->createDotFile("Exit-graph-output.dot");
72 }
73
76 static void setColorScheme(ColorScheme scheme) {
77 colorScheme = scheme;
78 }
79
83 structureOptions = options;
84 }
85
88 static void setDebugOptions(DebugOptions options) {
89 debugOptions = options;
90 }
91
95 graphInstance_ = graph;
96 }
97
101 static void registerSignal(int signum = SIGTERM, bool atExit = false) {
103 if (atExit) {
105 }
106 }
107};
108
112template<size_t Separator, class ...AllTypes>
113bool GraphSignalHandler<Separator, AllTypes...>::signalHandled_ = false;
114
118template<size_t Separator, class ...AllTypes>
119Graph<Separator, AllTypes...> *GraphSignalHandler<Separator, AllTypes...>::graphInstance_ = nullptr;
120
124template<size_t Separator, class ...AllTypes>
125ColorScheme GraphSignalHandler<Separator, AllTypes...>::colorScheme = ColorScheme::EXECUTION;
126
130template<size_t Separator, class ...AllTypes>
131StructureOptions GraphSignalHandler<Separator, AllTypes...>::structureOptions = StructureOptions::ALL;
132
136template<size_t Separator, class ...AllTypes>
137DebugOptions GraphSignalHandler<Separator, AllTypes...>::debugOptions = DebugOptions::ALL;
138}
139#endif //HEDGEHOG_GRAPH_SIGNAL_HANDLER_H
Hedgehog main namespace.
StructureOptions
Enum structural options.
@ ALL
Displays both THREADING and QUEUE.
DebugOptions
Enum to enable debug printing.
Definition: debug_options.h:27
@ ALL
Shows debug information such as pointer addresses for nodes and edges.
ColorScheme
Enum color options.
Definition: color_scheme.h:27
@ EXECUTION
Colors nodes based on execution time.
Hedgehog graph abstraction.
Definition: graph.h:137
void createDotFile(std::filesystem::path const &dotFilePath, ColorScheme colorScheme=ColorScheme::NONE, StructureOptions structureOptions=StructureOptions::NONE, DebugOptions debugOption=DebugOptions::NONE, std::unique_ptr< ColorPicker > colorPicker=std::make_unique< JetColor >(), bool verbose=false)
Create a dot file representing a snapshot of the state of the graph at the moment of the call,...
Definition: graph.h:324
Implements a signal handler to catch events such as termination and killing.
static void atExit()
Create a dot file at exit if the instance still exist.
static void handleSignal(int signum=SIGTERM)
Function that handles signals.
static void setColorScheme(ColorScheme scheme)
Sets the color scheme for dot file generation.
static void setStructureOptions(StructureOptions options)
Sets the structure options for dot file generation.
static StructureOptions structureOptions
< The structure options to use for graph dot file
static ColorScheme colorScheme
< The color scheme to use for graph dot file
static void registerSignal(int signum=SIGTERM, bool atExit=false)
Registers a signal for handling. (default SIGTERM)
static bool signalHandled_
Flag to indicate if a signal has been fired or not.
static Graph< Separator, AllTypes... > * graphInstance_
< The outer graph instance
static DebugOptions debugOptions
< The debug options to use for graph dot file
static void setDebugOptions(DebugOptions options)
Sets the debug options for dot file generation.
static void registerGraph(Graph< Separator, AllTypes... > *graph)
Registers a task graph to be displayed when a signal is fired.