validator.c 14.7 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**@IFILE validator.c  
 *
27
 * SIP parser tester. This uses output
Pekka Pessi's avatar
Pekka Pessi committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>.
 *
 * @date Wed Mar 21 19:12:13 2001 ppessi
 */

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>

#include <sys/types.h>
#include <sys/stat.h>
Martti Mela's avatar
Martti Mela committed
45
#ifndef _WIN32
Pekka Pessi's avatar
Pekka Pessi committed
46
#include <sys/mman.h>
Martti Mela's avatar
Martti Mela committed
47
#endif
Pekka Pessi's avatar
Pekka Pessi committed
48 49
#include <fcntl.h>
#include <unistd.h>
Martti Mela's avatar
Martti Mela committed
50
#include <errno.h>
Pekka Pessi's avatar
Pekka Pessi committed
51

52 53
#include <sofia-sip/su_types.h>
#include <sofia-sip/su_alloc_stat.h>
Pekka Pessi's avatar
Pekka Pessi committed
54

55
#include <sofia-sip/su_time.h>
Pekka Pessi's avatar
Pekka Pessi committed
56

57 58 59
#include <sofia-sip/su_tag.h>
#include <sofia-sip/su_tag_class.h>
#include <sofia-sip/su_tag_io.h>
Pekka Pessi's avatar
Pekka Pessi committed
60

61 62
#include <sofia-sip/sip_tag.h>
#include <sofia-sip/url_tag.h>
Pekka Pessi's avatar
Pekka Pessi committed
63

64 65
#include <sofia-sip/sip.h>
#include <sofia-sip/sip_header.h>
Pekka Pessi's avatar
Pekka Pessi committed
66

67
#include <sofia-sip/msg_buffer.h>
Pekka Pessi's avatar
Pekka Pessi committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

char const *name = "validator";

typedef struct {
  unsigned o_verbose : 1;	/**< Be verbose */
  unsigned o_very_verbose : 1;	/**< Be very verbose */
  unsigned o_requests : 1;	/**< Only requests */
  unsigned o_responses : 1;	/**< Only responses */
  unsigned o_decode : 1;	/**< Only try to decode, 
				   print error if unknown headers */
  unsigned o_print : 1;		/**< Print whole message */
  unsigned o_times : 1;		/**< Generate timing information */
  unsigned o_memstats : 1;	/**< Generate memory statistics */
  unsigned o_histogram : 1;	/**< Generate histograms */
  unsigned o_sipstats : 1;	/**< Generate header statistics  */
  unsigned o_vsipstats : 1;	/**< Generate verbatim header statistics */
  unsigned : 0;
  unsigned o_flags;		/**< Message flags */
} options_t;

typedef struct {
89
  size_t N;
Pekka Pessi's avatar
Pekka Pessi committed
90 91 92 93 94 95 96
  uint32_t bsize;
  double buckets[32768];
} histogram_t;

static
histogram_t *histogram_create(uint64_t max, uint32_t bsize)
{
97
  size_t N = (max + bsize - 1) / bsize;
Pekka Pessi's avatar
Pekka Pessi committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  histogram_t *h = calloc(1, offsetof(histogram_t, buckets[N + 1]));
  if (!h) { perror("calloc"); exit(1); }
  h->N = N, h->bsize = bsize;
  return h;
}

static
double *histogram_update(histogram_t *h, uint32_t n)
{
  if (h->bsize > 1)
    n /= h->bsize;
    
  if (n < h->N)
    return &h->buckets[n];
  else
    return &h->buckets[h->N];
}

static void
histogram_div(histogram_t *h, histogram_t const *n)
{
119
  size_t i;
Pekka Pessi's avatar
Pekka Pessi committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
  assert(h->N == n->N); assert(h->bsize == n->bsize);
  
  for (i = 0; i <= h->N; i++) {
    if (n->buckets[i]) {
      h->buckets[i] /= n->buckets[i];
    }
    else {
      assert(h->buckets[i] == 0);
    }
  }
}

typedef struct {
  uint64_t number;
  uint64_t headers;
  uint64_t payloads;
  uint64_t pl_bytes;
} sipstat_t;

typedef struct {
  sipstat_t req, resp;
  histogram_t *hist_headers;
} sipstats_t;

