Skip to content

Commit bb52e71

Browse files
committed
htcacheclean: Report additional statistics about entries deleted.
PR: 48944 Submitted by: Mark Drayton mark markdrayton.info git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@928223 13f79535-47bb-0310-9956-ffa450edef68
1 parent 974a5f4 commit bb52e71

2 files changed

Lines changed: 73 additions & 45 deletions

File tree

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Changes with Apache 2.3.7
2828
processing is completed, avoiding orphaned callback pointers.
2929
[Brett Gervasoni <brettg senseofsecurity.com>, Jeff Trawick]
3030

31+
*) htcacheclean: Report additional statistics about entries deleted.
32+
PR 48944. [Mark Drayton mark markdrayton.info]
33+
3134
*) Introduce SSLFIPS directive to support OpenSSL FIPS_mode; permits all
3235
builds of mod_ssl to use 'SSLFIPS off' for portability, but the proper
3336
build of openssl is required for 'SSLFIPS on'. PR 46270.

support/htcacheclean.c

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ static APR_RING_ENTRY(_entry) root; /* ENTRY ring anchor */
109109
/* short program name as called */
110110
static const char *shortname = "htcacheclean";
111111

112+
/* what did we clean? */
113+
struct stats {
114+
apr_off_t total;
115+
apr_off_t sum;
116+
apr_off_t max;
117+
apr_off_t etotal;
118+
apr_off_t entries;
119+
apr_off_t dfuture;
120+
apr_off_t dexpired;
121+
apr_off_t dfresh;
122+
};
123+
124+
112125
#ifdef DEBUG
113126
/*
114127
* fake delete for debug purposes
@@ -154,8 +167,7 @@ static int oom(int unused)
154167
/*
155168
* print purge statistics
156169
*/
157-
static void printstats(apr_off_t total, apr_off_t sum, apr_off_t max,
158-
apr_off_t etotal, apr_off_t entries)
170+
static void printstats(char *path, struct stats *s)
159171
{
160172
char ttype, stype, mtype, utype;
161173
apr_off_t tfrag, sfrag, ufrag;
@@ -165,31 +177,31 @@ static void printstats(apr_off_t total, apr_off_t sum, apr_off_t max,
165177
}
166178

167179
ttype = 'K';
168-
tfrag = ((total * 10) / KBYTE) % 10;
169-
total /= KBYTE;
170-
if (total >= KBYTE) {
180+
tfrag = ((s->total * 10) / KBYTE) % 10;
181+
s->total /= KBYTE;
182+
if (s->total >= KBYTE) {
171183
ttype = 'M';
172-
tfrag = ((total * 10) / KBYTE) % 10;
173-
total /= KBYTE;
184+
tfrag = ((s->total * 10) / KBYTE) % 10;
185+
s->total /= KBYTE;
174186
}
175187

176188
stype = 'K';
177-
sfrag = ((sum * 10) / KBYTE) % 10;
178-
sum /= KBYTE;
179-
if (sum >= KBYTE) {
189+
sfrag = ((s->sum * 10) / KBYTE) % 10;
190+
s->sum /= KBYTE;
191+
if (s->sum >= KBYTE) {
180192
stype = 'M';
181-
sfrag = ((sum * 10) / KBYTE) % 10;
182-
sum /= KBYTE;
193+
sfrag = ((s->sum * 10) / KBYTE) % 10;
194+
s->sum /= KBYTE;
183195
}
184196

185197
mtype = 'K';
186-
max /= KBYTE;
187-
if (max >= KBYTE) {
198+
s->max /= KBYTE;
199+
if (s->max >= KBYTE) {
188200
mtype = 'M';
189-
max /= KBYTE;
201+
s->max /= KBYTE;
190202
}
191203

192-
apr_file_printf(errfile, "Statistics:" APR_EOL_STR);
204+
apr_file_printf(errfile, "Cleaned %s. Statistics:" APR_EOL_STR, path);
193205
if (unsolicited) {
194206
utype = 'K';
195207
ufrag = ((unsolicited * 10) / KBYTE) % 10;
@@ -206,13 +218,18 @@ static void printstats(apr_off_t total, apr_off_t sum, apr_off_t max,
206218
(int)(unsolicited), (int)(ufrag), utype);
207219
}
208220
apr_file_printf(errfile, "size limit %d.0%c" APR_EOL_STR,
209-
(int)(max), mtype);
221+
(int)(s->max), mtype);
210222
apr_file_printf(errfile, "total size was %d.%d%c, total size now "
211223
"%d.%d%c" APR_EOL_STR,
212-
(int)(total), (int)(tfrag), ttype, (int)(sum),
213-
(int)(sfrag), stype);
224+
(int)(s->total), (int)(tfrag), ttype,
225+
(int)(s->sum), (int)(sfrag), stype);
214226
apr_file_printf(errfile, "total entries was %d, total entries now %d"
215-
APR_EOL_STR, (int)(etotal), (int)(entries));
227+
APR_EOL_STR, (int)(s->etotal),
228+
(int)(s->entries));
229+
apr_file_printf(errfile, "%d entries deleted (%d from future, %d "
230+
"expired, %d fresh)" APR_EOL_STR,
231+
(int)(s->etotal - s->entries), (int)(s->dfuture),
232+
(int)(s->dexpired), (int)(s->dfresh));
216233
}
217234

