IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 27, 2019, 5:29:35 AM (7 years ago)
Author:
eugene
Message:

added 2 new swap functions; added memory dump options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/src/ohana_allocate.c

    r40117 r41154  
    4545
    4646static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
     47
     48static int NblockMaxDump = 100;
    4749
    4850void ohana_meminit () {
     
    435437        fprintf (stderr, "memory corruption\n");
    436438      }
    437       if (Nbad < 100) {
     439      if (Nbad < NblockMaxDump) {
    438440        fprintf (stderr, "  file: %s, line: %d, func: %s\n", thisBlock->file, thisBlock->line, thisBlock->func);
    439441      }
     
    613615    Nbytes += thisBlock->size;
    614616
    615     if (Ntotal < 100) {
     617    if (Ntotal < NblockMaxDump) {
    616618      if (good) {
    617619        fprintf (f, "  %zd  %zd  %zd  GOOD  %s %d, func: %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->file, thisBlock->line, thisBlock->func);
     
    677679  return memstats;
    678680}
     681
     682void ohana_memdump_strings_file (FILE *f, int VERBOSE) {
     683
     684  if (!lastBlock) {
     685    if (VERBOSE) fprintf (f, "no memory allocated\n");
     686    return;
     687  }
     688
     689  OhanaMemblock *thisBlock = lastBlock;
     690
     691  size_t Ntotal = 0;
     692  size_t Nbytes = 0;
     693  size_t Nstring = 0;
     694
     695  fprintf (f, "    entry |    bytes | cumulative : line : string\n");
     696
     697  while (thisBlock) {
     698
     699    // pointer to the start of the user memory
     700    char *ptr = (char *)(thisBlock + 1);
     701
     702    Ntotal ++;
     703    Nbytes += thisBlock->size;
     704
     705    int N = strlen(thisBlock->file);
     706    if (N > 22) {
     707      int found = !strcmp("libohana/src/string.c", &thisBlock->file[N - 21]);
     708      if (found) {
     709        if (Nstring < NblockMaxDump) {
     710          fprintf (f, " %8zd | %8zd | %10zd : %4d : %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->line, ptr);
     711        }
     712        Nstring ++;
     713      }
     714      thisBlock = thisBlock->prevBlock;
     715    }
     716  }
     717
     718  if (Nstring || VERBOSE) {
     719    fprintf (f, "%zd strings allocated\n", Nstring);
     720  }
     721
     722  return;
     723}
     724
     725void ohana_memdump_set_maxlines (int N) {
     726  NblockMaxDump = N;
     727}
Note: See TracChangeset for help on using the changeset viewer.