tizen 2.3 release
[framework/system/swap-probe.git] / include / dacollection.h
1 /*
2  *  DA probe
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Jaewon Lim <jaewon81.lim@samsung.com>
9  * Woojin Jung <woojin2.jung@samsung.com>
10  * Juyoung Kim <j0.kim@samsung.com>
11  *
12  * This library is free software; you can redistribute it and/or modify it under
13  * the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation; either version 2.1 of the License, or (at your option)
15  * any later version.
16  *
17  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this library; if not, write to the Free Software Foundation, Inc., 51
24  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  *
26  * Contributors:
27  * - S-Core Co., Ltd
28  *
29  */
30
31 #ifndef __COLLECTIONS_H__
32 #define __COLLECTIONS_H__
33
34 #include <pthread.h>                    // for pthread_mutex_t
35
36 #include "khash.h"
37 #include "real_functions.h"
38
39 #ifdef __cplusplus
40 extern "C"{
41 #endif
42
43 #define SYMBOLHASH                      _hashinfo.symHash
44 #define SYMBOLHASH_LOCK         pthread_mutex_lock(&(_hashinfo.symHashMutex))
45 #define SYMBOLHASH_UNLOCK       pthread_mutex_unlock(&(_hashinfo.symHashMutex))
46
47 #define MEMORYHASH                      _hashinfo.memHash
48 #define MEMORYHASH_LOCK         pthread_mutex_lock(&(_hashinfo.memHashMutex))
49 #define MEMORYHASH_UNLOCK       pthread_mutex_unlock(&(_hashinfo.memHashMutex))
50
51 #define UIOBJECTHASH            _hashinfo.uiobjHash
52 #define UIOBJECTHASH_LOCK       pthread_mutex_lock(&(_hashinfo.uiobjHashMutex))
53 #define UIOBJECTHASH_UNLOCK     pthread_mutex_unlock(&(_hashinfo.uiobjHashMutex))
54
55 #define OBJECTHASH                      _hashinfo.objHash
56 #define OBJECTHASH_LOCK         pthread_mutex_lock(&(_hashinfo.objHashMutex))
57 #define OBJECTHASH_UNLOCK       pthread_mutex_unlock(&(_hashinfo.objHashMutex))
58
59 #define DETECTORHASH            _hashinfo.dttHash
60 #define DETECTORHASH_LOCK       pthread_mutex_lock(&(_hashinfo.dttHashMutex))
61 #define DETECTORHASH_UNLOCK     pthread_mutex_unlock(&(_hashinfo.dttHashMutex))
62
63 #define MEMTYPE_ALLOC   0x01
64 #define MEMTYPE_FREE    0x01
65 #define MEMTYPE_NEW             0x03
66 #define MEMTYPE_DELETE  0x03
67
68 #define MEM_INTERNAL    0x01
69 #define MEM_EXTERNAL    0x02
70
71 #define MEMMASK_CALLER  0xFFFF000000000000L
72 #define MEMMASK_TYPE    0x0000FFFF00000000L
73 #define MEMMASK_SIZE    0x00000000FFFFFFFFL
74
75 #define GET_MEMSIZE(_info)              ((size_t)(_info & MEMMASK_SIZE))
76 #define GET_MEMCALLER(_info)    ((unsigned short)((_info & MEMMASK_CALLER) >> 48))
77 #define GET_MEMTYPE(_info)              ((unsigned short)((_info & MEMMASK_TYPE) >> 32))
78
79 #define MAKE_MEMINFO(caller, type, size)        \
80         (((uint64_t)caller << 48) | ((uint64_t)type << 32) | ((uint64_t)size))
81
82 #define OBJECT_INTERNAL 0x01
83 #define OBJECT_EXTERNAL 0x02
84
85 typedef struct
86 {
87         char* type;
88         char* name;
89 } _uiobjectinfo;
90
91 // khash table function definition
92 KHASH_MAP_INIT_INT(symbol, char*)
93
94 KHASH_MAP_INIT_INT(allocmap, uint64_t)
95
96 KHASH_MAP_INIT_INT(uiobject, _uiobjectinfo*)
97
98 KHASH_MAP_INIT_INT(object, unsigned short)
99
100 KHASH_MAP_INIT_INT(detector, void*)
101
102 typedef struct
103 {
104         khash_t(symbol)*        symHash;
105         pthread_mutex_t         symHashMutex;
106         khash_t(allocmap)*      memHash;
107         pthread_mutex_t         memHashMutex;
108         khash_t(uiobject)*      uiobjHash;
109         pthread_mutex_t         uiobjHashMutex;
110         khash_t(object)*        objHash;
111         pthread_mutex_t         objHashMutex;
112         khash_t(detector)*      dttHash;
113         pthread_mutex_t         dttHashMutex;
114 } __hashInfo;
115
116 extern __hashInfo _hashinfo;
117
118 // APIs for symdata linked list
119 int add_to_glist(char* key, void* data);
120 int remove_from_glist(char* key);
121 int remove_all_glist();
122 void* find_glist(char* key);
123
124 // APIs for hash table
125 int initialize_hash_table();
126 int finalize_hash_table();
127
128 int find_symbol_hash(void* ptr, char** psymbol);
129 int add_symbol_hash(void* ptr, const char* str, int strlen);
130 int add_memory_hash(void* ptr, size_t size, unsigned short type, unsigned short caller);
131 int del_memory_hash(void* ptr, unsigned short type, unsigned short* caller);
132
133 int find_uiobject_hash(void* ptr, char** type,  char** classname);
134 int add_uiobject_hash_class(void* ptr, const char* classname);
135 int add_uiobject_hash_type(void* ptr, const char* type);
136 int del_uiobject_hash(void* ptr);
137
138 int find_object_hash(void* ptr, unsigned short *caller);
139 int add_object_hash(void* ptr, unsigned short caller);
140 int del_object_hash(void* ptr, unsigned short *caller);
141
142 int add_detector_hash(void* ptr, void* listener);
143 int del_detector_hash(void* ptr);
144
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif /* __COLLECTIONS_H_ */