Skip to content

Commit 86bb11f

Browse files
author
Rob Egan
committed
added -q quiet flag
1 parent 96dfdd9 commit 86bb11f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

memtimepro.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int main (int argc, char *argv[] )
6464
pid_t kid;
6565
int kid_status;
6666
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;
6868
long sample_time=0, time = 0, track_time = 0;
6969
char *jsonOutput = 0;
7070

@@ -82,12 +82,12 @@ int main (int argc, char *argv[] )
8282
tmp = (tmp ? tmp + 1 : argv[0]);
8383

8484
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",
8686
tmp,tmp);
8787
exit(EXIT_FAILURE);
8888
}
8989

90-
while ((opt = getopt(argc, argv, "+eo:t:m:c:")) != -1) {
90+
while ((opt = getopt(argc, argv, "+eqo:t:m:c:")) != -1) {
9191

9292
switch (opt) {
9393
case 'o' :
@@ -98,6 +98,10 @@ int main (int argc, char *argv[] )
9898
echo_args = 1;
9999
break;
100100

101+
case 'q' :
102+
quiet = 1;
103+
break;
104+
101105
case 't' :
102106
errno = 0;
103107
sample_time = strtol(optarg, NULL, 0);
@@ -128,7 +132,7 @@ int main (int argc, char *argv[] )
128132
}
129133
}
130134

131-
if (echo_args) {
135+
if (echo_args && quiet == 0) {
132136
fprintf(stderr,"Command line: ");
133137
for (i = optind; i < argc; i++)
134138
fprintf(stderr,"%s ", argv[i]);
@@ -179,7 +183,8 @@ int main (int argc, char *argv[] )
179183
time++;
180184
if (time == 10 * sample_time) {
181185

182-
fprintf(stderr,"%.2f user, %.2f system, %.2f elapsed"
186+
if (quiet == 0)
187+
fprintf(stderr,"%.2f user, %.2f system, %.2f elapsed"
183188
" -- VSize = %ldKB, RSS = %ldKB\n",
184189
(double)info.utime_ms/1000.0,
185190
(double)info.stime_ms/1000.0,
@@ -202,7 +207,7 @@ int main (int argc, char *argv[] )
202207
#endif
203208
}
204209

205-
if (usleep(USLEEP_USECS) != 0)
210+
if (usleep(USLEEP_USECS) != 0 && quiet == 0)
206211
fprintf(stderr, "Could not usleep(USLEEP_USECS)\n");
207212

208213
exit_flag = ((wait4(kid, &kid_status, WNOHANG, &kid_usage) == kid)
@@ -213,10 +218,12 @@ int main (int argc, char *argv[] )
213218
info_tracker.set_end(final_info);
214219

215220
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));
217223
exit_status += WEXITSTATUS(kid_status);
218224
} else {
219-
fprintf(stderr, "Killed [%d]\n", WTERMSIG(kid_status));
225+
if (quiet == 0)
226+
fprintf(stderr, "Killed [%d]\n", WTERMSIG(kid_status));
220227
exit_status += WTERMSIG(kid_status);
221228
}
222229

@@ -228,7 +235,8 @@ int main (int argc, char *argv[] )
228235

229236
info_tracker.set_times(kid_utime * 1000.0, kid_stime * 1000.0);
230237

231-
fprintf(stderr, "%.2f user, %.2f system, %.2f elapsed -- "
238+
if (quiet == 0)
239+
fprintf(stderr, "%.2f user, %.2f system, %.2f elapsed -- "
232240
"Max VSize = %ldKB, Max RSS = %ldKB\n",
233241
kid_utime, kid_stime, (double)(final_info.get_walltime_ms()) / 1000.0,
234242
info_tracker.get_max_vmem(), info_tracker.get_max_rss());

0 commit comments

Comments
 (0)