@@ -64,7 +64,7 @@ int main (int argc, char *argv[] )
64
64
pid_t kid;
65
65
int kid_status;
66
66
int exit_status = EXIT_SUCCESS;
67
- int i, opt, echo_args = 0 , exit_flag;
67
+ int i, opt, echo_args = 0 , quiet = 0 , exit_flag;
68
68
long sample_time=0 , time = 0 , track_time = 0 ;
69
69
char *jsonOutput = 0 ;
70
70
@@ -82,12 +82,12 @@ int main (int argc, char *argv[] )
82
82
tmp = (tmp ? tmp + 1 : argv[0 ]);
83
83
84
84
fprintf (stderr,
85
- " %s: usage %s [ -o JSON_output_file ] [-t <interval>] [-e] [-m <maxkilobytes>] [-c <maxcpuseconds>] <cmd> [<params>]\n " ,
85
+ " %s: usage %s [ -o JSON_output_file ] [-t <interval>] [-q] [- e] [-m <maxkilobytes>] [-c <maxcpuseconds>] <cmd> [<params>]\n " ,
86
86
tmp,tmp);
87
87
exit (EXIT_FAILURE);
88
88
}
89
89
90
- while ((opt = getopt (argc, argv, " +eo :t:m:c:" )) != -1 ) {
90
+ while ((opt = getopt (argc, argv, " +eqo :t:m:c:" )) != -1 ) {
91
91
92
92
switch (opt) {
93
93
case ' o' :
@@ -98,6 +98,10 @@ int main (int argc, char *argv[] )
98
98
echo_args = 1 ;
99
99
break ;
100
100
101
+ case ' q' :
102
+ quiet = 1 ;
103
+ break ;
104
+
101
105
case ' t' :
102
106
errno = 0 ;
103
107
sample_time = strtol (optarg , NULL , 0 );
@@ -128,7 +132,7 @@ int main (int argc, char *argv[] )
128
132
}
129
133
}
130
134
131
- if (echo_args) {
135
+ if (echo_args && quiet == 0 ) {
132
136
fprintf (stderr," Command line: " );
133
137
for (i = optind ; i < argc; i++)
134
138
fprintf (stderr," %s " , argv[i]);
@@ -179,7 +183,8 @@ int main (int argc, char *argv[] )
179
183
time ++;
180
184
if (time == 10 * sample_time) {
181
185
182
- fprintf (stderr," %.2f user, %.2f system, %.2f elapsed"
186
+ if (quiet == 0 )
187
+ fprintf (stderr," %.2f user, %.2f system, %.2f elapsed"
183
188
" -- VSize = %ldKB, RSS = %ldKB\n " ,
184
189
(double )info.utime_ms /1000.0 ,
185
190
(double )info.stime_ms /1000.0 ,
@@ -202,7 +207,7 @@ int main (int argc, char *argv[] )
202
207
#endif
203
208
}
204
209
205
- if (usleep (USLEEP_USECS) != 0 )
210
+ if (usleep (USLEEP_USECS) != 0 && quiet == 0 )
206
211
fprintf (stderr, " Could not usleep(USLEEP_USECS)\n " );
207
212
208
213
exit_flag = ((wait4 (kid, &kid_status, WNOHANG, &kid_usage) == kid)
@@ -213,10 +218,12 @@ int main (int argc, char *argv[] )
213
218
info_tracker.set_end (final_info);
214
219
215
220
if (WIFEXITED (kid_status)) {
216
- fprintf (stderr, " Exit [%d]\n " , WEXITSTATUS (kid_status));
221
+ if (quiet == 0 )
222
+ fprintf (stderr, " Exit [%d]\n " , WEXITSTATUS (kid_status));
217
223
exit_status += WEXITSTATUS (kid_status);
218
224
} else {
219
- fprintf (stderr, " Killed [%d]\n " , WTERMSIG (kid_status));
225
+ if (quiet == 0 )
226
+ fprintf (stderr, " Killed [%d]\n " , WTERMSIG (kid_status));
220
227
exit_status += WTERMSIG (kid_status);
221
228
}
222
229
@@ -228,7 +235,8 @@ int main (int argc, char *argv[] )
228
235
229
236
info_tracker.set_times (kid_utime * 1000.0 , kid_stime * 1000.0 );
230
237
231
- fprintf (stderr, " %.2f user, %.2f system, %.2f elapsed -- "
238
+ if (quiet == 0 )
239
+ fprintf (stderr, " %.2f user, %.2f system, %.2f elapsed -- "
232
240
" Max VSize = %ldKB, Max RSS = %ldKB\n " ,
233
241
kid_utime, kid_stime, (double )(final_info.get_walltime_ms ()) / 1000.0 ,
234
242
info_tracker.get_max_vmem (), info_tracker.get_max_rss ());
0 commit comments