Skip to content

Commit c5cacc1

Browse files
committed
iotop: add total read/write stats
Provide total read, write, and read/write stats across all threads or processes. Change-Id: I7dc2edd45681b6a54f67347337c76deb1342dc95
1 parent a1bc8d7 commit c5cacc1

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

iotop/iotop.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,35 @@ int main(int argc, char* argv[]) {
238238
"mem",
239239
"total");
240240
int n = limit;
241+
const int delay_div = accumulated ? 1 : delay;
242+
uint64_t total_read = 0;
243+
uint64_t total_write = 0;
244+
uint64_t total_read_write = 0;
241245
for (const TaskStatistics& statistics : stats) {
242-
const int delay_div = accumulated ? 1 : delay;
243-
printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n",
244-
statistics.pid(),
245-
statistics.comm().c_str(),
246-
BytesToKB(statistics.read()) / delay_div,
247-
BytesToKB(statistics.write()) / delay_div,
248-
BytesToKB(statistics.read_write()) / delay_div,
249-
TimeToTgidPercent(statistics.delay_io(), delay, statistics),
250-
TimeToTgidPercent(statistics.delay_swap(), delay, statistics),
251-
TimeToTgidPercent(statistics.delay_sched(), delay, statistics),
252-
TimeToTgidPercent(statistics.delay_mem(), delay, statistics),
253-
TimeToTgidPercent(statistics.delay_total(), delay, statistics));
254-
if (n > 0 && --n == 0) break;
246+
total_read += statistics.read();
247+
total_write += statistics.write();
248+
total_read_write += statistics.read_write();
249+
250+
if (n > 0) {
251+
n--;
252+
printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n",
253+
statistics.pid(),
254+
statistics.comm().c_str(),
255+
BytesToKB(statistics.read()) / delay_div,
256+
BytesToKB(statistics.write()) / delay_div,
257+
BytesToKB(statistics.read_write()) / delay_div,
258+
TimeToTgidPercent(statistics.delay_io(), delay, statistics),
259+
TimeToTgidPercent(statistics.delay_swap(), delay, statistics),
260+
TimeToTgidPercent(statistics.delay_sched(), delay, statistics),
261+
TimeToTgidPercent(statistics.delay_mem(), delay, statistics),
262+
TimeToTgidPercent(statistics.delay_total(), delay, statistics));
263+
}
255264
}
265+
printf("%6s %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 "\n", "", "TOTAL",
266+
BytesToKB(total_read) / delay_div,
267+
BytesToKB(total_write) / delay_div,
268+
BytesToKB(total_read_write) / delay_div);
269+
256270
second = false;
257271

258272
if (cycles > 0 && --cycles == 0) break;

0 commit comments

Comments
 (0)