| 265 | } |
| 266 | |
| 267 | void InitializeLibrary(dmMemProfile::InternalData* internal_data) |
| 268 | { |
| 269 | Log(STDERR_FILENO, "dmMemProfile loaded\n"); |
| 270 | |
| 271 | pthread_mutexattr_t attr; |
| 272 | int ret = pthread_mutexattr_init(&attr); |
| 273 | assert(ret == 0); |
| 274 | ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); |
| 275 | assert(ret == 0); |
| 276 | |
| 277 | g_Mutex = new pthread_mutex_t; |
| 278 | ret = pthread_mutex_init(g_Mutex, &attr); |
| 279 | assert(ret == 0); |
| 280 | ret = pthread_mutexattr_destroy(&attr); |
| 281 | assert(ret == 0); |
| 282 | |
| 283 | *internal_data->m_IsEnabled = true; |
| 284 | g_ExtStats = internal_data->m_Stats; |
| 285 | |
| 286 | if (m_PropertyRegisterGroup) |
| 287 | { |
| 288 | g_ProfileGroup = m_PropertyRegisterGroup("Memory", "", 0); |
| 289 | g_ProfileAllocations = m_PropertyRegisterU32("Allocations", "Num allocations", 0, 0, GetProfileGroup); |
| 290 | g_ProfileAmount = m_PropertyRegisterU32("Amount", "Total amount (bytes)", 0, 0, GetProfileGroup); |
| 291 | } |
| 292 | |
| 293 | char* trace = getenv("DMMEMPROFILE_TRACE"); |
| 294 | if (trace && strlen(trace) > 0 && trace[0] != '0') |
| 295 | { |
| 296 | g_TraceFile = open("memprofile.trace", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); |
| 297 | if (g_TraceFile == -1) |
| 298 | { |
| 299 | Log(STDERR_FILENO, "WARNING: Unable to open memprofile.trace\n"); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | void FinalizeLibrary() |
| 305 | { |
no test coverage detected