SPH
Crashpad.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "io/Output.h"
4 #include "quantities/Storage.h"
5 #include "system/Statistics.h"
6 #include <csignal>
7 
9 
10 class CrashPad {
11 private:
12  SharedPtr<Storage> storage;
13  Path dumpPath;
14 
15 public:
16  static void setup(SharedPtr<Storage> storage, const Path& dumpPath) {
17  getInstance().storage = storage;
18  getInstance().dumpPath = dumpPath;
19  signal(SIGSEGV, handler);
20  }
21 
22  static CrashPad& getInstance() {
23  static CrashPad instance;
24  return instance;
25  }
26 
27 private:
28  static void handler(const int UNUSED(signal)) {
29  /*void* array[10];
30  size_t size;
31 
32  // get void*'s for all entries on the stack
33  size = backtrace(array, 10);
34 
35  // print out all the frames to stderr
36  fprintf(stderr, "Error: signal %d:\n", sig);
37  backtrace_symbols_fd(array, size, STDERR_FILENO);*/
38  BinaryOutput output(getInstance().dumpPath);
39  Statistics stats;
40  stats.set(StatisticsId::RUN_TIME, 0._f);
41  stats.set(StatisticsId::TIMESTEP_VALUE, 1._f);
42  output.dump(*getInstance().storage, stats);
43  std::exit(1);
44  }
45 };
46 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
Saving and loading particle data.
Statistics gathered and periodically displayed during the run.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
@ TIMESTEP_VALUE
Current value of timestep.
Container for storing particle quantities and materials.
Output saving data to binary data without loss of precision.
Definition: Output.h:335
static void setup(SharedPtr< Storage > storage, const Path &dumpPath)
Definition: Crashpad.h:16
static CrashPad & getInstance()
Definition: Crashpad.h:22
Object representing a path on a filesystem.
Definition: Path.h:17
Object holding various statistics about current run.
Definition: Statistics.h:22
Statistics & set(const StatisticsId idx, TValue &&value)
Sets new values of a statistic.
Definition: Statistics.h:52