Rizin
unix-like reverse engineering framework and cli tools
mytime.c File Reference

Time handling functions. More...

#include "private.h"
#include <sys/time.h>

Go to the source code of this file.

Functions

static uint64_t mytime_now (void)
 Get the current time as milliseconds. More...
 
void mytime_set_start_time (void)
 Store the time when (de)compression was started. More...
 
uint64_t mytime_get_elapsed (void)
 Get the number of milliseconds since the operation started. More...
 
void mytime_set_flush_time (void)
 Store the time of when compressor was flushed. More...
 
int mytime_get_flush_timeout (void)
 Get the number of milliseconds until the next flush. More...
 

Variables

uint64_t opt_flush_timeout = 0
 Number of milliseconds to between LZMA_SYNC_FLUSHes. More...
 
static uint64_t start_time
 
static uint64_t next_flush
 

Detailed Description

Time handling functions.

Definition in file mytime.c.

Function Documentation

◆ mytime_get_elapsed()

uint64_t mytime_get_elapsed ( void  )

Get the number of milliseconds since the operation started.

Definition at line 59 of file mytime.c.

60 {
61  return mytime_now() - start_time;
62 }
static uint64_t start_time
Definition: mytime.c:21
static uint64_t mytime_now(void)
Get the current time as milliseconds.
Definition: mytime.c:29

References mytime_now(), and start_time.

Referenced by message_progress_update(), and progress_flush().

◆ mytime_get_flush_timeout()

int mytime_get_flush_timeout ( void  )

Get the number of milliseconds until the next flush.

This returns -1 if no timed flushing is used.

The return value is intended for use with poll().

Definition at line 74 of file mytime.c.

75 {
77  return -1;
78 
79  const uint64_t now = mytime_now();
80  if (now >= next_flush)
81  return 0;
82 
83  const uint64_t remaining = next_flush - now;
84  return remaining > INT_MAX ? INT_MAX : (int)remaining;
85 }
enum operation_mode opt_mode
Definition: coder.c:24
@ MODE_COMPRESS
Definition: coder.h:14
#define INT_MAX
Definition: cp-demangle.c:131
uint64_t opt_flush_timeout
Number of milliseconds to between LZMA_SYNC_FLUSHes.
Definition: mytime.c:19
static uint64_t next_flush
Definition: mytime.c:22
static int
Definition: sfsocketcall.h:114
unsigned long uint64_t
Definition: sftypes.h:28

References int, INT_MAX, MODE_COMPRESS, mytime_now(), next_flush, opt_flush_timeout, and opt_mode.

Referenced by io_read().

◆ mytime_now()

static uint64_t mytime_now ( void  )
static

Get the current time as milliseconds.

It's relative to some point but not necessarily to the UNIX Epoch.

Definition at line 29 of file mytime.c.

30 {
31  // NOTE: HAVE_DECL_CLOCK_MONOTONIC is always defined to 0 or 1.
32 #if defined(HAVE_CLOCK_GETTIME) && HAVE_DECL_CLOCK_MONOTONIC
33  // If CLOCK_MONOTONIC was available at compile time but for some
34  // reason isn't at runtime, fallback to CLOCK_REALTIME which
35  // according to POSIX is mandatory for all implementations.
36  static clockid_t clk_id = CLOCK_MONOTONIC;
37  struct timespec tv;
38  while (clock_gettime(clk_id, &tv))
39  clk_id = CLOCK_REALTIME;
40 
41  return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_nsec / 1000000);
42 #else
43  struct timeval tv;
44  gettimeofday(&tv, NULL);
45  return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_usec / 1000);
46 #endif
47 }
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval tv
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog gettimeofday
Definition: sflib.h:79

References gettimeofday, NULL, and tv.

Referenced by mytime_get_elapsed(), mytime_get_flush_timeout(), mytime_set_flush_time(), and mytime_set_start_time().

◆ mytime_set_flush_time()

void mytime_set_flush_time ( void  )

Store the time of when compressor was flushed.

Definition at line 66 of file mytime.c.

67 {
69  return;
70 }

References mytime_now(), next_flush, and opt_flush_timeout.

Referenced by io_read().

◆ mytime_set_start_time()

void mytime_set_start_time ( void  )

Store the time when (de)compression was started.

The start time is also stored as the time of the first flush.

Definition at line 51 of file mytime.c.

52 {
54  return;
55 }

References mytime_now(), and start_time.

Referenced by coder_run().

Variable Documentation

◆ next_flush

uint64_t next_flush
static

Definition at line 22 of file mytime.c.

Referenced by mytime_get_flush_timeout(), and mytime_set_flush_time().

◆ opt_flush_timeout

uint64_t opt_flush_timeout = 0

Number of milliseconds to between LZMA_SYNC_FLUSHes.

If 0, timed flushing is disabled. Otherwise if no more input is available and not at the end of the file and at least opt_flush_timeout milliseconds has elapsed since the start of compression or the previous flushing (LZMA_SYNC_FLUSH or LZMA_FULL_FLUSH), set LZMA_SYNC_FLUSH to flush the pending data.

Definition at line 19 of file mytime.c.

Referenced by coder_init(), mytime_get_flush_timeout(), mytime_set_flush_time(), and parse_real().

◆ start_time

uint64_t start_time
static

Definition at line 21 of file mytime.c.

Referenced by mytime_get_elapsed(), mytime_set_start_time(), and rz_test_run_test().