Enhancement - statistics
- Added total data file size to statistics report. - Implemented util.cpp/formatBytes.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@@ -1594,6 +1595,21 @@ std::string handleReportStats ()
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
// Go get the file sizes.
|
||||
size_t dataSize = 0;
|
||||
|
||||
struct stat s;
|
||||
std::string location = expandPath (context.config.get ("data.location"));
|
||||
std::string file = location + "/pending.data";
|
||||
if (!stat (file.c_str (), &s))
|
||||
dataSize += s.st_size;
|
||||
|
||||
file = location + "/completed.data";
|
||||
if (!stat (file.c_str (), &s))
|
||||
dataSize += s.st_size;
|
||||
|
||||
// TODO Include transaction log?
|
||||
|
||||
// Get all the tasks.
|
||||
std::vector <Task> tasks;
|
||||
context.tdb.lock (context.config.get ("locking", true));
|
||||
@@ -1712,6 +1728,10 @@ std::string handleReportStats ()
|
||||
table.addCell (row, 0, "Projects");
|
||||
table.addCell (row, 1, (int)allProjects.size ());
|
||||
|
||||
row = table.addRow ();
|
||||
table.addCell (row, 0, "Data size");
|
||||
table.addCell (row, 1, formatBytes (dataSize));
|
||||
|
||||
if (totalT)
|
||||
{
|
||||
row = table.addRow ();
|
||||
|
||||
14
src/util.cpp
14
src/util.cpp
@@ -147,6 +147,20 @@ std::string formatSecondsCompact (time_t delta)
|
||||
return std::string (formatted);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Convert a quantity in seconds to a more readable format.
|
||||
std::string formatBytes (size_t bytes)
|
||||
{
|
||||
char formatted[24];
|
||||
|
||||
if (bytes > 1000000000) sprintf (formatted, "%.1f GiB", (bytes / 1000000000.0));
|
||||
else if (bytes > 1000000) sprintf (formatted, "%.1f MiB", (bytes / 1000000.0));
|
||||
else if (bytes > 1000) sprintf (formatted, "%.1f KiB", (bytes / 1000.0));
|
||||
else sprintf (formatted, "%d B", (int)bytes );
|
||||
|
||||
return commify (formatted);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int autoComplete (
|
||||
const std::string& partial,
|
||||
|
||||
@@ -54,6 +54,7 @@ bool confirm (const std::string&);
|
||||
void delay (float);
|
||||
std::string formatSeconds (time_t);
|
||||
std::string formatSecondsCompact (time_t);
|
||||
std::string formatBytes (size_t);
|
||||
int autoComplete (const std::string&, const std::vector<std::string>&, std::vector<std::string>&);
|
||||
const std::string uuid ();
|
||||
int convertDuration (const std::string&);
|
||||
|
||||
Reference in New Issue
Block a user