OpenMPI  0.1.1
OTF_RBuffer.h File Reference

Provides read access to trace buffers. More...

#include <stdlib.h>
#include <stdio.h>
#include "OTF_inttypes.h"
#include "OTF_File.h"
#include "OTF_KeyValue.h"

Go to the source code of this file.

Data Structures

struct  struct_OTF_RBuffer
 

Macros

#define PARSE_ERROR(buffer)
 

Typedefs

typedef struct struct_OTF_RBuffer OTF_RBuffer
 

Functions

OTF_RBufferOTF_RBuffer_open (const char *filename, OTF_FileManager *manager)
 constructor - internal use only
 
OTF_RBufferOTF_RBuffer_open_with_external_buffer (uint32_t len, const char *buffer, uint8_t is_compressed)
 constructor - internal use only – special version with a memory buffer to read from instead of an input file, either compressed or uncompressed
 
int OTF_RBuffer_close (OTF_RBuffer *rbuffer)
 destructor - internal use only
 
int OTF_RBuffer_setSize (OTF_RBuffer *rbuffer, size_t size)
 Set buffer size. More...
 
void OTF_RBuffer_setZBufferSize (OTF_RBuffer *rbuffer, uint32_t size)
 Set zbuffer size. More...
 
int OTF_RBuffer_setJumpSize (OTF_RBuffer *rbuffer, size_t size)
 Set 'jumpsize'. More...
 
char * OTF_RBuffer_getRecord (OTF_RBuffer *rbuffer)
 Make the next record availabe from the buffer. More...
 
int OTF_RBuffer_guaranteeRecord (OTF_RBuffer *rbuffer)
 Ask the buffer to guarantee at least one complete record at the current read position inside the buffer. More...
 
char * OTF_RBuffer_printRecord (OTF_RBuffer *rbuffer)
 Print the record at the current buffer position, i.e. More...
 
int OTF_RBuffer_jump (OTF_RBuffer *rbuffer, uint64_t filepos)
 Jump to the given file position and restore buffer and references as if the buffer had reached the position by advancing through the file linearly. More...
 
uint64_t OTF_RBuffer_readUint64 (OTF_RBuffer *rbuffer)
 Read an 64bit unsigned integer in hex format from buffer and return it. More...
 
uint32_t OTF_RBuffer_readUint32 (OTF_RBuffer *rbuffer)
 Read an unsigned integer in hex format from buffer and return it. More...
 
const char * OTF_RBuffer_readString (OTF_RBuffer *rbuffer)
 Read a string from buffer and return it. More...
 
uint32_t OTF_RBuffer_readArray (OTF_RBuffer *rbuffer, uint32_t **array, uint32_t *size)
 Read an array from buffer and return the number of elements. More...
 
int OTF_RBuffer_testChar (OTF_RBuffer *rbuffer, char c)
 Test if the next character equals the given one (leading spaces are ignored). More...
 
int OTF_RBuffer_testKeyword (OTF_RBuffer *rbuffer, const char *string)
 Test if the next string equals the given one (leading spaces are ignored). More...
 
int OTF_RBuffer_testPrefix (OTF_RBuffer *rbuffer, const char *string)
 Test if the next string equals the given one (leading spaces are ignored). More...
 
int OTF_RBuffer_readNewline (OTF_RBuffer *rbuffer)
 Read a newline such that the buffer pos is at the next record beginning. More...
 
void OTF_RBuffer_skipSpaces (OTF_RBuffer *rbuffer)
 Advance the buffer position while there are spaces. More...
 
void OTF_RBuffer_skipKeyword (OTF_RBuffer *rbuffer)
 Advance the buffer position while there are capital letters. More...
 
uint64_t OTF_RBuffer_getCurrentTime (OTF_RBuffer *rbuffer)
 Return the current time of the buffer. More...
 
void OTF_RBuffer_setCurrentTime (OTF_RBuffer *rbuffer, uint64_t time)
 Set the current time of the buffer to the given one. More...
 
uint32_t OTF_RBuffer_getCurrentProcess (OTF_RBuffer *rbuffer)
 Return the current process of the buffer. More...
 
void OTF_RBuffer_setCurrentProcess (OTF_RBuffer *rbuffer, uint32_t process)
 Set the current process of the buffer to the given one. More...
 
int OTF_RBuffer_searchTime (OTF_RBuffer *rbuffer, uint64_t time)
 Search the buffer for the given time and set the buffer position to the next record after that time. More...
 
int OTF_RBuffer_getFileProperties (OTF_RBuffer *rbuffer)
 Determine buffers filesize, firstTime and lastTime if not already set. More...
 
uint64_t OTF_RBuffer_getFileSize (OTF_RBuffer *rbuffer)
 Returns the filesize of the file attached to this buffer.
 
uint64_t OTF_RBuffer_getFilePos (OTF_RBuffer *rbuffer)
 Returns the fileposition of the file attached to this buffer.
 
uint32_t OTF_RBuffer_readBytes (OTF_RBuffer *rbuffer, uint8_t *array, uint32_t max_len)
 Read a byte array in hex format from buffer and return the number of bytes read (=lenght of array). More...
 
uint32_t OTF_RBuffer_readKeyValueList (OTF_RBuffer *buffer)
 Read a KeyValueList from the buffer. More...
 

Detailed Description

Provides read access to trace buffers.

Macro Definition Documentation

#define PARSE_ERROR (   buffer)
Value:
OTF_Error( "Parse error in function %s, file: %s, line: %i:\n %s\n", \
__FUNCTION__, __FILE__, __LINE__, OTF_RBuffer_printRecord( buffer ) );
char * OTF_RBuffer_printRecord(OTF_RBuffer *rbuffer)
Print the record at the current buffer position, i.e.
Definition: OTF_RBuffer.c:550

Function Documentation

uint32_t OTF_RBuffer_getCurrentProcess ( OTF_RBuffer rbuffer)

Return the current process of the buffer.

References struct_OTF_RBuffer::process.

uint64_t OTF_RBuffer_getCurrentTime ( OTF_RBuffer rbuffer)

Return the current time of the buffer.

References struct_OTF_RBuffer::time.

int OTF_RBuffer_getFileProperties ( OTF_RBuffer rbuffer)

Determine buffers filesize, firstTime and lastTime if not already set.

Return 1 on success, 0 on error.

Determine buffers filesize, firstTime and lastTime if not already set.

Return 1 on success, 0 on error.

if both are != -1 we assume everything is fine and return successful. otherwise we go fetching both.

References struct_OTF_RBuffer::filesize, struct_OTF_RBuffer::firstTime, struct_OTF_RBuffer::lastTime, OTF_File_size(), OTF_RBuffer_getRecord(), OTF_RBuffer_jump(), OTF_RBuffer_readNewline(), struct_OTF_RBuffer::size, and struct_OTF_RBuffer::time.

Referenced by OTF_RBuffer_searchTime(), OTF_Reader_readEvents(), OTF_Reader_readEventsUnsorted(), OTF_Reader_readSnapshots(), OTF_Reader_readSnapshotsUnsorted(), OTF_Reader_readStatistics(), and OTF_Reader_readStatisticsUnsorted().

char* OTF_RBuffer_getRecord ( OTF_RBuffer rbuffer)

Make the next record availabe from the buffer.

Return the pointer to the record string which is terminated by '
' not '\0' ! This funktion must be called before any record access. It ensures the record is available completely in the buffer. Furthermore, time and process information is kept track of. It is recommended to use the 'OTF_RBuffer_readXXX()' functions below to read record components instead of parsing manually. In any case, after reading 'OTF_RBuffer_readNewline()' needs to be called which proceeds to the next record begin no matter if there are still characters from the current record present or not.

Make the next record availabe from the buffer.

return the pointer to the record string which is terminated by '
' not '\0' ! rbuffer funktion must be called before any record access. it ensures the record is available completely in the buffer. furthermore, time and process information is kept track of. It is recommended to use the 'OTF_RBuffer_readXXX()' functions below to read record components instead of parsing manually. In any case, after reading 'OTF_RBuffer_readNewline()' needs to be called which proceeds to the next record begin no matter if there are still characters from the current record present or not.

References struct_OTF_RBuffer::buffer, OTF_RBuffer_guaranteeRecord(), and struct_OTF_RBuffer::pos.

Referenced by OTF_RBuffer_getFileProperties(), OTF_RBuffer_searchTime(), OTF_Reader_readDefinitions(), OTF_Reader_readEvents(), OTF_Reader_readEventsUnsorted(), OTF_Reader_readMarkers(), OTF_Reader_readSnapshots(), OTF_Reader_readSnapshotsUnsorted(), OTF_Reader_readStatistics(), OTF_Reader_readStatisticsUnsorted(), OTF_RStream_readDefinitions(), OTF_RStream_readEvents(), OTF_RStream_readMarker(), OTF_RStream_readSnapshots(), and OTF_RStream_readStatistics().

int OTF_RBuffer_guaranteeRecord ( OTF_RBuffer rbuffer)

Ask the buffer to guarantee at least one complete record at the current read position inside the buffer.

This means one line, e.g. '
' character. If no complete record is found the buffer has to be advanced by reading new contents from file. Return 1 on success, 0 means the file is exceeded.

References struct_OTF_RBuffer::lastnewline, OTF_RBuffer_setSize(), struct_OTF_RBuffer::pos, and struct_OTF_RBuffer::size.

Referenced by OTF_MasterControl_read(), OTF_RBuffer_getRecord(), and OTF_RBuffer_jump().

int OTF_RBuffer_jump ( OTF_RBuffer rbuffer,
uint64_t  filepos 
)

Jump to the given file position and restore buffer and references as if the buffer had reached the position by advancing through the file linearly.

In particular, find the next record start, then find next timestamp and process specification in order to set 'time' and 'process' to true values. Return error code 1 on success. Otherwise the file is not that large or there are no appropriate time and process specifications on the tail of the file. Then the buffer contents is undefined

In particular, find the next record start, then find next timestamp and process specification in order to set 'time' and 'process' to true values. Return 1 on success. Otherwise, when 0 is returned the file is not that large or there are no appropriate time and process specifications on the tail of the file. Then the buffer contents is undefined!

References struct_OTF_RBuffer::buffer, struct_OTF_RBuffer::end, struct_OTF_RBuffer::jumpsize, struct_OTF_RBuffer::lastnewline, OTF_File_read(), OTF_File_seek(), OTF_RBuffer_guaranteeRecord(), OTF_RBuffer_readNewline(), struct_OTF_RBuffer::pos, struct_OTF_RBuffer::process, and struct_OTF_RBuffer::time.

Referenced by OTF_RBuffer_getFileProperties(), and OTF_RBuffer_searchTime().

char* OTF_RBuffer_printRecord ( OTF_RBuffer rbuffer)

Print the record at the current buffer position, i.e.

until the next newline character. This is for debugging purposes only and won't modify the buffer in any way.

References struct_OTF_RBuffer::buffer, and struct_OTF_RBuffer::pos.

uint32_t OTF_RBuffer_readArray ( OTF_RBuffer rbuffer,
uint32_t **  array,
uint32_t *  size 
)

Read an array from buffer and return the number of elements.

(re)malloc memory for *array internally, needs to be freed by caller

References struct_OTF_RBuffer::buffer, OTF_RBuffer_readUint32(), OTF_RBuffer_skipSpaces(), OTF_RBuffer_testChar(), and struct_OTF_RBuffer::pos.

uint32_t OTF_RBuffer_readBytes ( OTF_RBuffer rbuffer,
uint8_t *  array,
uint32_t  max_len 
)

Read a byte array in hex format from buffer and return the number of bytes read (=lenght of array).

If the return value is greater than max_len, there is more to read (this indicates an error in some cases!).

References struct_OTF_RBuffer::buffer, OTF_RBuffer_skipSpaces(), and struct_OTF_RBuffer::pos.