typedef struct {
  char const *name;
  char const *sep;
  uint64_t  messages;
  uint64_t  bytes;
  uint64_t  errors;
  uint32_t  files;
  double    time;
  options_t options[1];

  /* Statistics */
  histogram_t *hist_msgsize;
  histogram_t *hist_mallocs;
  histogram_t *hist_memsize;
  histogram_t *hist_nheaders;
  sipstats_t   sipstats[1];
  su_home_stat_t hs[1];

  uint64_t     est_fail, est_succ, est_slack;
} context_t;

void usage(void)
{
  fprintf(stderr, 
	  "usage: %s [-vdp]\n", 
	  name);
  exit(2);
}

char *lastpart(char *path)
{
  char *p = strrchr(path, '/');

  if (p) 
    return p + 1;
  else
    return path;
}

183
msg_mclass_t const *mclass = NULL;
Pekka Pessi's avatar
Pekka Pessi committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275

int validate_file(int fd, char const *name, context_t *ctx);
int validate_dump(char *, off_t, context_t *ctx);
int report(context_t const *ctx);
static void memstats(msg_t *, uint32_t msize, context_t *ctx);
static void sipstats(msg_t *, uint32_t msize, sipstats_t *ss, context_t *ctx);

int main(int argc, char *argv[])
{
  context_t ctx[1] =  {{ 0 }};
  options_t *o = ctx->options;

  name = lastpart(argv[0]);  /* Set our name */

  for (; argv[1]; argv++) {
    if (argv[1][0] == 0)
      usage();
    else if (argv[1][0] != '-')
      break;
    else if (argv[1][1] == 0) {
      argv++; break;
    }
    else if (strcmp(argv[1], "-v") == 0) 
      o->o_very_verbose = o->o_verbose, o->o_verbose = 1;
    else if (strcmp(argv[1], "-d") == 0) 
      o->o_decode = 1;		/* Decode only */
    else if (strcmp(argv[1], "-p") == 0) 
      o->o_print = 1;
    else if (strcmp(argv[1], "-q") == 0) 
      o->o_requests = 1;
    else if (strcmp(argv[1], "-Q") == 0) 
      o->o_responses = 1;
    else if (strcmp(argv[1], "-t") == 0) 
      o->o_times = 1;
    else if (strcmp(argv[1], "-m") == 0) 
      o->o_memstats = 1;
    else if (strcmp(argv[1], "-s") == 0) 
      o->o_vsipstats = o->o_sipstats, o->o_sipstats = 1;
    else if (strcmp(argv[1], "-h") == 0) 
      o->o_histogram = 1;
    else
      usage();
  }

  if (o->o_requests && o->o_responses)
    usage();

  if (!mclass)
    mclass = sip_default_mclass();

  if (argv[1]) {
    for (; argv[1]; argv++) {
      int fd = open(argv[1], O_RDONLY, 000);
      if (fd == -1)
	perror(argv[1]), exit(1);
      if (validate_file(fd, argv[1], ctx))
	exit(1);
      close(fd);
    }
  }
  else
    validate_file(0, "", ctx);

  report(ctx);
  
  exit(0);
}


int validate_file(int fd, char const *name, context_t *ctx)
{
  void *p;
  off_t size;
  int retval;

  ctx->name = name;
  if (strlen(name))
    ctx->sep = ": ";
  else
    ctx->sep = "";

  ctx->files++;

  size = lseek(fd, 0, SEEK_END);

  if (size < 1)
    return 0;
  if (size > INT_MAX) {
    fprintf(stderr, "%s%stoo large file to map\n", ctx->name, ctx->sep);
    return -1;
  }

Martti Mela's avatar
Martti Mela committed
276
#ifndef _WIN32
Pekka Pessi's avatar
Pekka Pessi committed
277 278 279 280 281
  p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0L);
  if (p == NULL) {
    perror("mmap");
    return -1;
  }
Martti Mela's avatar
Martti Mela committed
282

Pekka Pessi's avatar
Pekka Pessi committed
283 284 285
  retval = validate_dump(p, size, ctx);
  munmap(p, size);
  return retval;
Martti Mela's avatar
Martti Mela committed
286 287 288 289 290 291 292

#else
  errno = EINVAL;
  perror("mmap not implemented");
  return -1;
#endif    

Pekka Pessi's avatar
Pekka Pessi committed
293 294
}

295
su_inline 
Pekka Pessi's avatar
Pekka Pessi committed
296 297 298 299 300 301 302 303 304 305 306 307
void nul_terminate(char *b, off_t size)
{
  char *end;

  /* NUL-terminate */
  for (end = b + size - 1; end != b; end--)
    if (*end == '\v')
      break;

  *end = '\0';
}

