Skip to content

Commit 12f454e

Browse files
colincrossGerrit Code Review
authored and
Gerrit Code Review
committed
Merge changes I7dc2edd4,I419b2ec0
* changes: iotop: add total read/write stats iotop: fix bytes per second, and add accumulation
2 parents 59d3e1d + c5cacc1 commit 12f454e

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

Diff for: iotop/iotop.cpp

+41-15
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",
@@ -227,20 +238,35 @@ int main(int argc, char* argv[]) {
227238
"mem",
228239
"total");
229240
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;
230245
for (const TaskStatistics& statistics : stats) {
231-
printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n",
232-
statistics.pid(),
233-
statistics.comm().c_str(),
234-
BytesToKB(statistics.read()),
235-
BytesToKB(statistics.write()),
236-
BytesToKB(statistics.read_write()),
237-
TimeToTgidPercent(statistics.delay_io(), delay, statistics),
238-
TimeToTgidPercent(statistics.delay_swap(), delay, statistics),
239-
TimeToTgidPercent(statistics.delay_sched(), delay, statistics),
240-
TimeToTgidPercent(statistics.delay_mem(), delay, statistics),
241-
TimeToTgidPercent(statistics.delay_total(), delay, statistics));
242-
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+
}
243264
}
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+
244270
second = false;
245271

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

0 commit comments

Comments
 (0)