Referenced by OTF_RBuffer_readKeyValueList().

const char* OTF_RBuffer_readString ( OTF_RBuffer rbuffer)
uint32_t OTF_RBuffer_readUint32 ( OTF_RBuffer rbuffer)

Read an unsigned integer in hex format from buffer and return it.

References struct_OTF_RBuffer::buffer, OTF_RBuffer_skipSpaces(), and struct_OTF_RBuffer::pos.

Referenced by OTF_MasterControl_read(), OTF_RBuffer_readArray(), and OTF_RBuffer_readKeyValueList().

uint64_t OTF_RBuffer_readUint64 ( OTF_RBuffer rbuffer)

Read an 64bit unsigned integer in hex format from buffer and return it.

References struct_OTF_RBuffer::buffer, OTF_RBuffer_skipSpaces(), and struct_OTF_RBuffer::pos.

Referenced by OTF_RBuffer_readKeyValueList().

void OTF_RBuffer_setCurrentProcess ( OTF_RBuffer rbuffer,
uint32_t  process 
)

Set the current process of the buffer to the given one.

References struct_OTF_RBuffer::process.

void OTF_RBuffer_setCurrentTime ( OTF_RBuffer rbuffer,
uint64_t  time 
)

Set the current time of the buffer to the given one.

References struct_OTF_RBuffer::time.

int OTF_RBuffer_setJumpSize ( OTF_RBuffer rbuffer,
size_t  size 
)

Set 'jumpsize'.

Return 0 if 'size' is greater than the buffer size.

References struct_OTF_RBuffer::jumpsize, and struct_OTF_RBuffer::size.

void OTF_RBuffer_skipKeyword ( OTF_RBuffer rbuffer)

Advance the buffer position while there are capital letters.

References struct_OTF_RBuffer::buffer, and struct_OTF_RBuffer::pos.

Referenced by OTF_Reader_parseDefRecord(), OTF_Reader_parseEventRecord(), and OTF_Reader_parseMarkerRecord().

int OTF_RBuffer_testChar ( OTF_RBuffer rbuffer,
char  c 
)

Test if the next character equals the given one (leading spaces are ignored).

If the right character is found return 1, and advance by 1 step. If the character was not found, keep the buffer position such that the test can be repeated with another character.

References struct_OTF_RBuffer::buffer, struct_OTF_RBuffer::end, OTF_RBuffer_skipSpaces(), and struct_OTF_RBuffer::pos.

Referenced by OTF_MasterControl_read(), OTF_RBuffer_readArray(), and OTF_RBuffer_readString().

int OTF_RBuffer_testKeyword ( OTF_RBuffer rbuffer,
const char *  string 
)

Test if the next string equals the given one (leading spaces are ignored).

The next character must not be an uppercase letter as used in keywords. If the right string is found return 1, and advance the buffer position. If the string was not found, keep the buffer position such that the test can be repeated with another string.

References struct_OTF_RBuffer::buffer, OTF_RBuffer_skipSpaces(), and struct_OTF_RBuffer::pos.

Referenced by OTF_RBuffer_readKeyValueList(), OTF_Reader_parseDefRecord(), OTF_Reader_parseEventRecord(), OTF_Reader_parseMarkerRecord(), OTF_Reader_parseSnapshotsRecord(), and OTF_Reader_parseStatisticsRecord().

int OTF_RBuffer_testPrefix ( OTF_RBuffer rbuffer,
const char *  string 
)

Test if the next string equals the given one (leading spaces are ignored).

This version is similar to the above function but does not test the following character, i.e. it can be used to test for prefixes. If the right string is found return 1, and advance the buffer position. If the string was not found, keep the buffer position such that the test can be repeated with another string.

References struct_OTF_RBuffer::buffer, OTF_RBuffer_skipSpaces(), and struct_OTF_RBuffer::pos.

Referenced by OTF_Reader_parseDefRecord(), OTF_Reader_parseMarkerRecord(), OTF_Reader_parseSnapshotsRecord(), and OTF_Reader_parseStatisticsRecord().