@@ -41,6 +41,7 @@ static float TimeToTgidPercent(uint64_t ns, int time, const TaskStatistics& stat
41
41
static void usage (char * myname) {
42
42
printf (
43
43
" Usage: %s [-h] [-P] [-d <delay>] [-n <cycles>] [-s <column>]\n "
44
+ " -a Show byte count instead of rate\n "
44
45
" -d Set the delay between refreshes in seconds.\n "
45
46
" -h Display this help screen.\n "
46
47
" -m Set the number of processes or threads to show\n "
@@ -97,6 +98,7 @@ static Sorter GetSorter(const std::string field) {
97
98
}
98
99
99
100
int main (int argc, char * argv[]) {
101
+ bool accumulated = false ;
100
102
bool processes = false ;
101
103
int delay = 1 ;
102
104
int cycles = -1 ;
@@ -108,6 +110,7 @@ int main(int argc, char* argv[]) {
108
110
while (1 ) {
109
111
int c;
110
112
static const option longopts[] = {
113
+ {" accumulated" , 0 , 0 , ' a' },
111
114
{" delay" , required_argument, 0 , ' d' },
112
115
{" help" , 0 , 0 , ' h' },
113
116
{" limit" , required_argument, 0 , ' m' },
@@ -116,11 +119,14 @@ int main(int argc, char* argv[]) {
116
119
{" processes" , 0 , 0 , ' P' },
117
120
{0 , 0 , 0 , 0 },
118
121
};
119
- c = getopt_long (argc, argv, " d :hm:n:Ps:" , longopts, NULL );
122
+ c = getopt_long (argc, argv, " ad :hm:n:Ps:" , longopts, NULL );
120
123
if (c < 0 ) {
121
124
break ;
122
125
}
123
126
switch (c) {
127
+ case ' a' :
128
+ accumulated = true ;
129
+ break ;
124
130
case ' d' :
125
131
delay = atoi (optarg );
126
132
break ;
@@ -213,8 +219,13 @@ int main(int argc, char* argv[]) {
213
219
if (!second) {
214
220
printf (" \n " );
215
221
}
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
+ }
218
229
printf (" %6s %-16s %6s %6s %6s %-5s %-5s %-5s %-5s %-5s\n " ,
219
230
" PID" ,
220
231
" Command" ,
@@ -227,20 +238,35 @@ int main(int argc, char* argv[]) {
227
238
" mem" ,
228
239
" total" );
229
240
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 ;
230
245
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
+ }
243
264
}
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
+
244
270
second = false ;
245
271
246
272
if (cycles > 0 && --cycles == 0 ) break ;
0 commit comments