Hedgehog  0.0.0
A library to generate hybrid pipeline workflow systems
graph_signal_handler.h
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 "../../hedgehog.h"
29 namespace hh {
36 template<class GraphOutput, class ... GraphInputs>
38  private:
39  static Graph<GraphOutput, GraphInputs...>
41  static bool
43 
47 
48  public:
54  static void handleSignal(int signum = SIGTERM) {
55 #ifdef _WIN32
56  std::string signalString(std::to_string(signum));
57 #else
58  std::string signalString(strsignal(signum));
59 #endif
60 
61  if (!signalHandled_) {
62  signalHandled_ = true;
63  std::cout << "signal caught: " << signum << ": (" << signalString << ")" << std::endl;
65  signalString + "-graph-output.dot", colorScheme, structureOptions, debugOptions);
66  }
67  }
68 
70  static void atExit() {
71  if (graphInstance_)
72  graphInstance_->createDotFile("Exit-graph-output.dot");
73  }
74 
77  static void setColorScheme(ColorScheme scheme) {
78  colorScheme = scheme;
79  }
80 
83  static void setStructureOptions(StructureOptions options) {
84  structureOptions = options;
85  }
86 
89  static void setDebugOptions(DebugOptions options) {
90  debugOptions = options;
91  }
92 
96  graphInstance_ = graph;
97  }
98 
102  static void registerSignal(int signum = SIGTERM, bool atExit = false) {
104  if (atExit) {
106  }
107  }
108 };
109 
110 template<class GraphOutput, class ... GraphInputs>
111 bool GraphSignalHandler<GraphOutput, GraphInputs...>
112  ::signalHandled_ = false;
113 
114 template<class GraphOutput, class ... GraphInputs>
115 Graph<GraphOutput, GraphInputs...> *GraphSignalHandler<GraphOutput, GraphInputs...>
116  ::graphInstance_ = nullptr;
117 
118 
119 template<class GraphOutput, class ... GraphInputs>
120 ColorScheme GraphSignalHandler<GraphOutput, GraphInputs...>
122 
123 template<class GraphOutput, class ... GraphInputs>
124 StructureOptions GraphSignalHandler<GraphOutput, GraphInputs...>
126 
127 template<class GraphOutput, class ... GraphInputs>
128 DebugOptions GraphSignalHandler<GraphOutput, GraphInputs...>
130 
131 
132 }
133 #endif //HEDGEHOG_GRAPH_SIGNAL_HANDLER_H
static void setDebugOptions(DebugOptions options)
Sets the debug options for dot file generation.
static void registerGraph(Graph< GraphOutput, GraphInputs... > *graph)
Registers a task graph to be displayed when a signal is fired.
static void handleSignal(int signum=SIGTERM)
Function that handles signals.
StructureOptions
Enum structural options.
Definition: dot_printer.h:44
static void setColorScheme(ColorScheme scheme)
Sets the color scheme for dot file generation.
Hedgehog main namespace.
static DebugOptions debugOptions
< The debug options to use for graph dot file
Implements a signal handler to catch events such as termination and killing.
DebugOptions
Enum to enable debug printing.
Definition: dot_printer.h:52
static ColorScheme colorScheme
< The color scheme to use for graph dot file
Colors nodes based on execution time.
void createDotFile(std::filesystem::path const &dotFilePath, ColorScheme colorScheme=ColorScheme::NONE, StructureOptions structureOptions=StructureOptions::NONE, DebugOptions debugOption=DebugOptions::NONE)
Create a dot file representing a snapshot of the state of the graph at the moment of the call...
Definition: graph.h:259
Main Hedgehog object that does computation.
Definition: graph.h:85
Displays both ALLTHREADING and QUEUE.
Shows debug information such as pointer addresses for nodes and edges.
static StructureOptions structureOptions
< The structure options to use for graph dot file
static Graph< GraphOutput, GraphInputs... > * graphInstance_
< The outer graph instance
static void registerSignal(int signum=SIGTERM, bool atExit=false)
Registers a signal for handling. (default SIGTERM)
static void setStructureOptions(StructureOptions options)
Sets the structure options for dot file generation.
static bool signalHandled_
Flag to indicate if a signal has been fired or not.
static void atExit()
Create a dot file at exit if the instance still exist.
ColorScheme
Enum color options.
Definition: dot_printer.h:37