reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
trace_util.h File Reference
#include "reactor.h"
#include "trace.h"

Go to the source code of this file.

Macros

#define LF_TRACE
 
#define _LF_TRACE_FAILURE(trace_file)
 
#define BUFFER_SIZE   1024
 

Functions

void usage ()
 
char * root_name (const char *path)
 Return the root file name from the given path. Given a path to a file, this function returns a dynamically allocated string (which you must free) that points to the root filename without the preceding path and without the file extension.
 
FILE * open_file (const char *path, const char *mode)
 Open the specified file for reading or writing. This function records the file for closing at termination.
 
char * get_object_description (void *reactor, int *index)
 
char * get_trigger_name (void *trigger, int *index)
 
void print_table ()
 
size_t read_header ()
 
int read_trace ()
 

Variables

const char * trace_event_names []
 
trace_record_t trace []
 
FILE * trace_file
 
FILE * output_file
 
FILE * summary_file
 
instant_t start_time
 
object_description_tobject_table
 
int object_table_size
 
char * top_level
 

Detailed Description

Author
Edward A. Lee

LICENSE

Copyright (c) 2020, The University of California at Berkeley

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DESCRIPTION

Header file for common utilities used in converting Lingua Franca trace files into other formats.

Macro Definition Documentation

◆ _LF_TRACE_FAILURE

#define _LF_TRACE_FAILURE ( trace_file)
Value:
do { \
fprintf(stderr, "ERROR: Access to trace file failed.\n"); \
fclose(trace_file); \
trace_file = NULL; \
exit(1); \
} while (0)
FILE * trace_file
Definition trace_to_chrome.c:50

Macro to use when access to trace file fails.

◆ BUFFER_SIZE

#define BUFFER_SIZE   1024

Buffer for reading object descriptions. Size limit is BUFFER_SIZE bytes.

◆ LF_TRACE

#define LF_TRACE

Function Documentation

◆ get_object_description()

char * get_object_description ( void * pointer,
int * index )

Get the description of the object pointed to by the specified pointer. For example, this can be the name of a reactor (pointer points to the self struct) or a user-defined string. If there is no such pointer in the symbol table, return NULL. If the index argument is non-null, then put the index of the entry in the table into the int pointed to or -1 if none was found.

Parameters
pointerThe pointer to to an object, e.g. a self struct.
indexAn optional pointer into which to write the index.

Get the description of the object pointed to by the specified pointer. For example, this can be the name of a reactor (pointer points to the self struct) or a user-define string. If there is no such pointer in the symbol table, return NULL. If the index argument is non-null, then put the index of the entry in the table into the int pointed to or -1 if none was found.

Parameters
pointerThe pointer to to an object, e.g. a self struct.
indexAn optional pointer into which to write the index.

◆ get_trigger_name()

char * get_trigger_name ( void * trigger,
int * index )

Get the trigger name for the specified pointer. If there is no such trigger, return NULL. If the index argument is non-null, then put the index of the trigger in the table into the int pointed to or -1 if none was found.

Parameters
reactorThe pointer to a self struct.
indexAn optional pointer into which to write the index.

◆ open_file()

FILE * open_file ( const char * path,
const char * mode )

Open the specified file for reading or writing. This function records the file for closing at termination.

Parameters
pathThe path to the file.
mode"r" for reading and "w" for writing.
Returns
A pointer to the open file or NULL for failure.

◆ print_table()

void print_table ( )

Print the object to description table.

◆ read_header()

size_t read_header ( )

Read header information.

Returns
The number of objects in the object table or -1 for failure.

◆ read_trace()

int read_trace ( )

Read the trace from the trace_file and put it in the trace global variable. Return the length of the trace.

Returns
The number of trace record read or 0 upon seeing an EOF.

◆ root_name()

char * root_name ( const char * path)

Return the root file name from the given path. Given a path to a file, this function returns a dynamically allocated string (which you must free) that points to the root filename without the preceding path and without the file extension.

Parameters
pathThe path including the full filename.
Returns
The root name of the file or NULL for failure.

◆ usage()

void usage ( )

Print a usage message.

Variable Documentation

◆ object_table

object_description_t* object_table
extern

Table of pointers to a description of the object.

Table of pointers to the self struct of a reactor.

◆ object_table_size

int object_table_size
extern

◆ output_file

FILE* output_file
extern

File for writing the output data.

◆ start_time

instant_t start_time
extern

The start time read from the trace file.

◆ summary_file

FILE* summary_file
extern

File for writing summary statistics.

◆ top_level

char* top_level
extern

Name of the top-level reactor (first entry in symbol table).

◆ trace

trace_record_t trace[]
extern

Buffer for reading trace records.

◆ trace_event_names

const char* trace_event_names[]
extern

String description of event types.

◆ trace_file

FILE* trace_file
extern

File containing the trace binary data.