summaryrefslogtreecommitdiffstats
path: root/runtime/tests/pmaps/ix2.c
blob: 638e5226173f5d03410676e04a92a50353a43b06 (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
63
64
#include "runtime.h"

/* test of pmaps with keys of int64 and value of stat */

#define VALUE_TYPE STAT
#define KEY1_TYPE INT64
#include "pmap-gen.c"

#include "map.c"

int main ()
{
  PMAP map = _stp_pmap_new_ix(4, HIST_LINEAR, 0, 100, 10);
  int i;

  /* put some data in. _processor_number is a global hack that allows */
  /* us to set the current emulated cpu number for our userspace tests. */
  /* Note that we set values based on the cpu number just to show that */
  /* different values are stored in each cpu */
  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    _stp_pmap_add_ix(map, 1, _processor_number);
    _stp_pmap_add_ix(map, 2, 10 *_processor_number + 1);
    _stp_pmap_add_ix(map, 3, _processor_number * _processor_number);
    _stp_pmap_add_ix(map, 4, 1);
  }
  
  /* now print the per-cpu data */
  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++) {
    printf("CPU #%d\n", _processor_number);
    _stp_pmap_printn_cpu (map, 
			  0, 
			  "map[%1d] = count:%C  sum:%S  avg:%A  min:%m  max:%M", 
			  _processor_number);
  }  
  _processor_number = 0;

  /* print the aggregated data */
  _stp_pmap_print(map,"map[%1d] = count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H");

  /* now use GET */
  for (i = 1; i < 5; i++)
    printf("map[%d]  Sum = %lld\n", i, _stp_pmap_get_ix(map, i)->sum);
  printf("\n");

  /* delete an entry and repeat */
  for (_processor_number = 0; _processor_number < NR_CPUS; _processor_number++)
    _stp_pmap_set_ix(map, 2, 0);
  _processor_number = 0;  

  /* print the aggregated data */
  _stp_pmap_print(map,"map[%1d] = count:%C  sum:%S  avg:%A  min:%m  max:%M\n%H");

  /* now use GET */
  for (i = 1; i < 5; i++) {
    stat *sd = _stp_pmap_get_ix(map, i);
    if (sd)
      printf("map[%d]  Sum = %lld\n", i, sd->sum);
  }
  printf("\n");

  _stp_pmap_del (map);
  return 0;
}