218235
/*
@@ -596,25 +613,29 @@ static int process_dir(char *path, apr_pool_t *pool)
596613
*/
597614
static void purge(char *path, apr_pool_t *pool, apr_off_t max)
598615
{
599-
apr_off_t sum, total, entries, etotal;
600616
ENTRY *e, *n, *oldest;
601617

602-
sum = 0;
603-
entries = 0;
618+
struct stats s;
619+
s.sum = 0;
620+
s.entries = 0;
621+
s.dfuture = 0;
622+
s.dexpired = 0;
623+
s.dfresh = 0;
624+
s.max = max;
604625

605626
for (e = APR_RING_FIRST(&root);
606627
e != APR_RING_SENTINEL(&root, _entry, link);
607628
e = APR_RING_NEXT(e, link)) {
608-
sum += e->hsize;
609-
sum += e->dsize;
610-
entries++;
629+
s.sum += e->hsize;
630+
s.sum += e->dsize;
631+
s.entries++;
611632
}
612633

613-
total = sum;
614-
etotal = entries;
634+
s.total = s.sum;
635+
s.etotal = s.entries;
615636

616-
if (sum <= max) {
617-
printstats(total, sum, max, etotal, entries);
637+
if (s.sum <= s.max) {
638+
printstats(path, &s);
618639
return;
619640
}
620641

@@ -627,13 +648,14 @@ static void purge(char *path, apr_pool_t *pool, apr_off_t max)
627648
n = APR_RING_NEXT(e, link);
628649
if (e->response_time > now || e->htime > now || e->dtime > now) {
629650
delete_entry(path, e->basename, pool);
630-
sum -= e->hsize;
631-
sum -= e->dsize;
632-
entries--;
651+
s.sum -= e->hsize;
652+
s.sum -= e->dsize;
653+
s.entries--;
654+
s.dfuture++;
633655
APR_RING_REMOVE(e, link);
634-
if (sum <= max) {
656+
if (s.sum <= s.max) {
635657
if (!interrupted) {
636-
printstats(total, sum, max, etotal, entries);
658+
printstats(path, &s);
637659
}
638660
return;
639661
}
@@ -651,13 +673,14 @@ static void purge(char *path, apr_pool_t *pool, apr_off_t max)
651673
n = APR_RING_NEXT(e, link);
652674
if (e->expire != APR_DATE_BAD && e->expire < now) {
653675
delete_entry(path, e->basename, pool);
654-
sum -= e->hsize;
655-
sum -= e->dsize;
656-
entries--;
676+
s.sum -= e->hsize;
677+
s.sum -= e->dsize;
678+
s.entries--;
679+
s.dexpired++;
657680
APR_RING_REMOVE(e, link);
658-
if (sum <= max) {
681+
if (s.sum <= s.max) {
659682
if (!interrupted) {
660-
printstats(total, sum, max, etotal, entries);
683+
printstats(path, &s);
661684
}
662685
return;
663686
}
@@ -674,7 +697,8 @@ static void purge(char *path, apr_pool_t *pool, apr_off_t max)
674697
* corrupt 64bit arithmetics which happend to me once, so better safe
675698
* than sorry
676699
*/
677-
while (sum > max && !interrupted && !APR_RING_EMPTY(&root, _entry, link)) {
700+
while (s.sum > s.max && !interrupted
701+
&& !APR_RING_EMPTY(&root, _entry, link)) {
678702
oldest = APR_RING_FIRST(&root);
679703

680704
for (e = APR_RING_NEXT(oldest, link);
@@ -686,14 +710,15 @@ static void purge(char *path, apr_pool_t *pool, apr_off_t max)
686710
}
687711

688712
delete_entry(path, oldest->basename, pool);
689-
sum -= oldest->hsize;
690-
sum -= oldest->dsize;
691-
entries--;
713+
s.sum -= oldest->hsize;
714+
s.sum -= oldest->dsize;
715+
s.entries--;
716+
s.dfresh++;
692717
APR_RING_REMOVE(oldest, link);
693718
}
694719

695720
if (!interrupted) {
696-
printstats(total, sum, max, etotal, entries);
721+
printstats(path, &s);
697722
}
698723
}
699724

0 commit comments

Comments
 (0)