IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6396


Ignore:
Timestamp:
Feb 8, 2006, 4:37:59 PM (20 years ago)
Author:
Paul Price
Message:

Working version with no memory leaks (on MegaCam splice images)!

Location:
trunk/ppImage/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImage.c

    r6260 r6396  
    11#include <stdio.h>
    22#include "pslib.h"
     3#include "pmConcepts.h"
    34#include "ppImage.h"
    45#include "ppMem.h"
    5 
    66
    77int main(int argc, char **argv)
     
    2323    ppImageParseCamera(data, config);
    2424
    25     // Cleaning up
    26     psFree(data);
    27     psFree(options);
    28     psFree(config);
    29     psTimerStop();
    30     ppMemCheck();
    31 #if 0
    32 
    3325    // Set various tasks (define optional operations)
    3426    ppImageOptionsParse(data, options, config);
     
    3931    // Image Arithmetic Loop
    4032    ppImageLoop(data, options, config);
    41 #endif
    4233
    43     exit(EXIT_SUCCESS);
     34    // Cleaning up
     35    psFree(data);
     36    psFree(options);
     37    psFree(config);
     38    psTimerStop();
     39    psTraceReset();
     40    pmConceptsDone();
     41    ppMemCheck();
     42
     43    return EXIT_SUCCESS;
    4444}
  • trunk/ppImage/src/ppImageLoop.c

    r6260 r6396  
    77#include "ppImageDetrend.h"
    88#include "ppImage.h"
     9#include "ppMem.h"
    910
    1011#define MEM_LEAKS 1
     
    101102
    102103            // Need to free detrend cells here so we have enough memory to do other stuff
    103 #ifndef MEM_LEAKS
    104104            psFree(detrend.bias);
    105105            psFree(detrend.dark);
    106106            psFree(detrend.mask);
    107107            psFree(detrend.flat);
    108 #endif
    109108        }
    110109
     
    114113        // XXX EAM: Photometry goes here!
    115114
    116         // A kludge to get the write to behave wrt the concepts --- we've changed the camera format, so
     115        // XXX A kludge to get the write to behave w.r.t. the concepts --- we've changed the camera format, so
    117116        // the concepts don't know what on earth to do.
    118117        const psMetadata *camera = data->input->fpa->camera;
     
    122121
    123122        // Now I can blow away the mosaic so I can then read more.
    124 #ifndef MEM_LEAKS
    125         pmChipFreeCells(inputChip);
    126 #endif
     123        psFree(inputChip);
    127124    }
    128 
    129 #if 0
    130     // Write out the mosaicked chip, just to see; this wouldn't normally happen
    131     psFits *mosaicFile = psFitsOpen("mosaic.fits", "w");
    132     for (int i = 0; i < chips->n; i++) {
    133         pmChip *chip = chips->data[i];
    134         if (! chip || ! chip->exists || ! chip->process) {
    135             continue;
    136         }
    137 #if 0
    138         psArray *cells = chip->cells;
    139         pmCell *cell = cells->data[0];
    140         psArray *readouts = cell->readouts;
    141         pmReadout *readout = readouts->data[0];
    142         psImage *image = readout->image;
    143 #else
    144         psImage *image = chip->hdu->images->data[0];
    145 #endif
    146         psFitsWriteImage(mosaicFile, NULL, image, 0);
    147 
    148     }
    149 #endif
    150 
    151     // Free the detrend FPA and chips
    152 #ifndef MEM_LEAKS
    153     psFree(data->bias);
    154     psFree(data->dark);
    155     psFree(data->mask);
    156     psFree(data->flat);
    157 #endif
    158 
    159     psFitsClose(data->output);
    160125
    161126    return true;
    162127}
    163 
    164 /* if we allow per-readout loads, we need to load detrend images here */
  • trunk/ppImage/src/ppImageOptions.c

    r6260 r6396  
    180180        // Fill in the options
    181181        options->overscan = pmOverscanOptionsAlloc(overscanSingle, overscanFit, overscanOrder, overscanStats);
     182        psFree(overscanStats);
    182183    }
    183184
  • trunk/ppImage/src/ppMem.c

    r6260 r6396  
    5353
    5454    psMemBlock **leaks = NULL;          // List of leaks
    55     int nLeaks = psMemCheckLeaks(0, &leaks, leakFile, false); // Number of leaks
     55    int nLeaks = psMemCheckLeaks(0, &leaks, leakFile, true); // Number of leaks
    5656    fprintf(stderr, "%d leaks found:\n", nLeaks);
    57     for (int i = nLeaks - 1; i > 0; i--) {
     57    for (int i = nLeaks - 1; i >= 0; i--) {
    5858        ppMemPrint(leaks[i]);
    5959    }
     
    6363    fprintf(stderr, "%d memory blocks corrupted.\n", nCorrupted);
    6464}
     65
     66void ppMemUsed(void)
     67{
     68    psMemBlock **leaks = NULL;          // List of leaks
     69    int nLeaks = psMemCheckLeaks(0, &leaks, NULL, true); // Number of leaks
     70    size_t total = 0;                   // Total size
     71    size_t largest = 0;                 // Largest block size
     72    psMemId index = -1;                 // Id number of largest block
     73    for (int i = nLeaks - 1; i >= 0; i--) {
     74        psMemBlock *mb = leaks[i];
     75        if (mb->userMemorySize >= largest) {
     76            largest = mb->userMemorySize;
     77            index = mb->id;
     78        }
     79        total += mb->userMemorySize;
     80    }
     81    psFree(leaks);
     82
     83    psLogMsg(__func__, PS_LOG_INFO, "Memory used: %ld\nLargest id: %ld (%ld bytes)", total, index, largest);
     84
     85}
  • trunk/ppImage/src/ppMem.h

    r6260 r6396  
    88void ppMemPrint(const psMemBlock *ptr);
    99void ppMemCheck(void);
     10void ppMemUsed(void);
    1011
    1112#endif
Note: See TracChangeset for help on using the changeset viewer.