tracing.c File Reference

Trace routines for the anamod package. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "petsc.h"
#include "anamod.h"

Include dependency graph for tracing.c:

Go to the source code of this file.

Functions

PetscErrorCode AnaModDeclareTraceFunction (PetscErrorCode(*fn)(void *, char *, va_list))
PetscErrorCode AnaModDeclareTraceContext (void *ctx)
PetscErrorCode AnaModSetTraceArrays (PetscTruth f)
PetscErrorCode AnaModTraceArrays (PetscTruth *f)
PetscErrorCode AnaModTraceMessage (const char *fmt,...)
PetscErrorCode AnaModHasTrace (PetscTruth *flg)

Variables

static PetscErrorCode(* anamodtrace )(void *, char *fmt, va_list) = NULL
static size_t anamodtracectx = (size_t)NULL
static PetscTruth anamodtracearrays = PETSC_FALSE


Detailed Description

Trace routines for the anamod package.

Tracing the analysis modules

The AnaMod package does not by default print out anything, other than severe error messages (Petsc macro SETERRQ) that accompany an abort.

However, you can specify a trace function, which can further be tuned by specifying a trace context.

See AnaModDeclareTraceFunction(), AnaModDeclareTraceContext(), AnaModTraceMessage(), AnaModSetTraceArrays(), AnaModTraceArrays().

Definition in file tracing.c.


Function Documentation

PetscErrorCode AnaModDeclareTraceContext ( void *  ctx  ) 

Definition at line 69 of file tracing.c.

References anamodtracectx.

00070 {
00071   PetscFunctionBegin;
00072   anamodtracectx = (size_t)ctx;
00073   PetscFunctionReturn(0);
00074 }

PetscErrorCode AnaModDeclareTraceFunction ( PetscErrorCode(*)(void *, char *, va_list)  fn  ) 

Specify a trace function.

The trace function has a prototype

  PetscErrorCode tracefunction(void*,char*,va_list)
which means that it has an arbitrary number of arguments, much like printf. The first argument is a context, which can be set by AnaModDeclareTraceContext().

Here is an example of how you would write a trace function:

#include <stdarg.h>
PetscErrorCode tracefunction(void *ctx,char *fmt,va_list argp)
{
  char *prefix = (char*)ctx;
  PetscFunctionBegin;
  printf("%s ",prefix);
  vprintf(fmt, argp);
  PetscFunctionReturn(0);
}
Consult string.h (probably in /usr/include) to see which "v" versions of printf are available.

You can undeclare a trace function by passing NULL.

Definition at line 56 of file tracing.c.

References anamodtrace.

00057 {
00058   PetscFunctionBegin;
00059   anamodtrace = fn;
00060   PetscFunctionReturn(0);
00061 }

PetscErrorCode AnaModHasTrace ( PetscTruth *  flg  ) 

Test whether a trace function has been declared; see AnaModDeclareTraceFunction(). Normally you would use AnaModTraceMessage() which performs this test internally, but this function can be useful if a large amount of processing has to be performed to construct the trace message to begin with.

Definition at line 127 of file tracing.c.

References anamodtrace.

Referenced by ComputeQuantity(), and RetrieveQuantity().

00128 {
00129   PetscFunctionBegin;
00130   if (anamodtrace)
00131     *flg = PETSC_TRUE;
00132   else
00133     *flg = PETSC_FALSE;
00134   PetscFunctionReturn(0);
00135 }

PetscErrorCode AnaModSetTraceArrays ( PetscTruth  f  ) 

Definition at line 82 of file tracing.c.

References anamodtracearrays.

00083 {
00084   PetscFunctionBegin;
00085   anamodtracearrays = f;
00086   PetscFunctionReturn(0);
00087 }

PetscErrorCode AnaModTraceArrays ( PetscTruth *  f  ) 

Definition at line 95 of file tracing.c.

References anamodtracearrays.

Referenced by ComputeQuantity(), ReportAnamodContent(), and RetrieveQuantity().

00096 {
00097   PetscFunctionBegin;
00098   *f = anamodtracearrays;
00099   PetscFunctionReturn(0);
00100 }

PetscErrorCode AnaModTraceMessage ( const char *  fmt,
  ... 
)

This function prints a trace message if a trace function has been declared; see AnaModDeclareTraceFunction().

Definition at line 107 of file tracing.c.

References anamodtrace, and anamodtracectx.

Referenced by compute_eigenvalues_petsc(), ComputeQuantity(), and RetrieveQuantity().

00108 {
00109   va_list argp; PetscErrorCode ierr;
00110   PetscFunctionBegin;
00111   if (anamodtrace) {
00112     va_start(argp, fmt);
00113     ierr = (*anamodtrace)((void*)anamodtracectx,(char*)fmt,argp); CHKERRQ(ierr);
00114     va_end(argp);
00115   }
00116   PetscFunctionReturn(0);
00117 }


Variable Documentation

PetscErrorCode(* anamodtrace)(void *, char *fmt, va_list) = NULL [static]

PetscTruth anamodtracearrays = PETSC_FALSE [static]

Definition at line 25 of file tracing.c.

Referenced by AnaModSetTraceArrays(), and AnaModTraceArrays().

size_t anamodtracectx = (size_t)NULL [static]

Definition at line 24 of file tracing.c.

Referenced by AnaModDeclareTraceContext(), and AnaModTraceMessage().


Generated on Sun Oct 4 04:01:25 2009 for SALSA Analysis Modules by  doxygen 1.5.9