PAPI 7.1.0.0
Loading...
Searching...
No Matches
CountingSet_Lib.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include "sde_lib.h"
4#include "papi.h"
5#include "papi_test.h"
6
8
9typedef struct test_type_s{
10 int id;
11 float x;
12 double y;
14
15typedef struct mem_type_s{
16 void *ptr;
18 size_t size;
20
22 int i;
23 void *test_set;
24 test_type_t element;
25
26 handle = papi_sde_init("CSET_LIB");
27 papi_sde_create_counting_set( handle, "test counting set", &test_set );
28
29 for(i=0; i<22390; i++){
30 int j = i%5222;
31 element.id = j;
32 element.x = (float)j*1.037/((float)j+32.1);
33 element.y = (double)(element.x)+145.67/((double)j+0.01);
34 papi_sde_counting_set_insert( test_set, sizeof(element), sizeof(element), &element, 0);
35 }
36
37 return;
38}
39
42}
43
45 int i, iter;
46 void *mem_set;
47 void *ptrs[128];
48
49 handle = papi_sde_init("CSET_LIB");
50 papi_sde_create_counting_set( handle, "malloc_tracking", &mem_set );
51
52 for(iter=0; iter<8; iter++){
53 mem_type_t alloc_elem;
54
55 for(i=0; i<64; i++){
56 size_t len = (17+i)*73;
57 ptrs[i] = malloc(len);
58
59 alloc_elem.ptr = ptrs[i];
60 alloc_elem.line_of_code = __LINE__;
61 alloc_elem.size = len;
62 papi_sde_counting_set_insert( mem_set, sizeof(alloc_elem), sizeof(void *), &alloc_elem, 1);
63 }
64 // "i" does _not_ start from zero so that some pointers are _not_ free()ed
65 for(i=iter; i<64; i++){
66 papi_sde_counting_set_remove( mem_set, sizeof(void *), &(ptrs[i]), 1);
67 free(ptrs[i]);
68 }
69
70 for(i=0; i<32; i++){
71 size_t len = (19+i)*73;
72 ptrs[i] = malloc(len);
73
74 alloc_elem.ptr = ptrs[i];
75 alloc_elem.line_of_code = __LINE__;
76 alloc_elem.size = len;
77 papi_sde_counting_set_insert( mem_set, sizeof(alloc_elem), sizeof(void *), &alloc_elem, 1);
78 }
79 // "i" does _not_ go to 31 so that some pointers are _not_ free()ed
80 for(i=0; i<32-iter; i++){
81 papi_sde_counting_set_remove( mem_set, sizeof(void *), &(ptrs[i]), 1);
82 free(ptrs[i]);
83 }
84
85 }
86
87 return;
88}
89
90void libCSet_dump_set( cset_list_object_t *list_head ){
91 cset_list_object_t *list_runner;
92
93 for(list_runner = list_head; NULL != list_runner; list_runner=list_runner->next){
94
95 switch(list_runner->type_id){
96 case 0:
97 {
98 test_type_t *ptr = (test_type_t *)(list_runner->ptr);
99 printf("count= %d typesize= %lu {id= %d, x= %f, y= %lf}\n", list_runner->count, list_runner->type_size, ptr->id, ptr->x, ptr->y);
100 break;
101 }
102 case 1:
103 {
104 mem_type_t *ptr = (mem_type_t *)(list_runner->ptr);
105 printf("count= %d typesize= %lu { ptr= %p, line= %d, size= %lu }\n", list_runner->count, list_runner->type_size, ptr->ptr, ptr->line_of_code, ptr->size);
106 break;
107 }
108 }
109 }
110
111 return;
112}
113
114int libCSet_count_set_elements( cset_list_object_t *list_head ){
115 cset_list_object_t *list_runner;
116 int element_count = 0;
117
118 for(list_runner = list_head; NULL != list_runner; list_runner=list_runner->next){
119 ++element_count;
120 }
121
122 return element_count;
123}
124
125
126// Hook for papi_native_avail utility. No user code which links against this library should call
127// this function because it has the same name in all SDE-enabled libraries. papi_native_avail
128// uses dlopen and dlclose on each library so it only has one version of this symbol at a time.
130 papi_handle_t tmp_handle;
131 tmp_handle = fptr_struct->init("CSET_LIB");
132 fptr_struct->create_counting_set( tmp_handle, "test counting set", NULL );
133 fptr_struct->create_counting_set( tmp_handle, "malloc_tracking", NULL );
134 return tmp_handle;
135}
int libCSet_count_set_elements(cset_list_object_t *list_head)
void libCSet_dump_set(cset_list_object_t *list_head)
void libCSet_do_memory_allocations(void)
papi_handle_t papi_sde_hook_list_events(papi_sde_fptr_struct_t *fptr_struct)
int libCSet_finalize(void)
void libCSet_do_simple_work(void)
papi_handle_t handle
int i
static long iter[MAX_THREADS]
Return codes and api definitions.
papi_handle_t papi_sde_init(const char *name_of_library)
Definition: sde_lib.c:119
int papi_sde_counting_set_remove(void *cset_handle, size_t hashable_size, const void *element, uint32_t type_id)
Definition: sde_lib.c:737
int papi_sde_counting_set_insert(void *cset_handle, size_t element_size, size_t hashable_size, const void *element, uint32_t type_id)
Definition: sde_lib.c:766
int papi_sde_shutdown(papi_handle_t handle)
Definition: sde_lib.c:212
int papi_sde_create_counting_set(papi_handle_t handle, const char *cset_name, void **cset_handle)
Definition: sde_lib.c:682
SDE prototypes and macros.
void * papi_handle_t
Definition: sde_lib.h:100
papi_handle_t(* init)(const char *lib_name)
Definition: sde_lib.h:103
int(* create_counting_set)(papi_handle_t handle, const char *cset_name, void **cset_handle)
Definition: sde_lib.h:113