reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
trace_util.c File Reference
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "reactor.h"
#include "trace.h"
#include "trace_util.h"
#include "trace_impl.h"

Data Structures

struct  open_file_t
 

Macros

#define LF_TRACE
 

Typedefs

typedef struct open_file_t open_file_t
 

Functions

void termination ()
 Perform final wrap-up on exit.
 
charroot_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.
 
FILEopen_file (const char *path, const char *mode)
 Open the specified file for reading or writing. This function records the file for closing at termination.
 
charget_object_description (void *pointer, int *index)
 
charget_trigger_name (void *trigger, int *index)
 
void print_table ()
 
size_t read_header ()
 
int read_trace ()
 

Variables

char buffer [BUFFER_SIZE]
 
trace_record_t trace [TRACE_BUFFER_CAPACITY]
 
instant_t start_time
 
chartop_level = NULL
 
object_description_tobject_table
 
int object_table_size = 0
 
open_file_t_open_files = NULL
 
const chartrace_event_names []
 
const char PATH_SEPARATOR
 

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.

Functions intitializing and freeing memory for environments.

Standalone program to convert a Lingua Franca trace file to a comma-separated values text file.

Macro Definition Documentation

◆ LF_TRACE

#define LF_TRACE

Typedef Documentation

◆ open_file_t

typedef struct open_file_t open_file_t

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-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.

◆ termination()

void termination ( void )

Perform final wrap-up on exit.

Function to be invoked upon exiting.

Variable Documentation

◆ _open_files

open_file_t* _open_files = NULL

◆ buffer

char buffer[BUFFER_SIZE]

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

◆ object_table

object_description_t* object_table

Table of pointers to the self struct of a reactor.

◆ object_table_size

int object_table_size = 0

◆ PATH_SEPARATOR

const char PATH_SEPARATOR
Initial value:
=
'/'

◆ start_time

instant_t start_time

The start time read from the trace file.

◆ top_level

char* top_level = NULL

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

◆ trace

Buffer for reading trace records.

◆ trace_event_names

const char* trace_event_names[]

String description of event types.