Skip to content

Commit a1bc8d7

Browse files
committed
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
1 parent a2b2d81 commit a1bc8d7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

iotop/iotop.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static float TimeToTgidPercent(uint64_t ns, int time, const TaskStatistics& stat
4141
static void usage(char* myname) {
4242
printf(
4343
"Usage: %s [-h] [-P] [-d <delay>] [-n <cycles>] [-s <column>]\n"
44+
" -a Show byte count instead of rate\n"
4445
" -d Set the delay between refreshes in seconds.\n"
4546
" -h Display this help screen.\n"
4647
" -m Set the number of processes or threads to show\n"
@@ -97,6 +98,7 @@ static Sorter GetSorter(const std::string field) {
9798
}
9899

99100
int main(int argc, char* argv[]) {
101+
bool accumulated = false;
100102
bool processes = false;
101103
int delay = 1;
102104
int cycles = -1;
@@ -108,6 +110,7 @@ int main(int argc, char* argv[]) {
108110
while (1) {
109111
int c;
110112
static const option longopts[] = {
113+
{"accumulated", 0, 0, 'a'},
111114
{"delay", required_argument, 0, 'd'},
112115
{"help", 0, 0, 'h'},
113116
{"limit", required_argument, 0, 'm'},
@@ -116,11 +119,14 @@ int main(int argc, char* argv[]) {
116119
{"processes", 0, 0, 'P'},
117120
{0, 0, 0, 0},
118121
};
119-
c = getopt_long(argc, argv, "d:hm:n:Ps:", longopts, NULL);
122+
c = getopt_long(argc, argv, "ad:hm:n:Ps:", longopts, NULL);
120123
if (c < 0) {
121124
break;
122125
}
123126
switch (c) {
127+
case 'a':
128+
accumulated = true;
129+
break;
124130
case 'd':
125131
delay = atoi(optarg);
126132
break;
@@ -213,8 +219,13 @@ int main(int argc, char* argv[]) {
213219
if (!second) {
214220
printf("\n");
215221
}
216-
printf("%6s %-16s %20s %34s\n", "", "",
217-
"--- IO (KiB/s) ---", "----------- delayed on ----------");
222+
if (accumulated) {
223+
printf("%6s %-16s %20s %34s\n", "", "",
224+
"---- IO (KiB) ----", "----------- delayed on ----------");
225+
} else {
226+
printf("%6s %-16s %20s %34s\n", "", "",
227+
"--- IO (KiB/s) ---", "----------- delayed on ----------");
228+
}
218229
printf("%6s %-16s %6s %6s %6s %-5s %-5s %-5s %-5s %-5s\n",
219230
"PID",
220231
"Command",
@@ -228,12 +239,13 @@ int main(int argc, char* argv[]) {
228239
"total");
229240
int n = limit;
230241
for (const TaskStatistics& statistics : stats) {
242+
const int delay_div = accumulated ? 1 : delay;
231243
printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n",
232244
statistics.pid(),
233245
statistics.comm().c_str(),
234-
BytesToKB(statistics.read()),
235-
BytesToKB(statistics.write()),
236-
BytesToKB(statistics.read_write()),
246+
BytesToKB(statistics.read()) / delay_div,
247+
BytesToKB(statistics.write()) / delay_div,
248+
BytesToKB(statistics.read_write()) / delay_div,
237249
TimeToTgidPercent(statistics.delay_io(), delay, statistics),
238250
TimeToTgidPercent(statistics.delay_swap(), delay, statistics),
239251
TimeToTgidPercent(statistics.delay_sched(), delay, statistics),

0 commit comments

Comments
 (0)