Debian Codegraph @

src/reports/TaskReport.cpp

raw
1 #include <pbcopper/reports/Report.h>
2
3 #include <exception>
4 #include <ostream>
5 #include <string>
6
7 #if defined(_POSIX_VERSION)
8 #include <unistd.h>
9 #endif
10
11 namespace PacBio {
12 namespace Reports {
13
14 TaskReport::TaskReport(int nproc, double runTime, int exitCode, int64_t peakRss)
15 : report_{"workflow_task", "Task Report"}
16 {
17 #if defined(_POSIX_VERSION)
18 char hostname_[255];
19 int rc = gethostname(hostname_, 255);
20 if (rc != 0) {
21 throw std::runtime_error{"[pbcopper] reports ERROR: gethostname() failed"};
22 }
23 std::string hostname(hostname_);
24 #else
25 std::string hostname = "unknown";
26 #endif
27 double peakRssGb = peakRss / 1024.0 / 1024.0 / 1024.0;
28 report_.Attributes({{"host", hostname, "Hostname"},
29 {"nproc", nproc, "Number of cores/slots"},
30 {"run_time", runTime, "Run time (seconds)"},
31 {"exit_code", exitCode, "Exit code"},
32 {"peak_rss", peakRssGb, "Peak RSS (GB)"}});
33 }
34
35 void TaskReport::Print(const std::filesystem::path& filename, const std::string& prefix) const
36 {
37 report_.Print(filename, prefix);
38 }
39
40 void TaskReport::Print(std::ostream& out, const std::string& prefix) const
41 {
42 report_.Print(out, prefix);
43 }
44
45 } // namespace Reports
46 } // namespace PacBio