Changeset 7646
- Timestamp:
- Jun 22, 2006, 3:59:15 PM (20 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 edited
-
psConfigure.c (modified) (4 diffs)
-
psConfigure.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psConfigure.c
r5524 r7646 13 13 * @author Robert DeSonia, MHPCC 14 14 * 15 * @version $Revision: 1.1 2$ $Name: not supported by cvs2svn $16 * @date $Date: 200 5-11-16 20:52:23$15 * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-06-23 01:59:15 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 19 19 */ 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 #include "psMemory.h" 24 #include "psTrace.h" 20 25 #include "psString.h" 21 26 #include "psTime.h" … … 26 31 #include "config.h" 27 32 33 static char *memCheckName = NULL; // Filename to which to write results of mem check 34 static FILE *memCheckFile = NULL; // File to which to write results of mem check 35 28 36 char* psLibVersion(void) 29 37 { … … 31 39 snprintf(version,80,"%s-v%s",PACKAGE_NAME,PACKAGE_VERSION); 32 40 33 return (psStringCopy(version));41 return psStringCopy(version); 34 42 } 43 44 // Print details of a memory problem to the appropriate file 45 static void memoryProblem(const psMemBlock *ptr, // the pointer to the problematic memory block. 46 const char *file, // the file in which the problem originated 47 int lineno // the line number in which the problem originated 48 ) 49 { 50 fprintf(memCheckFile, 51 "Memory corruption detected in memBlock %lu\n" 52 "\tFile %s, line %d, size %zd\n" 53 "\tPosts: %p %p %p\n", 54 ptr->id, file, lineno, ptr->userMemorySize, ptr->startblock, ptr->endblock, 55 (ptr + 1 + ptr->userMemorySize)); 56 } 57 58 // Check the memory; intended for use on exit, but might be used elsewhere 59 void p_psMemoryCheck(void) 60 { 61 if (!memCheckName || strlen(memCheckName) == 0) { 62 return; 63 } 64 65 memCheckFile = fopen(memCheckName, "w"); // File to write leaks to 66 if (!memCheckFile) { 67 psError(PS_ERR_IO, true, "Unable to open leaks file, %s\n", memCheckName); 68 return; 69 } 70 71 int nLeaks = psMemCheckLeaks(0, NULL, memCheckFile, false); // Number of leaks 72 if (nLeaks > 0) { 73 psLogMsg(__func__, PS_LOG_WARN, "%d memory leaks found; list written to %s.\n", nLeaks, memCheckName); 74 } else { 75 psLogMsg(__func__, PS_LOG_INFO, "No memory leaks found.\n"); 76 } 77 78 int nCorrupted; // Number of corrupted memory blocks 79 (void)psMemProblemCallbackSet((psMemProblemCallback)memoryProblem); // Set callback for corruption 80 nCorrupted = psMemCheckCorruption(false); 81 if (nCorrupted > 0) { 82 psError(PS_ERR_UNKNOWN, true, "%d memory blocks corrupted; list written to %s.\n", nCorrupted); 83 } else { 84 psLogMsg(__func__, PS_LOG_INFO, "No memory corruption found.\n"); 85 } 86 87 fclose(memCheckFile); 88 89 return; 90 } 91 35 92 36 93 void psLibInit(const char* timeConfig) 37 94 { 38 95 // XXX: Still needs error codes to be set 39 // XXX: Still needs random number generator initialization40 96 41 if(!p_psTimeInit(timeConfig)) { 42 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 43 PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psTime"); 44 return; 97 if (timeConfig && strlen(timeConfig) > 0) { 98 if (!p_psTimeInit(timeConfig)) { 99 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 100 PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psTime"); 101 return; 102 } 45 103 } 46 if (!p_psEOCInit()) {104 if (!p_psEOCInit()) { 47 105 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 48 106 PS_ERRORTEXT_psConfigure_INITIALIZATION_FAILED, "psEOC"); 49 107 return; 108 } 109 110 // Does the user want memory checking at exit? 111 memCheckName = getenv("PS_ALLOC_CHECK"); // The value of PS_ALLOC_CHECK 112 if (memCheckName && strlen(memCheckName) > 0) { 113 atexit(&p_psMemoryCheck); 50 114 } 51 115 } … … 55 119 // Users of persistent memory should free them in this function 56 120 57 if(!p_psTimeFinalize()) { 58 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 121 // Stop timers 122 psTimerStop(); 123 124 // Free the time tables 125 if (!p_psTimeFinalize()) { 126 psError(PS_ERR_UNKNOWN, false, 59 127 PS_ERRORTEXT_psConfigure_FINALIZATION_FAILED, "psTime"); 60 128 return; 61 129 } 62 if(!p_psEOCFinalize()) { 63 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 130 131 // Free the precession tables 132 if (!p_psEOCFinalize()) { 133 psError(PS_ERR_UNKNOWN, false, 64 134 PS_ERRORTEXT_psConfigure_FINALIZATION_FAILED, "psEOC"); 65 135 return; 66 136 } 137 138 // Free the trace system 139 psTraceReset(); 140 141 // Free the error system 142 psErrorClear(); 143 67 144 } -
trunk/psLib/src/sys/psConfigure.h
r4205 r7646 13 13 * @author Robert DeSonia, MHPCC 14 14 * 15 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $16 * @date $Date: 200 5-06-10 01:41:35 $15 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-06-23 01:59:15 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 58 58 ); 59 59 60 // Check the memory; intended for use on exit, but might be used elsewhere 61 void p_psMemoryCheck(void); 60 62 61 63 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.
