1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/jprof/stub/libmalloc.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef libmalloc_h___ 1.9 +#define libmalloc_h___ 1.10 + 1.11 +#include <sys/types.h> 1.12 +#include <malloc.h> 1.13 + 1.14 +#ifdef __cplusplus 1.15 +extern "C" { 1.16 +#endif 1.17 + 1.18 +#include "config.h" 1.19 + 1.20 +typedef unsigned long u_long; 1.21 + 1.22 +// For me->flags 1.23 +#define JP_FIRST_AFTER_PAUSE 1 1.24 + 1.25 +// Format of a jprof log entry. This is what's written out to the 1.26 +// "jprof-log" file. 1.27 +// It's called malloc_log_entry because the history of jprof is that 1.28 +// it's a modified version of tracemalloc. 1.29 +struct malloc_log_entry { 1.30 + u_long delTime; 1.31 + u_long numpcs; 1.32 + unsigned int flags; 1.33 + int thread; 1.34 + char* pcs[MAX_STACK_CRAWL]; 1.35 +}; 1.36 + 1.37 +// type's 1.38 +#define malloc_log_stack 7 1.39 + 1.40 +// Format of a malloc map entry; after this struct is nameLen+1 bytes of 1.41 +// name data. 1.42 +struct malloc_map_entry { 1.43 + u_long nameLen; 1.44 + u_long address; // base address 1.45 +}; 1.46 + 1.47 +// A method that can be called if you want to programmatically control 1.48 +// the malloc logging. Note that you must link with the library to do 1.49 +// this (or use dlsym after dynamically loading the library...) 1.50 +extern u_long SetMallocFlags(u_long flags); 1.51 + 1.52 +// The environment variable LIBMALLOC_LOG should be set to an integer 1.53 +// value whose meaning is as follows: 1.54 + 1.55 +// Enable logging 1.56 +#define LIBMALLOC_LOG 0x1 1.57 + 1.58 +// Don't free memory when set 1.59 +#define LIBMALLOC_NOFREE 0x2 1.60 + 1.61 +// Check heap for corruption after every malloc/free/realloc 1.62 +#define LIBMALLOC_CHECK 0x4 1.63 + 1.64 +// Log reference count calls (addref/release) 1.65 +#define LIBMALLOC_LOG_RC 0x8 1.66 + 1.67 +// Log a stack trace 1.68 +#define LIBMALLOC_LOG_TRACE 0x10 1.69 + 1.70 +void __log_addref(void* p, int oldrc, int newrc); 1.71 +void __log_release(void* p, int oldrc, int newrc); 1.72 + 1.73 +#ifdef __cplusplus 1.74 +} /* end of extern "C" */ 1.75 +#endif 1.76 + 1.77 +#endif /* libmalloc_h___ */