MoonGen
 All Files Functions Variables Pages
timer.lua
Go to the documentation of this file.
1 ---------------------------------
2 --- @file timer.lua
3 --- @brief Timer ...
4 --- @todo TODO docu
5 ---------------------------------
6 
7 local mod = {}
8 
9 local dpdk = require "dpdk"
10 
11 local timer = {}
12 timer.__index = timer
13 
14 function mod:new(time)
15  return setmetatable({
16  time = time or 0,
17  stop = dpdk.getTime() + (time or 0)
18  }, timer)
19 end
20 
21 function timer:running()
22  return self.stop > dpdk.getTime()
23 end
24 
25 function timer:expired()
26  return self.stop <= dpdk.getTime()
27 end
28 
29 function timer:timeLeft()
30  return self.stop - dpdk.getTime()
31 end
32 
33 function timer:reset(time)
34  self.stop = dpdk.getTime() + (time or self.time)
35 end
36 
37 --- Perform a busy wait on the timer.
38 -- Returns early if MoonGen is stopped (mg.running() == false).
39 function timer:busyWait()
40  while not self:expired() and dpdk.running() do
41  end
42  return dpdk.running()
43 end
44 
45 --- Perform a non-busy wait on the timer.
46 --- Might be less accurate than busyWait()
47 function timer:wait()
48  -- TODO: implement
49  return self:busyWait()
50 end
51 
52 return mod
53 
function timer busyWait()
Perform a busy wait on the timer.
local mod
high-level dpdk wrapper
Definition: dpdk.lua:6
function mod stop()
request all tasks to exit
function timer wait()
Perform a non-busy wait on the timer.
function mod getTime()
gets the time in seconds
function mod running(extraTime)
Returns false once the app receives SIGTERM or SIGINT, the time set via setRuntime expires...