From a1bc8d7d45519b47fbc2dd13c47f4c4478b3285c Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 8 Sep 2015 15:04:22 -0700 Subject: iotop: fix bytes per second, and add accumulation Bytes per second forgot to divide bytes by seconds. Also add the -a flag to print bytes instead of bytes per second. Change-Id: I419b2ec0f702a291d299fe736d2d4ab290c03445 --- iotop/iotop.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'iotop') diff --git a/iotop/iotop.cpp b/iotop/iotop.cpp index e2d7e0b8..1b8628eb 100644 --- a/iotop/iotop.cpp +++ b/iotop/iotop.cpp @@ -41,6 +41,7 @@ static float TimeToTgidPercent(uint64_t ns, int time, const TaskStatistics& stat static void usage(char* myname) { printf( "Usage: %s [-h] [-P] [-d ] [-n ] [-s ]\n" + " -a Show byte count instead of rate\n" " -d Set the delay between refreshes in seconds.\n" " -h Display this help screen.\n" " -m Set the number of processes or threads to show\n" @@ -97,6 +98,7 @@ static Sorter GetSorter(const std::string field) { } int main(int argc, char* argv[]) { + bool accumulated = false; bool processes = false; int delay = 1; int cycles = -1; @@ -108,6 +110,7 @@ int main(int argc, char* argv[]) { while (1) { int c; static const option longopts[] = { + {"accumulated", 0, 0, 'a'}, {"delay", required_argument, 0, 'd'}, {"help", 0, 0, 'h'}, {"limit", required_argument, 0, 'm'}, @@ -116,11 +119,14 @@ int main(int argc, char* argv[]) { {"processes", 0, 0, 'P'}, {0, 0, 0, 0}, }; - c = getopt_long(argc, argv, "d:hm:n:Ps:", longopts, NULL); + c = getopt_long(argc, argv, "ad:hm:n:Ps:", longopts, NULL); if (c < 0) { break; } switch (c) { + case 'a': + accumulated = true; + break; case 'd': delay = atoi(optarg); break; @@ -213,8 +219,13 @@ int main(int argc, char* argv[]) { if (!second) { printf("\n"); } - printf("%6s %-16s %20s %34s\n", "", "", - "--- IO (KiB/s) ---", "----------- delayed on ----------"); + if (accumulated) { + printf("%6s %-16s %20s %34s\n", "", "", + "---- IO (KiB) ----", "----------- delayed on ----------"); + } else { + printf("%6s %-16s %20s %34s\n", "", "", + "--- IO (KiB/s) ---", "----------- delayed on ----------"); + } printf("%6s %-16s %6s %6s %6s %-5s %-5s %-5s %-5s %-5s\n", "PID", "Command", @@ -228,12 +239,13 @@ int main(int argc, char* argv[]) { "total"); int n = limit; for (const TaskStatistics& statistics : stats) { + const int delay_div = accumulated ? 1 : delay; printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n", statistics.pid(), statistics.comm().c_str(), - BytesToKB(statistics.read()), - BytesToKB(statistics.write()), - BytesToKB(statistics.read_write()), + BytesToKB(statistics.read()) / delay_div, + BytesToKB(statistics.write()) / delay_div, + BytesToKB(statistics.read_write()) / delay_div, TimeToTgidPercent(statistics.delay_io(), delay, statistics), TimeToTgidPercent(statistics.delay_swap(), delay, statistics), TimeToTgidPercent(statistics.delay_sched(), delay, statistics), -- cgit v1.2.3