MySQL 8.0.40
Source Code Documentation
my_rdtsc.cc File Reference

Multi-platform timer code. More...

#include <stdint.h>
#include <stdio.h>
#include "my_config.h"
#include "my_inttypes.h"
#include "my_rdtsc.h"
#include <sys/time.h>
#include <sys/times.h>

Macros

#define MY_TIMER_ITERATIONS   1000000
 

Functions

ulonglong my_timer_cycles (void)
 A cycle timer. More...
 
ulonglong my_timer_nanoseconds (void)
 A namoseconds timer. More...
 
ulonglong my_timer_microseconds (void)
 A microseconds timer. More...
 
ulonglong my_timer_milliseconds (void)
 A millisecond timer. More...
 
ulonglong my_timer_ticks (void)
 A ticks timer. More...
 
ulonglong my_timer_thread_cpu (void)
 THREAD_CPU timer. More...
 
static void my_timer_init_overhead (ulonglong *overhead, ulonglong(*cycle_timer)(void), ulonglong(*this_timer)(void), ulonglong best_timer_overhead)
 
static ulonglong my_timer_init_resolution (ulonglong(*this_timer)(void), ulonglong overhead_times_2)
 
static ulonglong my_timer_init_frequency (MY_TIMER_INFO *mti)
 
void my_timer_init (MY_TIMER_INFO *mti)
 Timer initialization function. More...
 

Detailed Description

Multi-platform timer code.

Functions:

my_timer_cycles ulonglong cycles my_timer_nanoseconds ulonglong nanoseconds my_timer_microseconds ulonglong "microseconds" my_timer_milliseconds ulonglong milliseconds my_timer_ticks ulonglong ticks my_timer_thread_cpu ulonglong thread_cpu my_timer_init initialization / test

We'll call the first 6 functions (the ones that return a ulonglong) "my_timer_xxx" functions. Each my_timer_xxx function returns a 64-bit timing value since an arbitrary 'epoch' start. Since the only purpose is to determine elapsed times, wall-clock time-of-day is not known and not relevant.

The my_timer_init function is necessary for initializing. It returns information (underlying routine name, frequency, resolution, overhead) about all my_timer_xxx functions. A program should call my_timer_init once, use the information to decide what my_timer_xxx function to use, and subsequently call that function by function pointer.

A typical use would be: my_timer_init() ... once, at program start ... time1= my_timer_xxx() ... time before start [code that's timed] time2= my_timer_xxx() ... time after end elapsed_time= (time2 - time1) - overhead

Macro Definition Documentation

◆ MY_TIMER_ITERATIONS

#define MY_TIMER_ITERATIONS   1000000

Function Documentation

◆ my_timer_cycles()

ulonglong my_timer_cycles ( void  )

A cycle timer.

Returns
the current timer value, in cycles.

◆ my_timer_init()

void my_timer_init ( MY_TIMER_INFO mti)

Timer initialization function.

Parameters
[out]mtithe timer characteristics.

◆ my_timer_init_frequency()

static ulonglong my_timer_init_frequency ( MY_TIMER_INFO mti)
static

◆ my_timer_init_overhead()

static void my_timer_init_overhead ( ulonglong overhead,
ulonglong(*)(void)  cycle_timer,
ulonglong(*)(void)  this_timer,
ulonglong  best_timer_overhead 
)
static

◆ my_timer_init_resolution()

static ulonglong my_timer_init_resolution ( ulonglong(*)(void)  this_timer,
ulonglong  overhead_times_2 
)
static

◆ my_timer_microseconds()

ulonglong my_timer_microseconds ( void  )

A microseconds timer.

Returns
the current timer value, in microseconds.

◆ my_timer_milliseconds()

ulonglong my_timer_milliseconds ( void  )

A millisecond timer.

Returns
the current timer value, in milliseconds.

◆ my_timer_nanoseconds()

ulonglong my_timer_nanoseconds ( void  )

A namoseconds timer.

Returns
the current timer value, in nanoseconds.

◆ my_timer_thread_cpu()

ulonglong my_timer_thread_cpu ( void  )

THREAD_CPU timer.

A THREAD CPU timer.

Expressed in nanoseconds.

◆ my_timer_ticks()

ulonglong my_timer_ticks ( void  )

A ticks timer.

Returns
the current timer value, in ticks.