![heil](/assets/img/avatar_default.png)
- add missing patches - add patch number to version git-svn-id: svn://svn.openwrt.org/openwrt/packages@35091 3c298f89-4303-0410-b956-a3cf2f4a3e73
135 lines
4.3 KiB
Diff
135 lines
4.3 KiB
Diff
From 9f03ab8e3ec603f2aed944a7887bcdf7be52009a Mon Sep 17 00:00:00 2001
|
|
From: Willy Tarreau <w@1wt.eu>
|
|
Date: Wed, 10 Oct 2012 16:49:28 +0200
|
|
Subject: MINOR: halog: add a parameter to limit output line count
|
|
|
|
Sometimes it's useful to limit the output to a number of lines, for
|
|
example when output is already sorted (eg: 10 slowest URLs, ...). Now
|
|
we can use -m for this.
|
|
(cherry picked from commit 667c905fe5153a8754bd8177c80dd9e6c245a0b0)
|
|
[ this patch introduces a but that is fixed by commit a1629a59 ]
|
|
---
|
|
contrib/halog/halog.c | 28 ++++++++++++++++++++++++----
|
|
1 files changed, 24 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/contrib/halog/halog.c b/contrib/halog/halog.c
|
|
index 3912807..7e16cd5 100644
|
|
--- a/contrib/halog/halog.c
|
|
+++ b/contrib/halog/halog.c
|
|
@@ -121,6 +121,7 @@ const char *line;
|
|
int linenum = 0;
|
|
int parse_err = 0;
|
|
int lines_out = 0;
|
|
+int lines_max = -1;
|
|
|
|
const char *fgets2(FILE *stream);
|
|
|
|
@@ -138,7 +139,7 @@ void usage(FILE *output, const char *msg)
|
|
fprintf(output,
|
|
"%s"
|
|
"Usage: halog [-h|--help] for long help\n"
|
|
- " halog [-q] [-c]\n"
|
|
+ " halog [-q] [-c] [-m <lines>]\n"
|
|
" {-cc|-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt}\n"
|
|
" [-s <skip>] [-e|-E] [-H] [-rt|-RT <time>] [-ad <delay>] [-ac <count>]\n"
|
|
" [-v] [-Q|-QS] [-tcn|-TCN <termcode>] [ -hs|-HS [min][:[max]] ] < log\n"
|
|
@@ -170,7 +171,7 @@ void help()
|
|
"Modifiers\n"
|
|
" -v invert the input filtering condition\n"
|
|
" -q don't report errors/warnings\n"
|
|
- "\n"
|
|
+ " -m <lines> limit output to the first <lines> lines\n"
|
|
"Output filters - only one may be used at a time\n"
|
|
" -c only report the number of lines that would have been printed\n"
|
|
" -pct output connect and response times percentiles\n"
|
|
@@ -575,6 +576,11 @@ int main(int argc, char **argv)
|
|
argc--; argv++;
|
|
skip_fields = atol(*argv);
|
|
}
|
|
+ else if (strcmp(argv[0], "-m") == 0) {
|
|
+ if (argc < 2) die("missing option for -m");
|
|
+ argc--; argv++;
|
|
+ lines_max = atol(*argv);
|
|
+ }
|
|
else if (strcmp(argv[0], "-e") == 0)
|
|
filter |= FILT_ERRORS_ONLY;
|
|
else if (strcmp(argv[0], "-E") == 0)
|
|
@@ -702,7 +708,7 @@ int main(int argc, char **argv)
|
|
posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL);
|
|
#endif
|
|
|
|
- if (!line_filter &&
|
|
+ if (!line_filter && lines_max >= 0 &&
|
|
!(filter & (FILT_HTTP_ONLY|FILT_TIME_RESP|FILT_ERRORS_ONLY|FILT_HTTP_STATUS|FILT_QUEUE_ONLY|FILT_QUEUE_SRV_ONLY|FILT_TERM_CODE_NAME))) {
|
|
/* read the whole file at once first */
|
|
if (!filter_invert)
|
|
@@ -867,6 +873,8 @@ int main(int argc, char **argv)
|
|
line_filter(accept_field, time_field, &t);
|
|
else
|
|
lines_out++; /* we're just counting lines */
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
}
|
|
|
|
skip_filters:
|
|
@@ -904,8 +912,10 @@ int main(int argc, char **argv)
|
|
ms = h % 1000; h = h / 1000;
|
|
s = h % 60; h = h / 60;
|
|
m = h % 60; h = h / 60;
|
|
- lines_out++;
|
|
printf("%02d:%02d:%02d.%03d %d %d %d\n", h, m, s, ms, last, d, t->count);
|
|
+ lines_out++;
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
}
|
|
n = eb32_next(n);
|
|
}
|
|
@@ -937,6 +947,8 @@ int main(int argc, char **argv)
|
|
if (d > 0.0) {
|
|
printf("%d %d %f\n", f, last, d+1.0);
|
|
lines_out++;
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
}
|
|
|
|
n = eb32_next(n);
|
|
@@ -994,6 +1006,8 @@ int main(int argc, char **argv)
|
|
t = container_of(n, struct timer, node);
|
|
printf("%d %d\n", n->key, t->count);
|
|
lines_out++;
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
n = eb32_next(n);
|
|
}
|
|
}
|
|
@@ -1021,6 +1035,8 @@ int main(int argc, char **argv)
|
|
(int)(srv->cum_ct / (srv->nb_ct?srv->nb_ct:1)), (int)(srv->cum_rt / (srv->nb_rt?srv->nb_rt:1)));
|
|
srv_node = ebmb_next(srv_node);
|
|
lines_out++;
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
}
|
|
}
|
|
else if (filter & (FILT_COUNT_TERM_CODES|FILT_COUNT_COOK_CODES)) {
|
|
@@ -1030,6 +1046,8 @@ int main(int argc, char **argv)
|
|
t = container_of(n, struct timer, node);
|
|
printf("%c%c %d\n", (n->key >> 8), (n->key) & 255, t->count);
|
|
lines_out++;
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
n = eb32_next(n);
|
|
}
|
|
}
|
|
@@ -1092,6 +1110,8 @@ int main(int argc, char **argv)
|
|
|
|
node = eb_prev(node);
|
|
lines_out++;
|
|
+ if (lines_out >= lines_max)
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
--
|
|
1.7.1
|
|
|