Skip to content

Commit

Permalink
Merge pull request #140 from lukego/debug
Browse files Browse the repository at this point in the history
Debug: Enable more LuaJIT features for debugging
  • Loading branch information
lukego committed Apr 23, 2014
2 parents a5e19a2 + c72460c commit 1fdd04f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ COBJ = $(CSRC:.c=.o)

LUAJIT_O := deps/luajit/src/libluajit.a

LUAJIT_CFLAGS := -DLUAJIT_USE_PERFTOOLS -DLUAJIT_USE_GDBJIT

all: $(LUAJIT_O)
cd src && $(MAKE)

$(LUAJIT_O): deps/luajit/Makefile
(echo 'Building LuaJIT\n'; cd deps/luajit && $(MAKE) PREFIX=`pwd`/usr/local && $(MAKE) DESTDIR=`pwd` install)
echo 'Building LuaJIT\n'
(cd deps/luajit && \
$(MAKE) PREFIX=`pwd`/usr/local \
CFLAGS="$(LUAJIT_CFLAGS)" && \
$(MAKE) DESTDIR=`pwd` install)
(cd deps/luajit/usr/local/bin; ln -fs luajit-2.1.0-alpha luajit)

clean:
Expand Down
18 changes: 9 additions & 9 deletions src/apps/basic/basic_apps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

--- # `Source` app: generate synthetic packets

Source = setmetatable({}, {__index = Basic})
Source = setmetatable({zone = "Source"}, {__index = Basic})

function Source:new()
return setmetatable({}, {__index=Source})
Expand All @@ -40,7 +40,7 @@ end

--- # `Join` app: Merge multiple inputs onto one output

Join = setmetatable({}, {__index = Basic})
Join = setmetatable({zone = "Join"}, {__index = Basic})

function Join:new()
return setmetatable({}, {__index=Join})
Expand All @@ -58,7 +58,7 @@ end

-- For each input port, push packets onto outputs. When one output
-- becomes full then continue with the next.
Split = setmetatable({}, {__index = Basic})
Split = setmetatable({zone = "Split"}, {__index = Basic})

function Split:new ()
return setmetatable({}, {__index=Split})
Expand All @@ -76,7 +76,7 @@ end

--- ### `Sink` app: Receive and discard packets

Sink = setmetatable({}, {__index = Basic})
Sink = setmetatable({zone = "Sink"}, {__index = Basic})

function Sink:new ()
return setmetatable({}, {__index=Sink})
Expand All @@ -98,7 +98,7 @@ end
-- Assumed to be used in pair with FastRepeater
-- FastSink doesn't calculate rx statistics

FastSink = setmetatable({}, {__index = Basic})
FastSink = setmetatable({zone = "FastSink"}, {__index = Basic})

function FastSink:new ()
return setmetatable({}, {__index=Sink})
Expand All @@ -113,7 +113,7 @@ end

--- ### `Tee` app: Send inputs to all outputs

Tee = setmetatable({}, {__index = Basic})
Tee = setmetatable({zone = "Tee"}, {__index = Basic})

function Tee:new ()
return setmetatable({}, {__index=Tee})
Expand Down Expand Up @@ -141,7 +141,7 @@ end

--- ### `Repeater` app: Send all received packets in a loop

Repeater = setmetatable({}, {__index = Basic})
Repeater = setmetatable({zone = "Repeater"}, {__index = Basic})

function Repeater:new ()
return setmetatable({index = 1, packets = {}},
Expand Down Expand Up @@ -171,7 +171,7 @@ end
-- Only for test purpose, never use it in real world application
-- Assumed to be used in pair with FastSink

FastRepeater = setmetatable({}, {__index = Basic})
FastRepeater = setmetatable({zone = "FastRepeater"}, {__index = Basic})

function FastRepeater:new ()
return setmetatable({init = true},
Expand Down Expand Up @@ -211,7 +211,7 @@ end

--- ### `Buzz` app: Print a debug message when called

Buzz = setmetatable({}, {__index = Basic})
Buzz = setmetatable({zone = "Buzz"}, {__index = Basic})

function Buzz:new ()
return setmetatable({}, {__index=Buzz})
Expand Down
9 changes: 7 additions & 2 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local lib = require("core.lib")
local link = require("core.link")
local config = require("core.config")
local timer = require("core.timer")
local zone = require("jit.zone")
require("core.packet_h")

test_skipped_code = 43
Expand Down Expand Up @@ -69,11 +70,13 @@ function apply_config_actions (actions, conf)
local class = conf.apps[name].class
local arg = conf.apps[name].arg
local app = class:new(arg)
local zone = app.zone or getfenv(class.new)._NAME or name
app.output = {}
app.input = {}
new_app_table[name] = app
table.insert(new_app_array, app)
app_name_to_index[name] = #new_app_array
app.zone = zone
end
function ops.restart (name)
ops.stop(name)
Expand Down Expand Up @@ -129,7 +132,9 @@ end
function breathe ()
-- Inhale: pull work into the app network
for _, app in ipairs(app_array) do
if app.pull then app:pull() end
if app.pull then
zone(app.zone) app:pull() zone()
end
end
-- Exhale: push work out through the app network
local firstloop = true
Expand All @@ -141,7 +146,7 @@ function breathe ()
link.has_new_data = false
local receiver = app_array[link.receiving_app]
if receiver.push then
receiver:push()
zone(receiver.zone) receiver:push() zone()
progress = true
end
end
Expand Down
5 changes: 4 additions & 1 deletion src/core/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module(...,package.seeall)

local ffi = require("ffi")
local zone = require("jit.zone")
local C = ffi.C

require("lib.lua.strict")
Expand Down Expand Up @@ -30,6 +31,7 @@ local profiling = false
parameters = {}

function main ()
zone("startup")
require "lib.lua.strict"
initialize()
local args = command_line_args()
Expand All @@ -47,7 +49,7 @@ function main ()
require(args[i+1])
i = i + 2
elseif args[i] == '-t' and i < #args then
require(args[i+1]).selftest()
zone("selftest") require(args[i+1]).selftest() zone()
i = i + 2
elseif args[i] == '-e' and i < #args then
local thunk, error = loadstring(args[i+1])
Expand All @@ -74,6 +76,7 @@ function main ()
table.insert(parameters, args[i])
i = i + 1
end
zone("module "..module)
require(module)
exit(0)
else
Expand Down

0 comments on commit 1fdd04f

Please sign in to comment.