Changeset 13993 for trunk/ppStats/src/ppStats.c
- Timestamp:
- Jul 2, 2007, 10:35:53 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/ppStats/src/ppStats.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStats/src/ppStats.c
r13677 r13993 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 1 # include "ppStatsInternal.h" 4 2 5 #include <stdio.h> 6 #include <pslib.h> 7 #include <psmodules.h> 3 int main(int argc, char **argv) { 8 4 9 #include "ppStats.h" 5 psExit status = PS_EXIT_SUCCESS; 10 6 11 psMetadata *ppStats(psMetadata *out, 12 pmFPA *fpa, // FPA for which to get statistics 13 pmFPAview *view, // View for analysis 14 psMaskType maskVal, // Value to mask 15 pmConfig *config // Configuration 16 ) 17 { 18 PS_ASSERT_PTR_NON_NULL(fpa, NULL) 19 PS_ASSERT_PTR_NON_NULL(view, NULL); 20 PS_ASSERT_PTR_NON_NULL(config, NULL); 7 psLibInit(NULL); 8 psTimerStart("PPSTATS"); 21 9 22 ppStatsData *data = ppStatsDataAlloc(); // All the input data 10 // Parse the configuration and arguments 11 pmConfig *config = pmConfigRead(&argc, argv, PPSTATS_RECIPE); 12 if (!config) { 13 psErrorStackPrint(stderr, "Unable to read configuration.\n"); 14 exit(PS_EXIT_CONFIG_ERROR); 15 } 23 16 24 17 // Get the options, open the files 25 if (!ppStatsSetupFromRecipe(data, config)) {26 psError(PS_ERR_UNKNOWN, false, "Unable to get ppStats options from recipe.");27 ps Free(data);28 return NULL;18 ppStatsData *data = ppStatsSetupFromArgs(&argc, argv, config); 19 if (!data) { 20 psErrorStackPrint(stderr, "Unable to parse command-line arguments.\n"); 21 exit(PS_EXIT_CONFIG_ERROR); 29 22 } 30 23 31 // Override recipe mask value if one is provided 32 if (maskVal != 0) { 33 data->maskVal = maskVal; 24 // Output filename is optional 25 const char *outName = NULL; // Output file name 26 FILE *outFile = stdout; // Output file 27 if (argc == 2) { 28 outName = argv[1]; 29 psString resolved = pmConfigConvertFilename(outName, config, true); // Resolved filename 30 31 if (resolved && strlen(resolved) > 0) { 32 outFile = fopen(resolved, "w"); 33 if (!outFile) { 34 psLogMsg("ppStats", PS_LOG_ERROR, "Unable to open output file %s\n", resolved); 35 psFree(resolved); 36 // XXX this could be a system or config error, but not a data error 37 status = PS_EXIT_CONFIG_ERROR; 38 goto die; 39 } 40 } else { 41 psErrorStackPrint(stderr, "Unable to open output file %s.\n", resolved); 42 exit(PS_EXIT_CONFIG_ERROR); 43 } 44 psFree(resolved); 34 45 } 35 46 36 if (data->fpa) { 37 psFree(data->fpa); 47 // Go through the FPA and do the hard work 48 psMetadata *results = ppStatsLoop(&status, data, config); 49 if (status != PS_EXIT_SUCCESS) { 50 psErrorStackPrint(stderr, "Error in stats loop.\n"); 51 exit (status); 38 52 } 39 data->fpa = psMemIncrRefCounter(fpa); 40 41 if (data->view) { 42 psFree(data->view); 43 } 44 data->view = psMemIncrRefCounter(view); 45 46 // Go through the FPA and do the hard work 47 psExit status; // Status of statistics loop 48 psMetadata *result = ppStatsLoop(&status, data, config); 49 if (status != PS_EXIT_SUCCESS) { 50 psError (PS_ERR_UNKNOWN, false, "Not able to measure FPA statistics.\n"); 51 psFree(result); 52 psFree(data); 53 return (NULL); 53 if (psListLength(results->list) == 0) { 54 psErrorStackPrint(stderr, "No output.\n"); 55 exit (status); 54 56 } 55 57 56 if (out != NULL) { 57 psMetadataCopy (out, result); 58 psFree(result); 59 psFree(data); 60 return out; 58 if (data->fileLevel) { 59 const char *level = pmFPALevelToName(pmFPAPHULevel(config->format)); // Level for file 60 psMetadataAddStr(results, PS_LIST_HEAD, "FILE.LEVEL", 0, "File level", level); 61 61 } 62 62 63 // Format and print the output 64 psString output = psMetadataConfigFormat(results); 65 if (!output) { 66 psErrorStackPrint(stderr, "Unable to generate configuration file with result.\n"); 67 psFree(results); 68 exit(PS_EXIT_CONFIG_ERROR); 69 } 70 fprintf(outFile, "%s", output); 71 psFree(output); 72 73 // Clean up 74 psFree(results); 75 if (outName) { 76 fclose(outFile); 77 } 78 79 // Common code for the death. 80 die: 81 if (status) { 82 psErrorStackPrint (stderr, "failure in %s", __func__); 83 } 63 84 psFree(data); 64 return result; 85 psFree(config); 86 pmConceptsDone(); 87 pmConfigDone(); 88 psLibFinalize(); 89 90 return status; 65 91 }
Note:
See TracChangeset
for help on using the changeset viewer.
