mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 17:07:19 +02:00
Enhancement - statistics
- Added total data file size to statistics report. - Implemented util.cpp/formatBytes.
This commit is contained in:
parent
ec17eaaa43
commit
aeaf443f67
3 changed files with 35 additions and 0 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -1594,6 +1595,21 @@ std::string handleReportStats ()
|
||||||
{
|
{
|
||||||
std::stringstream out;
|
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.
|
// Get all the tasks.
|
||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.get ("locking", true));
|
context.tdb.lock (context.config.get ("locking", true));
|
||||||
|
@ -1712,6 +1728,10 @@ std::string handleReportStats ()
|
||||||
table.addCell (row, 0, "Projects");
|
table.addCell (row, 0, "Projects");
|
||||||
table.addCell (row, 1, (int)allProjects.size ());
|
table.addCell (row, 1, (int)allProjects.size ());
|
||||||
|
|
||||||
|
row = table.addRow ();
|
||||||
|
table.addCell (row, 0, "Data size");
|
||||||
|
table.addCell (row, 1, formatBytes (dataSize));
|
||||||
|
|
||||||
if (totalT)
|
if (totalT)
|
||||||
{
|
{
|
||||||
row = table.addRow ();
|
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);
|
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 (
|
int autoComplete (
|
||||||
const std::string& partial,
|
const std::string& partial,
|
||||||
|
|
|
@ -54,6 +54,7 @@ bool confirm (const std::string&);
|
||||||
void delay (float);
|
void delay (float);
|
||||||
std::string formatSeconds (time_t);
|
std::string formatSeconds (time_t);
|
||||||
std::string formatSecondsCompact (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>&);
|
int autoComplete (const std::string&, const std::vector<std::string>&, std::vector<std::string>&);
|
||||||
const std::string uuid ();
|
const std::string uuid ();
|
||||||
int convertDuration (const std::string&);
|
int convertDuration (const std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue