/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*------------------------------------------------------------------------- * * Created: H5trace.c * Aug 21 2006 * Quincey Koziol * * Purpose: Internal code for tracing API calls * *------------------------------------------------------------------------- */ /****************/ /* Module Setup */ /****************/ #define H5I_PACKAGE /*suppress error about including H5Ipkg */ /***********/ /* Headers */ /***********/ #include "H5private.h" /* Generic Functions */ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5FDprivate.h" /* File drivers */ #include "H5Ipkg.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ #ifdef H5_HAVE_PARALLEL /* datatypes of predefined drivers needed by H5_trace() */ #include "H5FDmpio.h" #endif /* H5_HAVE_PARALLEL */ /****************/ /* Local Macros */ /****************/ /******************/ /* Local Typedefs */ /******************/ /********************/ /* Package Typedefs */ /********************/ /********************/ /* Local Prototypes */ /********************/ /*********************/ /* Package Variables */ /*********************/ /*****************************/ /* Library Private Variables */ /*****************************/ /*******************/ /* Local Variables */ /*******************/ /*------------------------------------------------------------------------- * Function: H5_trace * * Purpose: This function is called whenever an API function is called * and tracing is turned on. If RETURNING is non-zero then * the caller is about to return and RETURNING points to the * time for the corresponding function call event. Otherwise * we print the function name and the arguments. * * The TYPE argument is a string which gives the type of each of * the following argument pairs. Each type is zero or more * asterisks (one for each level of indirection, although some * types have one level of indirection already implied) followed * by either one letter (lower case) or two letters (first one * uppercase). * * The variable argument list consists of pairs of values. Each * pair is a string which is the formal argument name in the * calling function, followed by the argument value. The type * of the argument value is given by the TYPE string. * * Note: The TYPE string is meant to be terse and is generated by a * separate perl script. * * WARNING: DO NOT CALL ANY HDF5 FUNCTION THAT CALLS FUNC_ENTER(). DOING * SO MAY CAUSE H5_trace() TO BE INVOKED RECURSIVELY OR MAY * CAUSE LIBRARY INITIALIZATIONS THAT ARE NOT DESIRED. * * Return: void * * Programmer: Robb Matzke * Tuesday, June 16, 1998 * * Modifications: * Robb Matzke, 1999-08-02 * Added the `a' type letter for haddr_t arguments and `Mt' for * H5FD_mem_t arguments. * * Robb Matzke, 1999-10-25 * The `Ej' and `En' types are H5E_major_t and H5E_minor_t error * types. We only print the integer value here. * * Robb Matzke, 2002-08-08 * Better output for nested calls. Show only top-level calls * if so desired. Show event times if so desired. *------------------------------------------------------------------------- */ double H5_trace (const double *returning, const char *func, const char *type, ...) { va_list ap; char buf[64], *rest; const char *argname; int argno=0, ptr, asize_idx; hssize_t asize[16]; hssize_t i; void *vp = NULL; FILE *out = H5_debug_g.trace; H5_timer_t event_time; static H5_timer_t first_time = {0.0, 0.0, 0.0}; static int current_depth=0; static int last_call_depth=0; /* FUNC_ENTER() should not be called */ if (!out) return 0.0; /*tracing is off*/ va_start (ap, type); if (H5_debug_g.ttop) { if (returning) { if (current_depth>1) { --current_depth; return 0.0; } } else { if (current_depth>0) { /*do not update last_call_depth*/ current_depth++; return 0.0; } } } /* Get tim for event */ if (fabs(first_time.etime) < 0.0000000001) /* That is == 0.0, but direct comparison between floats is bad */ H5_timer_begin(&first_time); if (H5_debug_g.ttimes) { H5_timer_begin(&event_time); } else { HDmemset(&event_time, 0, sizeof event_time); } /* Print the first part of the line. This is the indication of the * nesting depth followed by the function name and either start of * argument list or start of return value. If this call is for a * function return and no other calls have been made to H5_trace() * since the one for the function call, then we're continuing * the same line. */ if (returning) { assert(current_depth>0); --current_depth; if (current_depth\n", out); if (H5_debug_g.ttimes) fprintf(out, "@%.6f ", event_time.etime-first_time.etime); for (i=0; i=0) fprintf (out, "SUCCEED"); else fprintf (out, "FAIL"); } break; case 'E': switch (type[1]) { case 'd': if (ptr) { if (vp) { fprintf (out, "0x%lx", (unsigned long)vp); } else { fprintf(out, "NULL"); } } else { H5E_direction_t direction = va_arg (ap, H5E_direction_t); /*lint !e64 Type mismatch not really occuring */ switch (direction) { case H5E_WALK_UPWARD: fprintf (out, "H5E_WALK_UPWARD"); break; case H5E_WALK_DOWNWARD: fprintf (out, "H5E_WALK_DOWNWARD"); break; default: fprintf (out, "%ld", (long)direction); break; } } break; case 'e': if (ptr) { if (vp) { fprintf (out, "0x%lx", (unsigned long)vp); } else { fprintf(out, "NULL"); } } else { H5E_error_stack_t *error = va_arg (ap, H5E_error_stack_t*); /*lint !e64 Type mismatch not really occuring */ fprintf (out, "0x%lx", (unsigned long)error); } break; case 't': if (ptr) { if (vp) { fprintf (out, "0x%lx", (unsigned long)vp); } else { fprintf(out, "NULL"); } } else { H5E_type_t etype = va_arg (ap, H5E_type_t); /*lint !e64 Type mismatch not really occuring */ switch (etype) { case H5E_MAJOR: fprintf (out, "H5E_MAJOR"); break; case H5E_MINOR: fprintf (out, "H5E_MINOR"); break; default: fprintf (out, "%ld", (long)etype); break; } } break; default: fprintf (out, "BADTYPE(E%c)", type[1]); goto error; } break; case 'F': switch(type[1]) { case 'd': if(ptr) { if(vp) fprintf(out, "0x%lx", (unsigned long)vp); else fprintf(out, "NULL"); } else { H5F_close_degree_t degree = va_arg(ap, H5F_close_degree_t); /*lint !e64 Type mismatch not really occuring */ switch(degree) { case H5F_CLOSE_DEFAULT: fprintf(out, "H5F_CLOSE_DEFAULT"); break; case H5F_CLOSE_WEAK: fprintf(out, "H5F_CLOSE_WEAK"); break; case H5F_CLOSE_SEMI: fprintf(out, "H5F_CLOSE_SEMI"); break; case H5F_CLOSE_STRONG: fprintf(out, "H5F_CLOSE_STRONG"); break; } } break; case 's': if(ptr) { if(vp) fprintf(out, "0x%lx", (unsigned long)vp); else fprintf(out, "NULL"); } else { H5F_scope_t scope = va_arg(ap, H5F_scope_t); /*lint !e64 Type mismatch not really occuring */ switch(scope) { case H5F_SCOPE_LOCAL: fprintf(out, "H5F_SCOPE_LOCAL"); break; case H5F_SCOPE_GLOBAL: fprintf(out, "H5F_SCOPE_GLOBAL"); break; case H5F_SCOPE_DOWN: fprintf(out, "H5F_SCOPE_DOWN " "/*FOR INTERNAL USE ONLY!*/"); break; } } break; default: fprintf(out, "BADTYPE(F%c)", type[1]); goto error; } break; case 'G': switch(type[1]) { case 'o': if(ptr) { if(vp) fprintf (out, "0x%lx", (unsigned long)vp); else fprintf(out, "NULL"); } else { H5G_obj_t obj_type = va_arg(ap, H5G_obj_t); /*lint !e64 Type mismatch not really occuring */ switch(obj_type) { case H5G_UNKNOWN: fprintf(out, "H5G_UNKNOWN"); break; case H5G_LINK: fprintf(out, "H5G_LINK"); break; case H5G_UDLINK: fprintf(out, "H5G_UDLINK"); break; case H5G_GROUP: fprintf(out, "H5G_GROUP"); break; case H5G_DATASET: fprintf(out, "H5G_DATASET"); break; case H5G_TYPE: fprintf(out, "H5G_TYPE"); break; case H5G_RESERVED_5: case H5G_RESERVED_6: case H5G_RESERVED_7: fprintf(out, "H5G_RESERVED(%ld)",(long)obj_type); break; default: fprintf(out, "%ld", (long)obj_type); break; } } break; case 's': if(ptr) { if(vp) fprintf (out, "0x%lx", (unsigned long)vp); else fprintf(out, "NULL"); } else { H5G_stat_t *statbuf = va_arg(ap, H5G_stat_t*); /*lint !e64 Type mismatch not really occuring */ fprintf(out, "0x%lx", (unsigned long)statbuf); } break; default: fprintf(out, "BADTYPE(G%c)", type[1]); goto error; } break; case 'h': if (ptr) { if (vp) { fprintf (out, "0x%lx", (unsigned long)vp); if (asize_idx>=0 && asize[asize_idx]>=0) { hsize_t *p = (hsize_t*)vp; fprintf(out, " {"); for (i=0; i=0 && asize[asize_idx]>=0) { hssize_t *p = (hssize_t*)vp; fprintf(out, " {"); for (i=0; i=0 && asize[asize_idx]>=0) { int *p = (int*)vp; fprintf(out, " {"); for (i=0; i=0 && asize[asize_idx]>=0) { unsigned *p = (unsigned*)vp; fprintf(out, " {"); for (i=0; i0) fprintf (out, "TRUE"); else if (!tri_var) fprintf (out, "FALSE"); else fprintf (out, "FAIL(%d)", (int)tri_var); } break; case 'x': if (ptr) { if (vp) { fprintf (out, "0x%lx", (unsigned long)vp); if (asize_idx>=0 && asize[asize_idx]>=0) { void **p = (void**)vp; fprintf(out, " {"); for (i=0; i=0 && asize[asize_idx]>=0) { size_t *p = (size_t*)vp; fprintf(out, " {"); for (i=0; i=0 && asize[asize_idx]>=0) { ssize_t *p = (ssize_t*)vp; fprintf(out, " {"); for (i=0; i