ROSE  0.11.98.0
WorkerStatus.h
1 #ifndef ROSE_BinaryAnalysis_ModelChecker_WorkerStatus_H
2 #define ROSE_BinaryAnalysis_ModelChecker_WorkerStatus_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/ModelChecker/Types.h>
7 
8 #include <Rose/Progress.h>
9 #include <boost/filesystem.hpp>
10 
11 namespace Rose {
12 namespace BinaryAnalysis {
13 namespace ModelChecker {
14 
16 class WorkerStatus {
17 public:
19  using Ptr = WorkerStatusPtr;
20 
21 private:
22  boost::filesystem::path fileName_;
23  int fd_ = -1;
24 
25  struct Status {
26  WorkerState state = WorkerState::STARTING; // current state
27  time_t stateChange = 0; // time of last state change
28  Progress::Ptr progress; // progress reports
29  };
30 
31  std::vector<Status> workers_;
32  time_t lastFileUpdate_ = 0; // last time that file was updated
33 
34  static constexpr time_t fileUpdatePeriod_ = 1; // update the file every so many seconds
35  static constexpr size_t workersPerLine_ = 4; // number of worker information per line
36  static constexpr size_t barWidth_ = 20; // width of the bar that says how long since a state change
37 
38 protected:
39  WorkerStatus(const boost::filesystem::path &fileName);
40 
41 public:
42  ~WorkerStatus();
43 
44 public:
46  static Ptr instance(const boost::filesystem::path &fileName);
47 
51  void insert(size_t workerIdx, const Progress::Ptr&);
52 
54  void setState(size_t workerIdx, WorkerState);
55 
57  const boost::filesystem::path& fileName() const;
58 
60  void updateFile();
61 
63  void updateFileNow();
64 };
65 
66 } // namespace
67 } // namespace
68 } // namespace
69 
70 #endif
71 #endif
WorkerStatusPtr Ptr
Shared ownership pointer.
Definition: WorkerStatus.h:19
void updateFileNow()
Update file now regardless of how much time has elapsed since prior update.
Writes information about workers to a text file for debugging.
Definition: WorkerStatus.h:16
Main namespace for the ROSE library.
void setState(size_t workerIdx, WorkerState)
Change the state of a worker.
void updateFile()
Update the file if enough time has elapsed since the prior update.
const boost::filesystem::path & fileName() const
Name of file to which status is written.
Binary analysis.
static Ptr instance(const boost::filesystem::path &fileName)
Allocating constructor.
void insert(size_t workerIdx, const Progress::Ptr &)
Create a new worker.