Commit e35be972 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Give access to blc_loop_timer which contain the time of the beginning of the loop

parent 4eb1e191
......@@ -37,6 +37,12 @@ Few functions helping for pseudo realtime applications.
typedef enum {BLC_QUIT=0, BLC_RUN, BLC_PAUSE, BLC_STEPS} type_blc_status;
typedef void (*type_blc_command_cb)(char const *argument, void *user_data);
/** Timer updated by blc_command_loop_start and blc_command_loop_end (i.e. BLC_LOOP_FOR(<period>))
It may be use by the application to get the absolute time in µs using blc_loop_timer.tv_sec*1000000+blc_loop_timer.tv_usec
It should not be changed by the application
extern struct timeval blc_loop_timer;
extern int blc_input_terminal, blc_output_terminal;
extern type_blc_status blc_status;
extern uint64_t blc_loop_iteration;
......@@ -47,6 +53,10 @@ extern FILE *blc_profile_file;
//void * to not need to include "semaphore.h"
void blc_loop_sem_to_unlock_on_stop(void *sem);
......@@ -9,7 +9,7 @@
#include <sys/time.h> //gettimeofday
#include <pthread.h> //pthread_mutex
static struct timeval timer;
struct timeval blc_loop_timer;
static uint blc_period=0;
static uint blc_duration=0;
static uint blc_duration_min=UINT_MAX, blc_duration_max=0;
......@@ -54,7 +54,7 @@ void blc_fprint_stats(FILE *file)
else fprintf(file, "%s: No new iteration yet\n", blc_program_id);
gettimeofday(&timer, NULL);
gettimeofday(&blc_loop_timer, NULL);
static void display_stats(){
......@@ -235,7 +235,7 @@ int blc_command_loop_start(){
int i;
if (blc_profile_file) gettimeofday(&profile_timer, NULL);
if (blc_profile_file) gettimeofday(&profile_timer, NULL); //this is only for profiling
//We wait before counting the duration time as the time for waiting does not matter
if (blc_loop_iteration==blc_loop_iteration_limit){
......@@ -256,11 +256,11 @@ int blc_command_loop_start(){
//Waiting general user defined callbacks
FOR(i, waiting_callbacks_nb) waiting_callbacks[i](waiting_callabacks_user_data[i]);
else blc_command_loop_period=-3; //In case we start another loop after
else blc_command_loop_period=-3; //In case we start another loop after by mistake
//We start counting the duration time
if (intermediate_iteration==0) blc_us_time_diff(&timer);
else blc_period+=blc_current_duration + blc_us_time_diff(&timer);
if (intermediate_iteration==0) blc_us_time_diff(&blc_loop_timer);
else blc_period+=blc_current_duration + blc_us_time_diff(&blc_loop_timer);
return blc_status;
......@@ -271,8 +271,8 @@ void blc_command_loop_end(){
int diff, i;
uint64_t start_time;
if (blc_profile_file) start_time=timer.tv_sec*1000000+timer.tv_usec;
if (blc_profile_file) start_time=blc_loop_timer.tv_sec*1000000+blc_loop_timer.tv_usec;
if (blc_profile_file) fprintf(blc_profile_file, "%16ld\t%16lld\t%8lu\t\n",profile_timer.tv_sec*1000000+profile_timer.tv_usec, start_time, blc_current_duration);
// fflush(stderr);
......@@ -454,7 +454,6 @@ void blc_program_init(int *argc, char ***argv, void (*exit_cb)(void))
char const*help, *profile;
struct sigaction action;
struct timeval timer;
action.sa_handler = on_sigterm;
......@@ -484,14 +483,6 @@ void blc_program_init(int *argc, char ***argv, void (*exit_cb)(void))
blc_program_add_option(&profile, '~', "profile", "filename", "profile the execution of the loop", NULL);
blc_program_add_option(&help, 'h', "help", 0, "display this help", NULL);
blc_program_parse_args_and_print_title(argc, argv);
if (profile){
SYSTEM_ERROR_CHECK(blc_profile_file=fopen(profile, "w"), NULL, "filename: %s", profile);
fprintf(blc_profile_file, "#start_time(µs) \texec_time(µs) \tduration(µs) \t\n");
gettimeofday(&timer, NULL);
fprintf(blc_profile_file, "%16lu\t 0\t 0\t\n", timer.tv_sec*1000000+timer.tv_usec);
if (help){
......@@ -499,6 +490,15 @@ void blc_program_init(int *argc, char ***argv, void (*exit_cb)(void))
blc_program_check_full_parsing(*argc, *argv);
if (exit_cb) atexit(exit_cb); //This will be called first
//We consider it is the begining of the program
gettimeofday(&blc_loop_timer, NULL);
if (profile){
SYSTEM_ERROR_CHECK(blc_profile_file=fopen(profile, "w"), NULL, "filename: %s", profile);
fprintf(blc_profile_file, "#start_time(µs) \texec_time(µs) \tduration(µs) \t\n");
fprintf(blc_profile_file, "%16lu\t 0\t 0\t\n", blc_loop_timer.tv_sec*1000000+blc_loop_timer.tv_usec);
void blc_program_check_full_parsing(int argc, char **argv){
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment