localPackages.hpcstat: export duc output

This commit is contained in:
2024-06-11 16:51:10 +08:00
parent 2534f35c4d
commit 92fdc6c67d
2 changed files with 4 additions and 11 deletions

View File

@@ -30,7 +30,7 @@ namespace hpcstat::disk
{ std::cerr << "HPCSTAT_DATADIR not set\n"; return {}; }
else if
(
auto result = biu::exec
auto result = biu::exec<{.DirectStdout = true, .DirectStderr = true}>
(
// duc index -d ./duc.db -p ~
"{}/duc"_f(*ducbindir),

View File

@@ -180,19 +180,12 @@ int main(int argc, const char** argv)
else if (args[1] == "version") { std::cout << HPCSTAT_VERSION << std::endl; }
else if (args[1] == "diskstat")
{
auto stat_thread = std::async(std::launch::async, []{ return disk::stat(); });
std::cout << "Waiting for disk usage statistic to be collected... 0s" << std::flush;
for (unsigned i = 1; stat_thread.wait_for(1s) != std::future_status::ready; i++)
std::cout << "\rWaiting for disk usage statistic to be collected... {}s"_f(i) << std::flush;
if (!stat_thread.get()) { std::cerr << "Failed to collect disk usage statistic.\n"; return 1; }
if (auto stat = disk::stat(); !stat)
{ std::cerr << "Failed to collect disk usage statistic.\n"; return 1; }
else
{
lock.lock();
if
(
auto write_result = sql::writedb(sql::DiskData{.Data = biu::serialize<char>(*stat_thread.get())});
!write_result
)
if (auto write_result = sql::writedb(sql::DiskData{.Data = biu::serialize<char>(*stat)}); !write_result)
{ std::cerr << "Failed to write disk usage statistic to database.\n"; return 1; }
}
}