📄 trace_impl.c
字号:
/* * (C) 2001 by Argonne National Laboratory * See COPYRIGHT in top-level directory. *//* * @author Anthony Chan */#include "trace_impl.h"#if defined( STDC_HEADERS ) || defined( HAVE_STDIO_H )#include <stdio.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )#include <stdlib.h>#endif#if defined( STDC_HEADERS ) || defined( HAVE_STRING_H )#include <string.h>#endif#include "trace_API.h"#define DRAW_TRUE 1#define DRAW_FALSE 0staticvoid bswp_byteswap( const int Nelem, const int elem_sz, char *bytes );staticvoid bswp_byteswap( const int Nelem, const int elem_sz, char *bytes ){ char *bptr; char btmp; int end_ii; int ii, jj; bptr = bytes; for ( jj = 0; jj < Nelem; jj++ ) { for ( ii = 0; ii < elem_sz/2; ii++ ) { end_ii = elem_sz - 1 - ii; btmp = bptr[ ii ]; bptr[ ii ] = bptr[ end_ii ]; bptr[ end_ii ] = btmp; } bptr += elem_sz; }}typedef struct { TRACE_Category_head_t *hdr; char *legend; char *label; int num_methods; int *methods;} DRAW_Category;#define MAX_COLNAMES 10#define MAX_NAME_LEN 128typedef struct { int num_rows; int num_columns; char title_name[ MAX_NAME_LEN ]; char column_names[ MAX_COLNAMES ][ MAX_NAME_LEN ]; int *elems; int num_methods; int *methods;} DRAW_YCoordMap;typedef struct { double starttime; double endtime; int type_idx; int num_info; char *info; int num_tcoords; double *tcoords; int num_ycoords; int *ycoords;} DRAW_Primitive;typedef struct { double starttime; double endtime; int type_idx; int num_info; char *info; int num_primes; /* DRAW_Primitive **primes; */ char **lines; /* each line contains one DRAW_Primitive */ int idx2prime;} DRAW_Composite;#define MAX_CATEGORIES 128#define MAX_LINE_LEN 1024typedef struct _trace_file { FILE *fd; char line[ MAX_LINE_LEN ]; int max_types; int num_types; DRAW_Category **types; DRAW_YCoordMap *ymap; DRAW_Primitive *prime; DRAW_Composite *cmplx;} DRAW_File;#define MAX_LEGEND_LEN 128#define MAX_LABEL_LEN 512staticDRAW_YCoordMap *YCoordMap_alloc( int Nrows, int Ncols, int Nmethods );staticDRAW_YCoordMap *YCoordMap_alloc( int Nrows, int Ncols, int Nmethods ){ DRAW_YCoordMap *map; map = (DRAW_YCoordMap *) malloc( sizeof(DRAW_YCoordMap) ); map->num_rows = Nrows; map->num_columns = Ncols; if ( Nrows * Ncols > 0 ) map->elems = (int *) malloc( Nrows * Ncols * sizeof( int ) ); else map->elems = NULL; map->num_methods = Nmethods; if ( Nmethods > 0 ) map->methods = (int *) malloc( Nmethods * sizeof( int ) ); else map->methods = NULL; return map;}staticvoid YCoordMap_free( DRAW_YCoordMap *map );staticvoid YCoordMap_free( DRAW_YCoordMap *map ){ if ( map != NULL ) { if ( map->methods != NULL ) { free( map->methods ); map->methods = NULL; } if ( map->elems != NULL ) { free( map->elems ); map->elems = NULL; } free( map ); }}/* legend_len & label_len are lengths of the string withOUT counting NULL */staticDRAW_Category *Category_alloc( int legend_len, int label_len, int Nmethods );staticDRAW_Category *Category_alloc( int legend_len, int label_len, int Nmethods ){ DRAW_Category *type; type = (DRAW_Category *) malloc( sizeof(DRAW_Category) ); type->hdr = (TRACE_Category_head_t *) malloc( sizeof(TRACE_Category_head_t) ); if ( legend_len > 0 ) type->legend = (char *) malloc( (legend_len+1) * sizeof(char) ); else type->legend = NULL; if ( label_len > 0 ) type->label = (char *) malloc( (label_len+1) * sizeof(char) ); else type->label = NULL; type->num_methods = Nmethods; if ( Nmethods > 0 ) type->methods = (int *) malloc( Nmethods * sizeof( int ) ); else type->methods = NULL; return type;}staticvoid Category_free( DRAW_Category *type );staticvoid Category_free( DRAW_Category *type ){ if ( type != NULL ) { if ( type->methods != NULL ) { free( type->methods ); type->methods = NULL; } if ( type->label != NULL ) { free( type->label ); type->label = NULL; } if ( type->legend != NULL ) { free( type->legend ); type->legend = NULL; } if ( type->hdr != NULL ) { free( type->hdr ); type->hdr = NULL; } free( type ); }}staticvoid Category_head_copy( TRACE_Category_head_t *hdr_copy, const TRACE_Category_head_t *hdr_copier );staticvoid Category_head_copy( TRACE_Category_head_t *hdr_copy, const TRACE_Category_head_t *hdr_copier ){ if ( hdr_copy != NULL && hdr_copier != NULL ) { hdr_copy->index = hdr_copier->index; hdr_copy->shape = hdr_copier->shape; hdr_copy->red = hdr_copier->red ; hdr_copy->green = hdr_copier->green; hdr_copy->blue = hdr_copier->blue ; hdr_copy->alpha = hdr_copier->alpha; hdr_copy->width = hdr_copier->width; }}staticDRAW_Primitive *Primitive_alloc( int num_vtxs );staticDRAW_Primitive *Primitive_alloc( int num_vtxs ){ DRAW_Primitive *prime; prime = (DRAW_Primitive *) malloc( sizeof(DRAW_Primitive) ); prime->num_info = 0; prime->info = NULL; prime->num_tcoords = num_vtxs; prime->tcoords = (double *) malloc( num_vtxs * sizeof(double) ); prime->num_ycoords = num_vtxs; prime->ycoords = (int *) malloc( num_vtxs * sizeof(int) ); return prime;}staticvoid Primitive_free( DRAW_Primitive *prime );staticvoid Primitive_free( DRAW_Primitive *prime ){ if ( prime != NULL ) { if ( prime->num_info > 0 && prime->info != NULL ) { free( prime->info ); prime->num_info = 0; prime->info = NULL; } if ( prime->num_tcoords > 0 && prime->tcoords != NULL ) { free( prime->tcoords ); prime->num_tcoords = 0; prime->tcoords = NULL; } if ( prime->num_ycoords > 0 && prime->ycoords != NULL ) { free( prime->ycoords ); prime->num_ycoords = 0; prime->ycoords = NULL; } free( prime ); }}staticDRAW_Composite *Composite_alloc( int Nprimes );staticDRAW_Composite *Composite_alloc( int Nprimes ){ DRAW_Composite *cmplx; int idx; cmplx = (DRAW_Composite *) malloc( sizeof(DRAW_Composite) ); cmplx->num_info = 0; cmplx->info = NULL; cmplx->num_primes = Nprimes; /* cmplx->primes = (DRAW_Primitive **) malloc( Nprimes * sizeof(DRAW_Primitive *) ); */ cmplx->lines = (char **) malloc( Nprimes * sizeof(char *) ); for ( idx = 0; idx < Nprimes; idx++ ) cmplx->lines[ idx ] = (char *) malloc( MAX_LINE_LEN * sizeof(char) ); return cmplx;}/*int Composite_setPrimitiveAt( DRAW_Composite *cmplx, int idx, DRAW_Primitive *prime ){ if ( cmplx == NULL ) return DRAW_FALSE; if ( idx < 0 || idx >= cmplx->num_primes ) return DRAW_FALSE; cmplx->primes[ idx ] = prime; return DRAW_TRUE;}*/staticvoid Composite_free( DRAW_Composite *cmplx );staticvoid Composite_free( DRAW_Composite *cmplx ){ int idx; if ( cmplx != NULL ) { if ( cmplx->num_info > 0 && cmplx->info != NULL ) { free( cmplx->info ); cmplx->num_info = 0; cmplx->info = NULL; } for ( idx = 0; idx < cmplx->num_primes; idx++ ) if ( cmplx->lines[ idx ] != NULL ) { free( cmplx->lines[ idx ] ); cmplx->lines[ idx ] = NULL; } /* if ( cmplx->primes[ idx ] != NULL ) { Primitive_free( cmplx->primes[ idx ] ); cmplx->primes[ idx ] = NULL; } */ cmplx->num_primes = 0; free( cmplx ); }}/* Actual TRACE-API implementation */TRACE_EXPORTchar *TRACE_Get_err_string( int ierr ){ switch ( ierr ) { case 0: return "Usage: executable_name ASCII_drawable_filename"; case 1: return "Error: fopen() fails!"; case 10: return "Maximum of Categories has been reached."; case 20: return "Cannot locate CATEGORY in the internal table."; case 21: return "TRACE_Get_next_category(): Memory violation " "detected before writing Legend.\n"; case 22: return "TRACE_Get_next_category(): Memory violation " "detected after writing Legend.\n"; case 23: return "TRACE_Get_next_category(): Memory violation " "detected before writing Label.\n"; case 24: return "TRACE_Get_next_category(): Memory violation " "detected after writing Label.\n"; case 25: return "TRACE_Get_next_category(): Memory violation " "detected before writing MethodIDs.\n"; case 26: return "TRACE_Get_next_category(): Memory violation " "detected after writing MethodIDs.\n"; case 30: return "Cannot locate PRIMITIVE in the internal table."; case 31: return "TRACE_Get_next_primitive(): Memory violation " "detected before writing ByteInfo.\n"; case 32: return "TRACE_Get_next_primitive(): Memory violation " "detected after writing ByteInfo.\n"; case 33: return "TRACE_Get_next_primitive(): Memory violation " "detected before writing Time coordinates.\n"; case 34: return "TRACE_Get_next_primitive(): Memory violation " "detected after writing Time coordinates.\n"; case 35: return "TRACE_Get_next_primitive(): Memory violation " "detected before writing Yaxis coordinates.\n"; case 36: return "TRACE_Get_next_primitive(): Memory violation " "detected after writing Yaxis coordinates.\n"; case 40: return "Cannot locate COMPOSITE in the internal table."; case 41: return "TRACE_Get_next_composite(): Memory violation " "detected before writing ByteInfo.\n"; case 42:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -