@@ -146,6 +146,7 @@ typedef struct {
146
146
unsigned long numthreads ;
147
147
unsigned long threads_running ;
148
148
unsigned long skip ;
149
+ unsigned long count ;
149
150
unsigned long delayedspinup_interval ; /* use a random delay until the queue gets filled for the first time.
150
151
the top value in ms can be supplied via a command line switch.
151
152
this option makes only sense if the interval is somewhat smaller than the
@@ -371,13 +372,15 @@ static int syntax(void) {
371
372
"until EOF is received. we call this 'pipe mode'.\n"
372
373
"\n"
373
374
"available options:\n\n"
374
- "-skip N -threads N -resume -statefile=/tmp/state -delayedflush\n"
375
+ "-skip N -count N - threads N -resume -statefile=/tmp/state -delayedflush\n"
375
376
"-delayedspinup N -buffered -joinoutput -limits mem=16M,cpu=10\n"
376
377
"-eof=XXX\n"
377
378
"-exec ./mycommand {}\n"
378
379
"\n"
379
380
"-skip N\n"
380
381
" N=number of entries to skip\n"
382
+ "-count N\n"
383
+ " N=only process count lines (after skipping)\n"
381
384
"-threads N (alternative: -j N)\n"
382
385
" N=number of parallel processes to spawn\n"
383
386
"-resume\n"
@@ -453,6 +456,7 @@ static int parse_args(unsigned argc, char** argv) {
453
456
{"statefile" , 0 , 's' , .dest .s = & prog_state .statefile },
454
457
{"eof" , 0 , 's' , .dest .s = & prog_state .eof_marker },
455
458
{"skip" , 0 , 'i' , .dest .i = & prog_state .skip },
459
+ {"count" , 0 , 'i' , .dest .i = & prog_state .count },
456
460
{"resume" , 0 , 'b' , .dest .b = & resume },
457
461
{"delayedflush" , 0 , 'b' , .dest .b = & prog_state .delayedflush },
458
462
{"delayedspinup" , 0 , 'i' , .dest .i = & prog_state .delayedspinup_interval },
@@ -463,6 +467,7 @@ static int parse_args(unsigned argc, char** argv) {
463
467
};
464
468
465
469
prog_state .numthreads = 1 ;
470
+ prog_state .count = -1UL ;
466
471
467
472
for (i = 1 ; i < argc ; ++ i ) {
468
473
char * p = argv [i ], * q = strchr (p , '=' );
@@ -671,7 +676,8 @@ static char* mystrnrchr_chk(const char *in, int ch, size_t end) {
671
676
}
672
677
673
678
static int need_linecounter (void ) {
674
- return !!prog_state .skip || prog_state .statefile || prog_state .use_seqnr ;
679
+ return !!prog_state .skip || prog_state .statefile ||
680
+ prog_state .use_seqnr || prog_state .count != -1UL ;
675
681
}
676
682
static size_t count_linefeeds (const char * buf , size_t len ) {
677
683
const char * p = buf , * e = buf + len ;
@@ -723,7 +729,11 @@ static int dispatch_line(char* inbuf, size_t len, char** argv) {
723
729
}
724
730
if (!len ) return 1 ;
725
731
}
732
+ } else if (prog_state .count != -1UL ) {
733
+ if (!prog_state .count ) return -1 ;
734
+ -- prog_state .count ;
726
735
}
736
+
727
737
if (!prog_state .cmd_startarg ) {
728
738
write_all (1 , inbuf , len );
729
739
return 1 ;
0 commit comments