308
su_inline
Pekka Pessi's avatar
Pekka Pessi committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
int search_msg(char **bb, char const *protocol)
{
  int linelen, plen = strlen(protocol);
  char *b = *bb;

  for (;;) {
    if (!b[0])
      return 0;

    if (strncmp(b, protocol, plen) == 0 && b[plen] == ' ')
      return 1;			/* status */

    linelen = strcspn(b, "\r\n");
    
    if (linelen > plen + 1 && 
	b[linelen - plen - 1] == ' ' && 
	strncmp(b + linelen - plen, protocol, plen) == 0)
      return 1;			/* request */

    b += linelen + strspn(b + linelen, "\r\n");
    *bb = b;
  }
}

int validate_dump(char *b, off_t size, context_t *ctx)
{
335
  size_t n = 0, N = 0;
Pekka Pessi's avatar
Pekka Pessi committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
  struct message { 
    char *b;
    int   size;
  } *msgs = NULL;
  uint64_t time0, time1;
  options_t *o = ctx->options;
  int maxsize = 0;

  nul_terminate(b, size);

  /* Split dump file to messages */
  while (search_msg(&b, SIP_VERSION_CURRENT)) {
    int msize = strcspn(b, "\v");
    int linelen = strcspn(b, "\r\n");

    if (o->o_responses &&
	memcmp(b, SIP_VERSION_CURRENT, strlen(SIP_VERSION_CURRENT)) != 0)
      ;
    else if (o->o_requests && 
	memcmp(b, SIP_VERSION_CURRENT, strlen(SIP_VERSION_CURRENT)) == 0)
      ;
    else {
      if (o->o_very_verbose)
359
	printf("message "MOD_ZU": %.*s\n", n, linelen, b);
Pekka Pessi's avatar
Pekka Pessi committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418

      if (n == N) {
	N *= 2; if (n == N) N = 16;
      
	msgs = realloc(msgs, sizeof(*msgs) * N);
	if (msgs == NULL) {
	  perror("realloc");
	  exit(1);
	}
      }
      msgs[n].b = b; msgs[n].size = msize;
      n++;
      
      ctx->bytes += msize;
      
      if (msize > maxsize)
	maxsize = msize;
    }
    
    b += msize; if (*b) *b++ = '\0';
  }

  ctx->messages += N = n;

  if (o->o_histogram) {
    ctx->hist_msgsize = histogram_create(maxsize, 64);

    if (o->o_memstats) {
      ctx->hist_mallocs = histogram_create(maxsize, 64);
      ctx->hist_memsize = histogram_create(maxsize, 64);
    }

    if (o->o_sipstats) {
      ctx->sipstats->hist_headers = histogram_create(64, 1);
      ctx->hist_nheaders = histogram_create(maxsize, 64);
    }
  }

  time0 = su_nanocounter();

  for (n = 0; n < N; n++) {
    msg_t *msg = msg_create(mclass, o->o_flags);
    int m;

    if (msg == NULL) {
      perror("msg_create"); exit(1);
    }

    if (o->o_memstats)
      su_home_init_stats(msg_home(msg));
    
    msg_buf_set(msg, msgs[n].b, msgs[n].size + 1);
    msg_buf_commit(msg, msgs[n].size, 1);
    
    su_home_preload(msg_home(msg), 1, msgs[n].size + 384);

    m = msg_extract(msg);

    if (m < 0) {
419
      fprintf(stderr, "%s%sparsing error in message "MOD_ZU"\n", 
Pekka Pessi's avatar
Pekka Pessi committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
	      ctx->name, ctx->sep, n);
      ctx->errors++;
    }
    else {
      if (ctx->hist_msgsize)
	*histogram_update(ctx->hist_msgsize, msgs[n].size) += 1;

      if (o->o_sipstats)
	sipstats(msg, msgs[n].size, ctx->sipstats, ctx);

      if (o->o_memstats)
	memstats(msg, msgs[n].size, ctx);
    }

    msg_destroy(msg);
  }
  
  time1 = su_nanocounter();

  if (o->o_times) {
    double dur = (time1 - time0) * 1E-9;

    ctx->time += dur;

444
    printf("%s%s"MOD_ZU" messages in %g seconds (%g msg/sec)\n"
Pekka Pessi's avatar
Pekka Pessi committed
445 446 447 448 449 450 451 452 453 454 455
	   "      parse speed %.1f Mb/s (on Ethernet wire %.1f Mb/s)\n",
	   ctx->name, ctx->sep, N, dur, (double)N / dur,
	   (double)ctx->bytes * 8 / ctx->time / 1e6,
	   ((double)ctx->bytes + N * (16 + 20 + 8)) * 8 / ctx->time / 1e6);
  }

  free(msgs);

  return 0;
}

