How to slow down all measurements of the process time?
I would like the app to show that time is running faster / slower than real time. That is, I need all the time measurement APIs to return t0+dt*s
with a custom s
one when t0+dt
it is real time. This will affect something like gettimeofday()
, timer_gettime()
and all related functions and mechanisms (including the actual timing of the timers).
I am thinking about placing the hook somewhere that will change the apparent time for the application.
On a Linux system, what's the best place to put it so that I don't have to create too many hooks? Is there a central place for this?
source to share
You can use the LD_PRELOAD trick described in this question .
Libfaketime to do what you need (see the README under "Advanced Time Specification Options"). The following example shows that time running 2x slower for "sleep":
$ time FAKETIME="x0.5" LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1 sleep 1
real 0m2.002s
user 0m0.000s
sys 0m0.000s
(on debian system, so / usr / lib /)
If it doesn't actually do what you want, instead of deploying your own solution, I suggest taking its source and implementing what you need from there.
For completeness, another possible starting point is datefudge .
source to share