int main(int argc, char *argv[]) { char *ptr; int fp; char *v; int loop; struct stat *buf; int fsize; if( argc != 3 ) { return fprintf(stderr, "\nUsage :\n%s <filename> <size in megs>\n\n",argv[0]); } fprintf(stderr, "\nbefore allocation:\n\n"); malloc_stats(); getchar(); ptr = (char *) malloc(strlen(argv[1]) * sizeof(char) + 1); buf = (struct stat *) malloc(sizeof(struct stat)); if( (fp = open(argv[1], O_RDWR|O_CREAT)) < 0 ) { return fprintf(stderr, "\nUnable to open %s\n", argv[1]); } fsize = atol(argv[2]) * 1024 * 1024; if(! fsize ) fsize = DEFAULT * 1024 * 1024; if( ftruncate(fp, fsize ) < 0 ) { return fprintf(stderr, "\nUnable to ftruncate %s\n", argv[1]); } if( fstat(fp, buf ) < 0 ) { return fprintf(stderr, "\nUnable to fstat %s\n", argv[1]); } v = mmap(0, buf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0 ); if( (int) v < 0 ) { return fprintf(stderr, "\nmmap() failed.\n"); } fprintf(stderr, "\n\nafter allocation:\n\n"); malloc_stats(); getchar(); for(loop=0;loop < buf->st_size - 1; loop+=2) { v[loop] = 'X'; } free(ptr); munmap(v, buf->st_size); fprintf(stderr,"\nargv[1] length : %d\nfile size : %ld\n", strlen(argv[1]),buf->st_size); free(buf); fprintf(stderr, "\nafter free:\n\n"); malloc_stats(); getchar(); return close(fp); }
int main(int argc, char *argv[]) { char *ptr; int fp; char *v; int loop; struct stat *buf; if( argc != 2 ) { return fprintf(stderr, "\nNo data for argv[1]\n\n"); } fprintf(stderr, "\nbefore allocation:\n\n"); malloc_stats(); getchar(); ptr = (char *) malloc(strlen(argv[1]) * sizeof(char) + 1); buf = (struct stat *) malloc(sizeof(struct stat)); if( (fp = open(argv[1], O_RDWR)) < 0 ) { return fprintf(stderr, "\nUnable to open %s\n", argv[1]); } if( fstat(fp, buf) < 0 ) { return fprintf(stderr, "\nUnable to fstat %s\n", argv[1]); } v = mmap(0, buf->st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fp, 0 ); if( (int) v < 0 ) { return fprintf(stderr, "\nmmap() failed.\n"); } fprintf(stderr, "\n\nafter allocation:\n\n"); malloc_stats(); getchar(); for(loop=0;loop < buf->st_size - 1; loop+=2) { v[loop] = 'X'; } free(ptr); munmap(v, buf->st_size); fprintf(stderr,"\nargv[1] length : %d\nfile size : %ld\n", strlen(argv[1]),buf->st_size); free(buf); fprintf(stderr, "\nafter free:\n\n"); malloc_stats(); getchar(); return close(fp); }
int main() { char *s; s = malloc(20); malloc_stats(); return 0; }
static void luash_entry(const struct app_descriptor *app, void *args) { int status; iprintf("Got here 1, BUFSIZ=%d\n", BUFSIZ); malloc_stats(); lua_State *L = luaL_newstate(); /* create state */ iprintf("Got here 2\n"); if (L == NULL) { l_message(progname, "cannot create state: not enough memory"); return; } /* call 'pmain' in protected mode */ lua_pushcfunction(L, &pmain); status = lua_pcall(L, 2, 1, 0); lua_toboolean(L, -1); finalreport(L, status); lua_close(L); return; }
static gboolean mallocStatsCb(gpointer data) { char buf[30]; time_t cur_time; time(&cur_time); static pid_t my_pid = 0; static char process_name[16] = { 0 }; if (!my_pid) { my_pid = getpid(); } if (!process_name[0]) { ::prctl(PR_GET_NAME, (unsigned long)process_name, 0, 0, 0); process_name[sizeof(process_name) - 1] = '\0'; } struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); flock(STDERR_FILENO, LOCK_EX); fflush(stderr); fprintf(stderr, "\nMALLOC STATS FOR PROCESS: \"%s\" (PID: %d) AT [%ld.%ld] %s", process_name, my_pid, ts.tv_sec, ts.tv_nsec, ctime_r(&cur_time, buf)); fflush(stderr); malloc_stats(); fprintf(stderr, "\n\n"); fflush(stderr); fsync(STDERR_FILENO); flock(STDERR_FILENO, LOCK_UN); return TRUE; }
int main() { char *str; str = (char *)malloc(15); strcpy(str, "dfgasdfgasdfgasdfg"); int realSize = 48; int MIN_SIZE = 32; double d = realSize / MIN_SIZE; printf("d = %f\n", d); int flIndex = (int)ceil(log(d) / log(2)); printf("index = %d\n", flIndex); printf("%s\n", str); malloc_stats(); free(str); int *aa[2]; int i1 = 1; int i2 = 2; int i3 = 3; aa[0] = &i1; int *ii; ii = &i3; aa[1] = aa[0]; aa[0] = ii; printf("aa0: %d, aa1: %d\n", *aa[0], *aa[1]); return(0); }
int main() { search_tree t = create_search_tree(); for(int i = 0;i < 20;++i){ search_tree_node node = create_search_tree_node(i); search_tree_insert(t,node); } in_order_search_tree(t->root); putchar('\n'); int maximum = search_tree_maximum(t->root)->key; int minimum = search_tree_minimum(t->root)->key; printf("maximum element:%d\nminimum element:%d\n",maximum,minimum); printf("After delete key=maximum,key=0 operation:\n"); delete_search_tree_node(t,search_tree_find(t->root,maximum)); delete_search_tree_node(t,search_tree_find(t->root,0)); in_order_search_tree(t->root); putchar('\n'); free_search_tree(t); malloc_stats(); return 0; }
/* Does the actual shutdown stuff for a proper shutdown */ void arch_shutdown() { /* Run dtors */ arch_atexit(); arch_dtors(); dbglog(DBG_CRITICAL, "arch: shutting down kernel\n"); /* Turn off UBC breakpoints, if any */ // ubc_disable_all(); /* Do auto-shutdown... or use the "light weight" version underneath */ #if 1 arch_auto_shutdown(); #else /* Ensure that interrupts are disabled */ irq_disable(); irq_enable_exc(); /* Make sure that PVR and Maple are shut down */ pvr_shutdown(); maple_shutdown(); /* Shut down any other hardware things */ hardware_shutdown(); #endif if (__kos_init_flags & INIT_MALLOCSTATS) { malloc_stats(); } /* Shut down IRQs */ // irq_shutdown(); }
void show_mem_info() { MEM_MSG("malloc times:\t %d\n", malloc_times); MEM_MSG("calloc times:\t %d\n", calloc_times); MEM_MSG("free times:\t %d\n", free_times); MEM_MSG("strdup times:\t %d\n", strdup_times); #ifdef HAVE_MALLINFO MEM_MSG("------ mallinfo ------\n"); struct mallinfo mi = mallinfo(); MEM_MSG("System bytes\t=\t\t%d\n", mi.arena+mi.hblkhd); MEM_MSG("In use bytes\t=\t\t%d\n", mi.uordblks); MEM_MSG("Freed bytes\t=\t\t%d\n", mi.fordblks); MEM_MSG("----------------------\n"); #endif #ifdef HAVE_MALLOC_STATS /* FIXME */ /* malloc_stats output string to stderr. We can * try to temporarily reset stderr to our debug output. */ malloc_stats(); #endif #if 0 if (free_times != malloc_times + calloc_times + strdup_times) MEM_MSG("Memery leak found!!!!\n"); else MEM_MSG("No memory leak found.\n"); #endif return; }
int main(int argc, char *argv[]) { long num; long i; int size; int sum = 0; long overhead; struct mallinfo info; srand((unsigned int)time(NULL)); num = atol(argv[1]); for(i = 0; i < num; i++) { size = get_random_size(); malloc(size); sum += size; } fprintf(stderr, "Sum: %d\n", sum); malloc_stats(); info = mallinfo(); fprintf(stderr, "info.arena: %d\n", info.arena); overhead = info.arena - sum; fprintf(stderr, "%lu (%lu%%)\n", overhead, 100*overhead / info.arena); return 0; }
CAMLprim value malloc_stats_stub(value __unused v_unit) { caml_enter_blocking_section(); malloc_stats(); caml_leave_blocking_section(); return Val_unit; }
int main(void) { char text[] = "The art of Unix Programming"; char *str = malloc(strlen(text)); malloc_stats(); return(EXIT_SUCCESS); }
main () { int i = 130; void *p; printf("\n Before Malloc Call \n"); malloc_stats(); printf("\n"); getchar(); printf("\n After Malloc Call \n"); p = malloc(i); printf("\n %p \n",p); getchar(); malloc_stats(); free(p); getchar(); malloc_stats(); }
void TestMem() { #ifdef INSTANCE_COUNTING Log.Green("Counts:"); Log.Message("MappedRead count = %i", MappedRead::sInstanceCount); Log.Message("LocationScore count = %i", LocationScore::sInstanceCount); #endif malloc_stats(); }
void *my_realloc(void *ptr, size_t bytes) { void *mem = realloc(ptr, bytes); if(mem == NULL) { myLog(LOG_ERR, "realloc() failed : %s", strerror(errno)); if(debug) malloc_stats(); exit(EXIT_FAILURE); } return mem; }
static void minfo(void) { #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO) struct mallinfo mi; mi = mallinfo(); printf(" fordblks = %d\n", mi.fordblks); malloc_stats(); printf("\n"); #endif }
void doit (int bytes) { char *buf; struct mallinfo mi; fprintf (stderr, "\n Allocating %10d bytes ------- \n", bytes); buf = malloc (bytes); malloc_stats (); mi = mallinfo (); dump_mi (&mi); free (buf); }
void jl_print_gc_stats(JL_STREAM *s) { double gct = total_gc_time/1e9; malloc_stats(); double ptime = clock_now()-process_t0; jl_printf(s, "exec time\t%.5f sec\n", ptime); jl_printf(s, "gc time \t%.5f sec (%2.1f%%)\n", gct, (gct/ptime)*100); struct mallinfo mi = mallinfo(); jl_printf(s, "malloc size\t%d MB\n", mi.uordblks/1024/1024); jl_printf(s, "total freed\t%llu b\n", total_freed_bytes); jl_printf(s, "free rate\t%.1f MB/sec\n", (total_freed_bytes/gct)/1024/1024); }
bool CAPIApp::Run() { while(!exit) { pthread_testcancel(); // Thread beenden wenn gewuenscht struct timeval tv; unsigned int Info; tv.tv_sec = 60; tv.tv_usec = 0; CAPI20_WaitforMessage(Appl_Id, &tv); switch(Info = capi_get_cmsg(CMSG, Appl_Id)) { case 0x0000: switch (CMSG->Subcommand) { case CAPI_CONF: if(dbg_capiconf) cdebug << "capiconf : Received CAPI_CONF!" << endl; HandleConf(); break; case CAPI_IND: if(dbg_capiind) cdebug << "capiind : Received CAPI_IND!" << endl; HandleInd(); break; default: cdebug << "error : unknown subcommand " << CMSG->Subcommand << endl; break; } break; case 0x1104: if(dbg_capireq || dbg_capiresp || dbg_capiconf || dbg_capiind || dbg_systeminfo) { time_t t; time(&t); cdebug << "info : nothing received @" << ctime(&t) << endl; if(dbg_systeminfo) malloc_stats(); } break; default: cdebug << "error : ignoring CAPI_GET_CMSG Info == " << Info << endl; break; } } // while !exit exit=false; return 0; }
void MEM_lockfree_printmemlist_stats(void) { printf("\ntotal memory len: %.3f MB\n", (double)mem_in_use / (double)(1024 * 1024)); printf("peak memory len: %.3f MB\n", (double)peak_mem / (double)(1024 * 1024)); printf("\nFor more detailed per-block statistics run Blender with memory debugging command line argument.\n"); #ifdef HAVE_MALLOC_STATS printf("System Statistics:\n"); malloc_stats(); #endif }
Var memory_usage(void) { Var r; #ifdef USE_GNU_MALLOC int nsizes, i; /* Discover how many block sizes there are. */ for (nsizes = 0;; nsizes++) { struct mstats_value v; v = malloc_stats(nsizes); if (v.blocksize <= 0) break; } /* Get all of the allocation out of the way before getting the stats. */ r = new_list(nsizes); for (i = 1; i <= nsizes; i++) r.v.list[i] = new_list(3); for (i = 0; i < nsizes; i++) { struct mstats_value v; Var l; v = malloc_stats(i); l = r.v.list[i + 1]; l.v.list[1].type = l.v.list[2].type = l.v.list[3].type = TYPE_INT; l.v.list[1].v.num = v.blocksize; l.v.list[2].v.num = v.nused; l.v.list[3].v.num = v.nfree; } #else r = new_list(0); #endif return r; }
void print_gc_stats(void) { malloc_stats(); double ptime = clock_now()-process_t0; ios_printf(ios_stderr, "exec time\t%.5f sec\n", ptime); ios_printf(ios_stdout, "gc time \t%.5f sec (%2.1f%%)\n", total_gc_time, (total_gc_time/ptime)*100); struct mallinfo mi = mallinfo(); ios_printf(ios_stdout, "malloc size\t%d MB\n", mi.uordblks/1024/1024); ios_printf(ios_stdout, "total freed\t%llu b\n", total_freed_bytes); ios_printf(ios_stdout, "free rate\t%.1f MB/sec\n", (total_freed_bytes/total_gc_time)/1024/1024); }
static int_fast8_t printInfo() { float f1; printf("\n"); printf(" PID = %d\n", CLIPID); printf("--------------- GENERAL ----------------------\n"); printf("%s VERSION %s\n", PACKAGE_NAME, PACKAGE_VERSION ); printf("%s BUILT %s %s\n", __FILE__,__DATE__,__TIME__); printf("\n"); printf("--------------- SETTINGS ---------------------\n"); if(data.precision==0) printf("Default precision upon startup : float\n"); if(data.precision==1) printf("Default precision upon startup : double\n"); printf("sizeof(short int) = %3ld bit\n", sizeof(short int)*8); printf("sizeof(int) = %3ld bit\n", sizeof(int)*8); printf("sizeof(long) = %3ld bit\n", sizeof(long)*8); printf("sizeof(long long) = %3ld bit\n", sizeof(long long)*8); printf("sizeof(int_fast8_t) = %3ld bit\n", sizeof(int_fast8_t)*8); printf("sizeof(int_fast16_t) = %3ld bit\n", sizeof(int_fast16_t)*8); printf("sizeof(int_fast32_t) = %3ld bit\n", sizeof(int_fast32_t)*8); printf("sizeof(int_fast64_t) = %3ld bit\n", sizeof(int_fast64_t)*8); printf("sizeof(uint_fast8_t) = %3ld bit\n", sizeof(uint_fast8_t)*8); printf("sizeof(uint_fast16_t) = %3ld bit\n", sizeof(uint_fast16_t)*8); printf("sizeof(uint_fast32_t) = %3ld bit\n", sizeof(uint_fast32_t)*8); printf("sizeof(uint_fast64_t) = %3ld bit\n", sizeof(uint_fast64_t)*8); printf("\n"); printf("--------------- LIBRARIES --------------------\n"); printf("READLINE : version %x\n",RL_READLINE_VERSION); # ifdef _OPENMP printf("OPENMP : Compiled by an OpenMP-compliant implementation.\n"); # endif printf("CFITSIO : version %f\n", fits_get_version(&f1)); printf("\n"); printf("--------------- DIRECTORIES ------------------\n"); printf("CONFIGDIR = %s\n", CONFIGDIR); printf("SOURCEDIR = %s\n", SOURCEDIR); printf("\n"); printf("--------------- MALLOC INFO ------------------\n"); malloc_stats(); printf("\n"); return(0); }
static void print_memory_usage(void) { #if 0 fprintf(stderr, "blocks alloced: %lu, %.1f%% 8K\n", (unsigned long)(total_8kblocks + total_otherblocks), (100.0 * total_8kblocks) / (total_8kblocks + total_otherblocks)); fprintf(stderr, "system bytes(kB): %lu\n", ((unsigned long)total_system_bytes + 512) / 1024); fprintf(stderr, "overhead: %.1f%%\n", total_system_bytes * 100.0 / bytes.max - 100); #endif { extern void malloc_stats(void); malloc_stats(); } fflush(stderr); }
int main(int argc, char *argv[]) { long num; long i; int sum = 0; num = atol(argv[1]); for(i = 0; i < num; i++) { malloc(SIZE); sum += SIZE; } fprintf(stderr, "Sum: %d\n", sum); malloc_stats(); return 0; }
int main( void ) { int rc = 0; struct timezone tz = { 240, 1 }; struct timeval begin_timeval; struct timeval end_timeval; gettimeofday( &begin_timeval, &tz ); long i; jsonObject * pObj = NULL; for( i = 10000000; i; --i ) { // pObj = jsonParse( sample_json ); pObj = jsonNewObject( NULL ); jsonObject * p1 = jsonNewObject( NULL ); jsonObject * p2 = jsonNewObject( NULL ); jsonObjectFree( p1 ); jsonObjectFree( p2 ); jsonObjectFree( pObj ); } jsonObjectFreeUnused(); gettimeofday( &end_timeval, &tz ); struct timeval elapsed = diff_timeval( &begin_timeval, &end_timeval ); printf( "Elapsed time: %ld seconds, %ld microseconds\n", (long) elapsed.tv_sec, (long) elapsed.tv_usec ); struct rlimit rlim; if( getrlimit( RLIMIT_DATA, &rlim ) ) printf( "Error calling getrlimit\n" ); else printf( "Address space: %lu\n", (unsigned long) rlim.rlim_cur ); #ifdef HAVE_MALLOC_STATS malloc_stats(); #else fprintf(stderr, "malloc_stats() is not available on your system\n"); #endif return rc; }
int main(int argc, char **argv) { int err = 0; lua_State *L; setup_signal_handler(); /* parse args once to read config file location */ if (parse_args(argc, argv, &err) != 0) { return err; } /* ini file sets defaults for arguments*/ parse_config(inifile); if (!global.inifile) { log_error("could not open ini configuration %s\n", inifile); } /* parse arguments again, to override ini file */ parse_args(argc, argv, &err); log_open(logfile); locale_init(); #ifdef CRTDBG init_crtdbg(); #endif L = lua_init(); game_init(); bind_monsters(L); err = eressea_run(L, luafile); if (err) { log_error("script %s failed with code %d\n", luafile, err); return err; } #ifdef MSPACES malloc_stats(); #endif game_done(); lua_done(L); log_close(); if (global.inifile) { iniparser_freedict(global.inifile); } return 0; }
int main(int argc, char **argv) { int err, result = 0; lua_State *L; setup_signal_handler(); parse_config(inifile); log_open(logfile); err = parse_args(argc, argv, &result); if (err) { return result; } locale_init(); #ifdef CRTDBG init_crtdbg(); #endif L = lua_init(); game_init(); register_races(); register_borders(); register_spells(); bind_monsters(L); err = eressea_run(L, luafile); if (err) { log_error("server execution failed with code %d\n", err); return err; } #ifdef MSPACES malloc_stats(); #endif game_done(); lua_done(L); log_close(); if (global.inifile) { iniparser_free(global.inifile); } return 0; }
static void start() { memset(&songinfo, 0, sizeof(SONGINFO)); read_song_info_for_song(&(songlist.list[current_song_index]), &songinfo); assert(f_open( &file, get_full_filename(songlist.list[current_song_index].filename), FA_OPEN_EXISTING|FA_READ) == FR_OK); iprintf("title: %s\n", songinfo.title); iprintf("artist: %s\n", songinfo.artist); iprintf("album: %s\n", songinfo.album); iprintf("skipping: %i\n", songinfo.data_start); f_lseek(&file, songinfo.data_start); if (songinfo.type != UNKNOWN) { //assert(f_open( &file, get_full_filename(fileinfo.fname), FA_OPEN_EXISTING|FA_READ) == FR_OK); //puts("File opened."); switch(songinfo.type) { case AAC: aac_alloc(); aac_reset(); break; case MP4: aac_alloc(); aac_reset(); aac_setup_raw(); break; case MP3: mp3_alloc(); mp3_reset(); break; } puts("playing"); malloc_stats(); state = PLAYING; } else { puts("unknown file type"); stop(); } }
void testEventHandler(Event* event, void* opaque) { printf("Hello iBoot! Up time: %Ld seconds\r\n", timer_get_system_microtime() / 1000000); printf("ClockFrequency: %u Hz\r\n", (unsigned int) ClockFrequency); printf("MemoryFrequency: %u Hz\r\n", (unsigned int) MemoryFrequency); printf("BusFrequency: %u Hz\r\n", (unsigned int) BusFrequency); printf("UnknownFrequency: %u Hz\r\n", (unsigned int) UnknownFrequency); printf("PeripheralFrequency: %u Hz\r\n", (unsigned int) PeripheralFrequency); printf("Unknown2Frequency: %u Hz\r\n", (unsigned int) Unknown2Frequency); printf("FixedFrequency: %u Hz\r\n", (unsigned int) FixedFrequency); printf("TimebaseFrequency: %u Hz\r\n", (unsigned int) TimebaseFrequency); printf("PLL0 Frequency: %u Hz\r\n", (unsigned int) PLLFrequencies[0]); printf("PLL1 Frequency: %u Hz\r\n", (unsigned int) PLLFrequencies[1]); printf("PLL2 Frequency: %u Hz\r\n", (unsigned int) PLLFrequencies[2]); printf("PLL3 Frequency: %u Hz\r\n", (unsigned int) PLLFrequencies[3]); void* x = malloc(32214); malloc_stats(); free(x); printf("\n\n"); event_readd(event, 0); }