456
typedef unsigned longlong ull;
Pekka Pessi's avatar
Pekka Pessi committed
457 458 459 460 461 462

static
void report_memstats(char const *title, su_home_stat_t const hs[1])
{
  printf("%s%smemory statistics\n", title, strlen(title) ? " " : "");
  if (hs->hs_allocs.hsa_number)
463 464 465 466
    printf("\t"LLU" allocs, "LLU" bytes, "LLU" rounded,"
	   " "LLU" max\n",
	   (ull)hs->hs_allocs.hsa_number, (ull)hs->hs_allocs.hsa_bytes,
	   (ull)hs->hs_allocs.hsa_rbytes, (ull)hs->hs_allocs.hsa_maxrbytes);
Pekka Pessi's avatar
Pekka Pessi committed
467
  if (hs->hs_frees.hsf_number)
468 469 470
    printf("\t"LLU" frees, "LLU" bytes, rounded to "LLU" bytes\n",
	   (ull)hs->hs_frees.hsf_number, (ull)hs->hs_frees.hsf_bytes,
	   (ull)hs->hs_frees.hsf_rbytes);
Pekka Pessi's avatar
Pekka Pessi committed
471
  if (hs->hs_rehash || hs->hs_clones)
472 473
    printf("\t"LLU" rehashes, "LLU" clones\n", 
	   (ull)hs->hs_rehash, (ull)hs->hs_clones);
Pekka Pessi's avatar
Pekka Pessi committed
474 475 476 477 478 479 480
}

void memstats(msg_t *msg, uint32_t msize, context_t *ctx)
{
  options_t *o = ctx->options;
  su_home_stat_t hs[1];

481
  su_home_get_stats(msg_home(msg), 1, hs, sizeof(hs));
Pekka Pessi's avatar
Pekka Pessi committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
  su_home_stat_add(ctx->hs, hs);

  if (o->o_histogram) {
    *histogram_update(ctx->hist_mallocs, msize) += hs->hs_allocs.hsa_number;
    *histogram_update(ctx->hist_memsize, msize) += hs->hs_allocs.hsa_maxrbytes;
  }

  {
    int estimate = msize + 384;
    int slack = estimate - hs->hs_allocs.hsa_maxrbytes;

    if (slack < 0)
      ctx->est_fail++;
    else {
      ctx->est_succ++;
      ctx->est_slack += slack;
    }
  }

  if (o->o_very_verbose)
    report_memstats(ctx->name, hs);
}

void report_sipstat(char const *what, sipstat_t const *sss)
{
507 508 509
  printf("%s: "LLU" with %.1f headers (total "LLU")\n",
	 what, (ull)sss->number, (double)sss->headers / sss->number, 
	 (ull)sss->headers);
Pekka Pessi's avatar
Pekka Pessi committed
510
  if (sss->payloads)
511 512 513
    printf("\t"LLU" with body of %.1f bytes (total "LLU")\n",
	   (ull)sss->payloads, (double)sss->pl_bytes / sss->payloads, 
	   (ull)sss->payloads);
Pekka Pessi's avatar
Pekka Pessi committed
514 515 516 517 518 519 520 521 522
}

void sipstats(msg_t *msg, uint32_t msize, sipstats_t *ss, context_t *ctx)
{
  options_t *o = ctx->options;
  msg_pub_t *m = msg_object(msg);
  sip_t const *sip = sip_object(msg);
  msg_header_t *h;
  sipstat_t *sss;
523
  size_t n, bytes;
Pekka Pessi's avatar
Pekka Pessi committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547

  if (!sip)
    return;

  if (m->msg_request) {
    sss = &ss->req;
    h = m->msg_request;
  }
  else if (m->msg_status) {
    sss = &ss->resp;
    h = m->msg_status;
  }
  else {
    return;
  }

  sss->number++;

  /* Count headers */
  for (n = 0, h = h->sh_succ; h && !sip_is_separator((sip_header_t *)h); h = h->sh_succ) 
    n++;

  sss->headers += n;

548
  bytes = sip->sip_payload ? (size_t)sip->sip_payload->pl_len : 0;
Pekka Pessi's avatar
Pekka Pessi committed
549 550 551 552 553 554 555 556 557 558 559 560

  if (bytes) {
    sss->payloads++;
    sss->pl_bytes += bytes;
  }

  if (ctx->hist_nheaders) {
    *histogram_update(ctx->hist_nheaders, msize) += n;
    *histogram_update(ss->hist_headers, n) += 1;
  }

  if (o->o_very_verbose)
561
    printf("%s%s"MOD_ZU" headers, "MOD_ZU" bytes in payload\n",
Pekka Pessi's avatar
Pekka Pessi committed
562 563 564 565 566
	   ctx->name, ctx->sep, n, bytes);
}

void report_histogram(char const *title, histogram_t const *h)
{
567
  size_t i, min_i, max_i;
Pekka Pessi's avatar
Pekka Pessi committed
568

569
  for (i = 0; i < h->N && h->buckets[i] == 0.0; i++)
Pekka Pessi's avatar
Pekka Pessi committed
570 571 572
    ;
  min_i = i;

573
  for (i = h->N - 1; i >= 0 && h->buckets[i] == 0.0; i--)
Pekka Pessi's avatar
Pekka Pessi committed
574 575 576 577 578 579 580 581
    ;
  max_i = i;
  
  if (min_i >= max_i)
    return;

  printf("%s histogram\n", title);
  for (i = min_i; i < max_i; i++)
582
    printf("\t"MOD_ZU".."MOD_ZU": %.1f\n", i * h->bsize, (i + 1) * h->bsize, h->buckets[i]);
Pekka Pessi's avatar
Pekka Pessi committed
583 584

  if (h->buckets[h->N])
585
    printf("\t"MOD_ZU"..: %.1f\n", h->N * h->bsize, h->buckets[h->N]);
Pekka Pessi's avatar
Pekka Pessi committed
586 587 588 589
}

int report(context_t const *ctx)
{
590
  const options_t *o = ctx->options;
Pekka Pessi's avatar
Pekka Pessi committed
591 592 593 594 595
  uint64_t n = ctx->messages;

  if (!n)
    return -1;

596 597
  printf("total "LLU" messages with "LLU" bytes (mean size "LLU")\n",
	 (ull)n, (ull)ctx->bytes, (ull)(ctx->bytes / n));
Pekka Pessi's avatar
Pekka Pessi committed
598 599 600 601 602

  if (ctx->hist_msgsize)
    report_histogram("Message size", ctx->hist_msgsize);

  if (o->o_times && ctx->files > 1) 
603 604
    printf("total "LLU" messages in %g seconds (%g msg/sec)\n",
	   (ull)n, ctx->time, (double)n / ctx->time);
Pekka Pessi's avatar
Pekka Pessi committed
605 606

  if (o->o_sipstats) {
607
    const sipstats_t *ss = ctx->sipstats;
Pekka Pessi's avatar
Pekka Pessi committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
    report_sipstat("requests", &ss->req);
    report_sipstat("responses", &ss->resp);

    if (ctx->hist_nheaders) {
      histogram_div(ctx->hist_nheaders, ctx->hist_msgsize);
      report_histogram("Number of headers", ctx->hist_nheaders);
    }
  }

  if (o->o_memstats) {
    su_home_stat_t hs[1];

    *hs = *ctx->hs;
    report_memstats("total", hs);
    
    /* Calculate mean */
    hs->hs_clones /= n; hs->hs_rehash /= n;
    hs->hs_allocs.hsa_number /= n; hs->hs_allocs.hsa_bytes /= n;
    hs->hs_allocs.hsa_rbytes /= n; hs->hs_allocs.hsa_maxrbytes /= n;
    hs->hs_frees.hsf_number /= n; hs->hs_frees.hsf_bytes /= n;
    hs->hs_frees.hsf_rbytes /= n;
    hs->hs_blocks.hsb_number /= n; hs->hs_blocks.hsb_bytes /= n;
    hs->hs_blocks.hsb_rbytes /= n;

    report_memstats("mean", hs);

    printf("\testimator fails %.1f%% times (mean slack %.0f bytes)\n", 
	   100 * (double)ctx->est_fail / (ctx->est_fail + ctx->est_succ),
	   (double)ctx->est_slack / ctx->est_succ);

    if (ctx->hist_memsize) {
      histogram_div(ctx->hist_memsize, ctx->hist_msgsize);
      report_histogram("Allocated memory", ctx->hist_memsize);
    }
  }

  return 0;
}