forked from lthn/blockchain
performance_tests: free_space_check (#133)
This commit is contained in:
parent
e9bc068bfb
commit
b4c1542597
2 changed files with 91 additions and 1 deletions
87
tests/performance_tests/free_space_check.h
Normal file
87
tests/performance_tests/free_space_check.h
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
std::string exec(const char* cmd)
|
||||
{
|
||||
std::array<char, 1024> buffer;
|
||||
|
||||
#if defined(WIN32)
|
||||
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
|
||||
#else
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||
#endif
|
||||
|
||||
if (!pipe)
|
||||
throw std::runtime_error("popen() failed!");
|
||||
|
||||
|
||||
std::string result;
|
||||
while (fgets(buffer.data(), static_cast<int>(buffer.size()), pipe.get()) != nullptr)
|
||||
result += buffer.data();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void free_space_check()
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
std::string output;
|
||||
|
||||
#ifdef WIN32
|
||||
output = exec("dir");
|
||||
#else
|
||||
output = exec("df -h");
|
||||
#endif
|
||||
|
||||
LOG_PRINT_L0("test command output:" << std::endl << output);
|
||||
|
||||
boost::filesystem::path current_path(".");
|
||||
|
||||
size_t counter = 0;
|
||||
while (true)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds( 900 ));
|
||||
try
|
||||
{
|
||||
fs::space_info si = fs::space(current_path);
|
||||
if (si.available > 1024)
|
||||
{
|
||||
// free space is ok
|
||||
counter = (counter + 1) % 4;
|
||||
std::cout << '\b';
|
||||
std::cout << ( counter == 0 ? '*' : counter == 1 ? '\\' : counter == 2 ? '|' : '/' );
|
||||
continue;
|
||||
}
|
||||
// free space is not ok!
|
||||
LOG_PRINT_YELLOW("free space available: " << si.available, LOG_LEVEL_0);
|
||||
#ifdef WIN32
|
||||
output = exec("dir");
|
||||
#else
|
||||
output = exec("df -h");
|
||||
#endif
|
||||
LOG_PRINT_YELLOW(output, LOG_LEVEL_0);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR("failed to determine free space: " << e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
LOG_ERROR("failed to determine free space: unknown exception");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
#include "keccak_test.h"
|
||||
#include "blake2_test.h"
|
||||
#include "print_struct_to_json.h"
|
||||
#include "free_space_check.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
|
@ -36,7 +37,9 @@ int main(int argc, char** argv)
|
|||
|
||||
//test_blake2();
|
||||
|
||||
print_struct_to_json();
|
||||
free_space_check();
|
||||
|
||||
//print_struct_to_json();
|
||||
|
||||
//performance_timer timer;
|
||||
//timer.start();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue