summaryrefslogtreecommitdiffstats
path: root/runtime/tests/agg/stats.c
blob: 58fb9d4162c4ae5840eb9c723e1c8bf3c8fb9426 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "runtime.h"

/* test of Stats */
#include "stat.c"

int main ()
{
  int i;
  struct stat_data *st;
  Stat st1 = _stp_stat_init(HIST_NONE);
  Stat st2 = _stp_stat_init(HIST_LOG, 7);
  Stat st3 = _stp_stat_init(HIST_LINEAR, 0, 100, 5);
  
  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    _stp_stat_add (st1, _processor_number + 1);
    _stp_stat_add (st2, _processor_number + 10);
    _stp_stat_add (st3, _processor_number + 100);
  }
  _processor_number = 0;

  /* this is for internal testing only.  Not recommended */
  for (i = 0; i < NR_CPUS; i++) {
    st = _stp_stat_get_cpu(st1, i);
    printf ("st1[%d] = count: %lld  sum:%lld\n", i, st->count, st->sum);
    STAT_UNLOCK(st1);
    st = _stp_stat_get_cpu(st2, i);
    printf ("st2[%d] = count: %lld  sum:%lld\n", i, st->count, st->sum);
    STAT_UNLOCK(st2);
    st = _stp_stat_get_cpu(st3, i);
    printf ("st3[%d] = count: %lld  sum:%lld\n", i, st->count, st->sum);
    STAT_UNLOCK(st3);
  }
  _stp_printf ("--------------------\n");

  /* normal way to print per-cpu stats */
  _stp_stat_print_cpu (st1, "CPU: %c\tCount: %C\tSum: %S", 0);
  _stp_stat_print_cpu (st2, "CPU: %c\tCount: %C\tSum: %S", 0);
  _stp_stat_print_cpu (st3, "CPU: %c\tCount: %C\tSum: %S", 0);
  printf ("--------------------\n");

  /* basic aggregated stats */
  _stp_stat_print (st1, "Count: %C\tSum: %S", 0);
  _stp_stat_print (st2, "Count: %C\tSum: %S", 0);
  _stp_stat_print (st3, "Count: %C\tSum: %S", 0);
  printf ("--------------------\n");

  /* now print full stats */
  _stp_stat_print (st1, "count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H", 1);
  _stp_stat_print (st2, "count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H", 1);
  _stp_stat_print (st3, "count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H", 1);

  /* and print again, after they were cleared */
  _stp_stat_print (st1, "count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H", 1);
  _stp_stat_print (st2, "count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H", 1);
  _stp_stat_print (st3, "count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H", 1);

  _stp_print_flush();
  _stp_stat_del(st1);
  _stp_stat_del(st2);
  _stp_stat_del(st3);
  return 0;
}