Commit 24b971bf authored by Geoff Simmons's avatar Geoff Simmons

Add the in statistic -- input bytes processed by the de-/compressor.

parent 8a5c0740
......@@ -18,4 +18,10 @@
Total number of bytes output by the de-/compressor
.. varnish_vsc:: in
:type: counter
:oneliner: Input bytes
Total number of input bytes processed by the de-/compressor
.. varnish_vsc_end:: brotli
......@@ -36,8 +36,10 @@ client c1 -run
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.br.in > 0
varnish v1 -expect BROTLI.br.out > 0
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.unbr.in > 0
varnish v1 -expect BROTLI.unbr.out > 0
varnish v1 -vcl+backend {
......@@ -61,8 +63,10 @@ varnish v1 -cliok "vcl.list"
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.br.in > 0
varnish v1 -expect BROTLI.br.out > 0
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.unbr.in > 0
varnish v1 -expect BROTLI.unbr.out > 0
server s1 -wait
......@@ -71,12 +75,16 @@ client c1 -run
varnish v1 -vsc BROTLI.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.br.in > 0
varnish v1 -expect BROTLI.br.out > 0
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.unbr.in > 0
varnish v1 -expect BROTLI.unbr.out > 0
varnish v1 -expect BROTLI.vcl2.mybr.ops == 10
varnish v1 -expect BROTLI.vcl2.mybr.in > 0
varnish v1 -expect BROTLI.vcl2.mybr.out > 0
varnish v1 -expect BROTLI.vcl2.myunbr.ops == 10
varnish v1 -expect BROTLI.vcl2.myunbr.in > 0
varnish v1 -expect BROTLI.vcl2.myunbr.out > 0
varnish v1 -vcl+backend {}
......@@ -87,20 +95,26 @@ varnish v1 -cliok "vcl.state vcl2 cold"
# This has to be checked manually in the log.
varnish v1 -vsc BROTLI.vcl2.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.br.in > 0
varnish v1 -expect BROTLI.br.out > 0
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.unbr.in > 0
varnish v1 -expect BROTLI.unbr.out > 0
varnish v1 -cliok "vcl.state vcl2 warm"
# With vcl2 back in the warm state, stats for vcl2.* appear again.
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.br.in > 0
varnish v1 -expect BROTLI.br.out > 0
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.unbr.in > 0
varnish v1 -expect BROTLI.unbr.out > 0
varnish v1 -expect BROTLI.vcl2.mybr.ops == 10
varnish v1 -expect BROTLI.vcl2.mybr.in > 0
varnish v1 -expect BROTLI.vcl2.mybr.out > 0
varnish v1 -expect BROTLI.vcl2.myunbr.ops == 10
varnish v1 -expect BROTLI.vcl2.myunbr.in > 0
varnish v1 -expect BROTLI.vcl2.myunbr.out > 0
varnish v1 -cliok "vcl.state vcl2 cold"
......@@ -109,6 +123,8 @@ varnish v1 -cliok "vcl.list"
varnish v1 -vsc BROTLI.vcl2.*
varnish v1 -expect BROTLI.br.ops == 10
varnish v1 -expect BROTLI.br.in > 0
varnish v1 -expect BROTLI.br.out > 0
varnish v1 -expect BROTLI.unbr.ops == 10
varnish v1 -expect BROTLI.unbr.in > 0
varnish v1 -expect BROTLI.unbr.out > 0
......@@ -246,15 +246,17 @@ setOutputBuf(struct vbr *vbr, const void *ptr, ssize_t len)
}
static BROTLI_BOOL
encode(struct vbr *vbr, ssize_t *dl, int finished)
encode(struct vbr *vbr, ssize_t *dl, int finished, struct VSC_brotli *stats)
{
BROTLI_BOOL ret;
const uint8_t *before;
size_t inb4;
enum BrotliEncoderOperation op = BROTLI_OPERATION_PROCESS;
CHECK_OBJ_NOTNULL(vbr, VBR_MAGIC);
assert(vbr->which == ENC);
before = vbr->stream.next_out;
inb4 = vbr->stream.avail_in;
if (finished)
op = BROTLI_OPERATION_FINISH;
......@@ -265,18 +267,24 @@ encode(struct vbr *vbr, ssize_t *dl, int finished)
&vbr->stream.next_out,
&vbr->stream.total_out);
*dl = (const uint8_t *)vbr->stream.next_out - before;
if (stats != NULL) {
assert(inb4 >= vbr->stream.avail_in);
stats->in += (inb4 - vbr->stream.avail_in);
}
return (ret);
}
static BrotliDecoderResult
decode(struct vbr *vbr, ssize_t *dl)
decode(struct vbr *vbr, ssize_t *dl, struct VSC_brotli *stats)
{
BrotliDecoderResult ret;
const uint8_t *before;
size_t inb4;
CHECK_OBJ_NOTNULL(vbr, VBR_MAGIC);
assert(vbr->which == DEC);
before = vbr->stream.next_out;
inb4 = vbr->stream.avail_in;
ret = BrotliDecoderDecompressStream(vbr->state.dec,
&vbr->stream.avail_in,
......@@ -285,6 +293,10 @@ decode(struct vbr *vbr, ssize_t *dl)
&vbr->stream.next_out,
&vbr->stream.total_out);
*dl = (const uint8_t *)vbr->stream.next_out - before;
if (stats != NULL) {
assert(inb4 >= vbr->stream.avail_in);
stats->in += (inb4 - vbr->stream.avail_in);
}
return (ret);
}
......@@ -380,10 +392,13 @@ vfp_br_pull(struct vfp_ctx *ctx, struct vfp_entry *ent, void *ptr,
enum vfp_status vp = VFP_ERROR;
int finished = 0;
BROTLI_BOOL done;
const struct vfp_priv *priv;
CHECK_OBJ_NOTNULL(ctx, VFP_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ent, VFP_ENTRY_MAGIC);
CAST_OBJ_NOTNULL(vbr, ent->priv1, VBR_MAGIC);
AN(ent->vfp);
CAST_OBJ_NOTNULL(priv, ent->vfp->priv1, VFP_PRIV_MAGIC);
assert(vbr->which == ENC);
AN(ptr);
AN(lenp);
......@@ -403,7 +418,7 @@ vfp_br_pull(struct vfp_ctx *ctx, struct vfp_entry *ent, void *ptr,
setInputBuf(vbr, vbr->buf, len);
}
if (!isInputBufEmpty(vbr) || finished) {
done = encode(vbr, &dl, finished);
done = encode(vbr, &dl, finished, priv->stats);
if (done != BROTLI_TRUE)
return (VFP_Error(ctx, "brotli encode failed"));
if (dl > 0) {
......@@ -429,10 +444,13 @@ vfp_unbr_pull(struct vfp_ctx *ctx, struct vfp_entry *ent, void *ptr,
ssize_t len, dl;
enum vfp_status vp = VFP_ERROR;
BrotliDecoderResult result = BROTLI_DECODER_RESULT_ERROR;
const struct vfp_priv *priv;
CHECK_OBJ_NOTNULL(ctx, VFP_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ent, VFP_ENTRY_MAGIC);
CAST_OBJ_NOTNULL(vbr, ent->priv1, VBR_MAGIC);
AN(ent->vfp);
CAST_OBJ_NOTNULL(priv, ent->vfp->priv1, VFP_PRIV_MAGIC);
assert(vbr->which == DEC);
AN(ptr);
AN(lenp);
......@@ -450,7 +468,7 @@ vfp_unbr_pull(struct vfp_ctx *ctx, struct vfp_entry *ent, void *ptr,
setInputBuf(vbr, vbr->buf, len);
}
if (!isInputBufEmpty(vbr) || vp == VFP_END) {
result = decode(vbr, &dl);
result = decode(vbr, &dl, priv->stats);
if (result == BROTLI_DECODER_RESULT_SUCCESS &&
!isInputBufEmpty(vbr))
return(VFP_Error(ctx,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment