|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* hdr_histogram_log.h
|
|
rpm-build |
2ca94e |
* Written by Michael Barker and released to the public domain,
|
|
rpm-build |
2ca94e |
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* The implementation makes use of zlib to provide compression. You will need
|
|
rpm-build |
2ca94e |
* to link against -lz in order to link applications that include this header.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#ifndef HDR_HISTOGRAM_H_LOG
|
|
rpm-build |
2ca94e |
#define HDR_HISTOGRAM_H_LOG 1
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#define HDR_COMPRESSION_COOKIE_MISMATCH -29999
|
|
rpm-build |
2ca94e |
#define HDR_ENCODING_COOKIE_MISMATCH -29998
|
|
rpm-build |
2ca94e |
#define HDR_DEFLATE_INIT_FAIL -29997
|
|
rpm-build |
2ca94e |
#define HDR_DEFLATE_FAIL -29996
|
|
rpm-build |
2ca94e |
#define HDR_INFLATE_INIT_FAIL -29995
|
|
rpm-build |
2ca94e |
#define HDR_INFLATE_FAIL -29994
|
|
rpm-build |
2ca94e |
#define HDR_LOG_INVALID_VERSION -29993
|
|
rpm-build |
2ca94e |
#define HDR_TRAILING_ZEROS_INVALID -29992
|
|
rpm-build |
2ca94e |
#define HDR_VALUE_TRUNCATED -29991
|
|
rpm-build |
2ca94e |
#define HDR_ENCODED_INPUT_TOO_LONG -29990
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#include <stdint.h>
|
|
rpm-build |
2ca94e |
#include <stdbool.h>
|
|
rpm-build |
2ca94e |
#include <stdio.h>
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#include "hdr_time.h"
|
|
rpm-build |
2ca94e |
#include "hdr_histogram.h"
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#ifdef __cplusplus
|
|
rpm-build |
2ca94e |
extern "C" {
|
|
rpm-build |
2ca94e |
#endif
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Encode and compress the histogram with gzip.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Decode and decompress the histogram with gzip.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
struct hdr_log_writer
|
|
rpm-build |
2ca94e |
{
|
|
rpm-build |
2ca94e |
uint32_t nonce;
|
|
rpm-build |
2ca94e |
};
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Initialise the log writer.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param writer 'This' pointer
|
|
rpm-build |
2ca94e |
* @return 0 on success.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_writer_init(struct hdr_log_writer* writer);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Write the header to the log, this will constist of a user defined string,
|
|
rpm-build |
2ca94e |
* the current timestamp, version information and the CSV header.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param writer 'This' pointer
|
|
rpm-build |
2ca94e |
* @param file The stream to output the log header to.
|
|
rpm-build |
2ca94e |
* @param user_prefix User defined string to include in the header.
|
|
rpm-build |
2ca94e |
* @param timestamp The start time that the histogram started recording from.
|
|
rpm-build |
2ca94e |
* @return Will return 0 if it successfully completed or an error number if there
|
|
rpm-build |
2ca94e |
* was a failure. EIO if the write failed.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_write_header(
|
|
rpm-build |
2ca94e |
struct hdr_log_writer* writer,
|
|
rpm-build |
2ca94e |
FILE* file,
|
|
rpm-build |
2ca94e |
const char* user_prefix,
|
|
rpm-build |
2ca94e |
hdr_timespec* timestamp);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Write an hdr_histogram entry to the log. It will be encoded in a similar
|
|
rpm-build |
2ca94e |
* fashion to the approach used by the Java version of the HdrHistogram. It will
|
|
rpm-build |
2ca94e |
* be a CSV line consisting of <start timestamp>,<end timestamp>,<max>,<histogram>
|
|
rpm-build |
2ca94e |
* where <histogram> is the binary histogram gzip compressed and base64 encoded.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* Timestamp is a bit of misnomer for the start_timestamp and end_timestamp values
|
|
rpm-build |
2ca94e |
* these could be offsets, e.g. start_timestamp could be offset from process start
|
|
rpm-build |
2ca94e |
* time and end_timestamp could actually be the length of the recorded interval.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param writer 'This' pointer
|
|
rpm-build |
2ca94e |
* @param file The stream to write the entry to.
|
|
rpm-build |
2ca94e |
* @param start_timestamp The start timestamp to include in the logged entry.
|
|
rpm-build |
2ca94e |
* @param end_timestamp The end timestamp to include in the logged entry.
|
|
rpm-build |
2ca94e |
* @param histogram The histogram to encode and log.
|
|
rpm-build |
2ca94e |
* @return Will return 0 if it successfully completed or an error number if there
|
|
rpm-build |
2ca94e |
* was a failure. Errors include HDR_DEFLATE_INIT_FAIL, HDR_DEFLATE_FAIL if
|
|
rpm-build |
2ca94e |
* something when wrong during gzip compression. ENOMEM if we failed to allocate
|
|
rpm-build |
2ca94e |
* or reallocate the buffer used for encoding (out of memory problem). EIO if
|
|
rpm-build |
2ca94e |
* write failed.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_write(
|
|
rpm-build |
2ca94e |
struct hdr_log_writer* writer,
|
|
rpm-build |
2ca94e |
FILE* file,
|
|
rpm-build |
2ca94e |
const hdr_timespec* start_timestamp,
|
|
rpm-build |
2ca94e |
const hdr_timespec* end_timestamp,
|
|
rpm-build |
2ca94e |
struct hdr_histogram* histogram);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
struct hdr_log_reader
|
|
rpm-build |
2ca94e |
{
|
|
rpm-build |
2ca94e |
int major_version;
|
|
rpm-build |
2ca94e |
int minor_version;
|
|
rpm-build |
2ca94e |
hdr_timespec start_timestamp;
|
|
rpm-build |
2ca94e |
};
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Initialise the log reader.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param reader 'This' pointer
|
|
rpm-build |
2ca94e |
* @return 0 on success
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_reader_init(struct hdr_log_reader* reader);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Reads the the header information from the log. Will capure information
|
|
rpm-build |
2ca94e |
* such as version number and start timestamp from the header.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param hdr_log_reader 'This' pointer
|
|
rpm-build |
2ca94e |
* @param file The data stream to read from.
|
|
rpm-build |
2ca94e |
* @return 0 on success. An error number on failure.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Reads an entry from the log filling in the specified histogram, timestamp and
|
|
rpm-build |
2ca94e |
* interval values. If the supplied pointer to the histogram for this method is
|
|
rpm-build |
2ca94e |
* NULL then a new histogram will be allocated for the caller, however it will
|
|
rpm-build |
2ca94e |
* become the callers responsibility to free it later. If the pointer is non-null
|
|
rpm-build |
2ca94e |
* the histogram read from the log will be merged with the supplied histogram.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param reader 'This' pointer
|
|
rpm-build |
2ca94e |
* @param file The stream to read the histogram from.
|
|
rpm-build |
2ca94e |
* @param histogram Pointer to allocate a histogram to or merge into.
|
|
rpm-build |
2ca94e |
* @param timestamp The first timestamp from the CSV entry.
|
|
rpm-build |
2ca94e |
* @param interval The second timestamp from the CSV entry
|
|
rpm-build |
2ca94e |
* @return Will return 0 on success or an error number if there was some wrong
|
|
rpm-build |
2ca94e |
* when reading in the histogram. EOF (-1) will indicate that there are no more
|
|
rpm-build |
2ca94e |
* histograms left to be read from 'file'.
|
|
rpm-build |
2ca94e |
* HDR_INFLATE_INIT_FAIL or HDR_INFLATE_FAIL if
|
|
rpm-build |
2ca94e |
* there was a problem with Gzip. HDR_COMPRESSION_COOKIE_MISMATCH or
|
|
rpm-build |
2ca94e |
* HDR_ENCODING_COOKIE_MISMATCH if the cookie values are incorrect.
|
|
rpm-build |
2ca94e |
* HDR_LOG_INVALID_VERSION if the log can not be parsed. ENOMEM if buffer space
|
|
rpm-build |
2ca94e |
* or the histogram can not be allocated. EIO if there was an error during
|
|
rpm-build |
2ca94e |
* the read. EINVAL in any input values are incorrect.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
int hdr_log_read(
|
|
rpm-build |
2ca94e |
struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
|
|
rpm-build |
2ca94e |
hdr_timespec* timestamp, hdr_timespec* interval);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
/**
|
|
rpm-build |
2ca94e |
* Returns a string representation of the error number.
|
|
rpm-build |
2ca94e |
*
|
|
rpm-build |
2ca94e |
* @param errnum The error response from a previous call.
|
|
rpm-build |
2ca94e |
* @return The user readable representation of the error.
|
|
rpm-build |
2ca94e |
*/
|
|
rpm-build |
2ca94e |
const char* hdr_strerror(int errnum);
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#ifdef __cplusplus
|
|
rpm-build |
2ca94e |
}
|
|
rpm-build |
2ca94e |
#endif
|
|
rpm-build |
2ca94e |
|
|
rpm-build |
2ca94e |
#endif
|