Skip to content

Commit

Permalink
Merge pull request #155 from lukego/csv
Browse files Browse the repository at this point in the history
Generate CSV files for diagnostics [DRAFT]
  • Loading branch information
lukego committed Apr 30, 2014
2 parents 5443082 + 70474b5 commit 1e98af1
Show file tree
Hide file tree
Showing 7 changed files with 3,361 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/apps/csv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module(...,package.seeall)

local app = require("core.app")
local ffi = require("ffi")
local C = ffi.C

-- Frequency at which lines are added to the CSV file.
-- (XXX should be an argument to the app.)
interval = 1.0

CSV = {}

function CSV:new (directory)
local o = { appfile = io.open(directory.."/app.csv", "w"),
linkfile = io.open(directory.."/link.csv", "w") }
o.appfile:write("time,name,class,cpu,crashes,starttime\n")
o.appfile:flush()
o.linkfile:write("time,from_app,from_port,to_app,to_port,txbytes,txpackets,rxbytes,rxpackets,dropbytes,droppackets\n")
o.linkfile:flush()
timer.init()
timer.new('CSV',
function () o:output() end,
1e9,
'repeating')
return setmetatable(o, {__index = CSV})
end

function CSV:pull ()
local now = engine.now()
if self.next_report and self.next_report > now then
return
end
self.next_report = (self.next_report or now) + interval
for name, app in pairs(app.app_table) do
self.appfile:write(
string.format("%f,%s,%s,%d,%d,%d\n",
tonumber(now), name, app.zone, 0, 0, 0))
self.appfile:flush()
end
for spec, link in pairs(app.link_table) do
local fa, fl, ta, tl = config.parse_link(spec)
local s = link.stats
self.linkfile:write(
string.format("%f,%s,%s,%s,%s,%d,%d,%d,%d,%d,%d\n",
now,fa,fl,ta,tl,
s.txbytes, s.txpackets,
s.rxbytes, s.rxpackets,
0, s.txdrop))
self.linkfile:flush()
end
end

11 changes: 11 additions & 0 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ local link = require("core.link")
local config = require("core.config")
local timer = require("core.timer")
local zone = require("jit.zone")
local ffi = require("ffi")
local C = ffi.C
require("core.packet_h")

test_skipped_code = 43
Expand All @@ -18,6 +20,14 @@ link_table, link_array = {}, {}

configuration = config.new()

monotinic_now = false

-- Return current monotonic time in seconds.
-- Can be used to drive timers in apps.
function now ()
return monotonic_now
end

-- Configure the running app network to match new_configuration.
--
-- Successive calls to configure() will migrate from the old to the
Expand Down Expand Up @@ -130,6 +140,7 @@ function main (options)
end

function breathe ()
monotonic_now = C.get_monotonic_time()
-- Inhale: pull work into the app network
for _, app in ipairs(app_array) do
if app.pull then
Expand Down
19 changes: 19 additions & 0 deletions src/core/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ uint64_t get_time_ns()
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
}

static double get_time(int clock)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec + (ts.tv_nsec / 1000000000.0);
}

/* Return monotonic time (in seconds) suitable for timers. */
double get_monotonic_time()
{
return get_time(CLOCK_MONOTONIC);
}

/* Return real wall-clock time in seconds since the epoch. */
double get_unix_time()
{
return get_time(CLOCK_REALTIME);
}

/* Sleep for a given number of nanoseconds.
Must be less than 1 second. */
void sleep_ns(int nanoseconds)
Expand Down
2 changes: 2 additions & 0 deletions src/core/lib.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
uint64_t get_time_ns();
double get_monotonic_time();
double get_unix_time();
void sleep_ns(int nanoseconds);
void full_memory_barrier();
void prefetch_for_read(const void *address);
Expand Down

0 comments on commit 1e98af1

Please sign in to comment.