IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40774


Ignore:
Timestamp:
Jun 2, 2019, 5:33:14 PM (7 years ago)
Author:
eugene
Message:

add function to print allocated strings (strcreate, strncreate); add function to set the number of memory blocks / strings printed by the memory functions

Location:
branches/eam_branches/ohana.20190329/src/libohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20190329/src/libohana/include/ohana_allocate.h

    r39457 r40774  
    4444void ohana_memcheck_block_func (const char *myFile, int myLine, const char *myFunc, void *in);
    4545void  real_free (void *in);
     46
     47void ohana_memdump_strings_file (FILE *f, int VERBOSE);
     48void ohana_memdump_set_maxlines (int N);
    4649
    4750# define ohana_memcheck(X) ohana_memcheck_func (__FILE__, __LINE__, __func__, X)
  • branches/eam_branches/ohana.20190329/src/libohana/src/ohana_allocate.c

    r40117 r40774  
    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.