GUAC-1452: Actually write timestamps to timing file.

This commit is contained in:
Michael Jumper 2016-01-26 17:20:56 -08:00
parent 88a121f81e
commit 8a6a2a1156
2 changed files with 39 additions and 2 deletions

View File

@ -24,7 +24,10 @@
#include "guac_io.h"
#include "typescript.h"
#include <guacamole/timestamp.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
@ -63,6 +66,7 @@ guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path,
typescript->data_fd = data_fd;
typescript->timing_fd = timing_fd;
typescript->length = 0;
typescript->last_flush = guac_timestamp_current();
/* Write header */
guac_common_write(data_fd, GUAC_TERMINAL_TYPESCRIPT_HEADER,
@ -86,12 +90,37 @@ void guac_terminal_typescript_write(guac_terminal_typescript* typescript,
void guac_terminal_typescript_flush(guac_terminal_typescript* typescript) {
/* Do nothing if nothing to flush */
if (typescript->length == 0)
return;
/* Get timestamps of previous and current flush */
guac_timestamp this_flush = guac_timestamp_current();
guac_timestamp last_flush = typescript->last_flush;
/* Calculate elapsed time in seconds */
double elapsed_time = (this_flush - last_flush) / 1000.0;
/* Produce single line of timestamp output */
char timestamp_buffer[32];
int timestamp_length = snprintf(timestamp_buffer, sizeof(timestamp_buffer),
"%0.6f %i\n", elapsed_time, typescript->length);
/* Calculate actual length of timestamp line */
if (timestamp_length > sizeof(timestamp_buffer))
timestamp_length = sizeof(timestamp_buffer);
/* Write timestamp to timing file */
guac_common_write(typescript->timing_fd,
timestamp_buffer, timestamp_length);
/* Empty buffer into data file */
guac_common_write(typescript->data_fd,
typescript->buffer, typescript->length);
typescript->length = 0;
/* TODO: Write timestamp */
/* Buffer is now flushed */
typescript->length = 0;
typescript->last_flush = this_flush;
}

View File

@ -26,6 +26,8 @@
#include "config.h"
#include <guacamole/timestamp.h>
/**
* A NULL-terminated string of raw bytes which should be written at the
* beginning of any typescript.
@ -68,6 +70,12 @@ typedef struct guac_terminal_typescript {
*/
int timing_fd;
/**
* The last time that this typescript was flushed. If this typescript was
* never flushed, this will be the time the typescripe was created.
*/
guac_timestamp last_flush;
} guac_terminal_typescript;
/**