Skip to content

Commit

Permalink
Use the "zone" feature for LuaJIT profiling.
Browse files Browse the repository at this point in the history
Snabb Switch now tells the profiler what "zone" of computation is
executing at any given time. The profiler is then able to report on
each zone separately, when given the -jp=z flag.

The zone name for an app can be given explicitly as the "zone" field
of the app (or its class). If no name is given then one is guessed
based on the module name of the app's code.

Example output:

    # ./snabbswitch -jp=2zF -t apps.intel.intel_app
    75%  apps.intel.intel_app
      -- 18%  intel10g.lua:transmit < intel_app.lua:push
      -- 17%  intel10g.lua:receive < intel_app.lua:pull
      -- 11%  buffer.lua:free < packet.lua:free
      --  7%  intel10g.lua:sync_transmit < intel_app.lua:push
      --  5%  intel10g.lua:can_add_receive_buffer < intel_app.lua:add_receive_buffers
      --  4%  register.lua:RDH < intel10g.lua:sync_receive
      --  3%  freelist.lua:add < buffer.lua:free
      --  3%  intel10g.lua:add_receive_buffer < intel_app.lua:add_receive_buffers
      --  3%  link.lua:receive < intel_app.lua:push
      --  3%  link.lua:transmit < intel_app.lua:pull
      --  3%  freelist.lua:remove < packet.lua:allocate
    11%  Sink
      -- 48%  buffer.lua:free < packet.lua:free
      -- 13%  freelist.lua:add < packet.lua:free
      -- 11%  link.lua:receive < basic_apps.lua:push
      --  9%  freelist.lua:add < buffer.lua:free
      --  7%  packet.lua:free < packet.lua:deref
      --  7%  packet.lua:deref < basic_apps.lua:push
    10%  Source
      -- 45%  packet.lua:add_iovec < basic_apps.lua:pull
      -- 15%  link.lua:transmit < basic_apps.lua:pull
      -- 15%  freelist.lua:remove < buffer.lua:allocate
      -- 11%  link.lua:full < link.lua:transmit
      --  8%  freelist.lua:remove < packet.lua:allocate
      --  6%  basic_apps.lua:pull < app.lua:breathe
     4%  selftest
      -- 27%  lib.lua:waitfor < register.lua:wait
      -- 27%  memory.lua:allocate_RAM < memory.lua:allocate_next_chunk
      -- 23%  app.lua:breathe < app.lua:main
      -- 14%  zone.lua:zone < app.lua:breathe
      --  5%  lib.lua:firstline < pci.lua:device_info
      --  5%  lib.lua:done < app.lua:main
  • Loading branch information
lukego committed Apr 23, 2014
1 parent cbed6e5 commit c72460c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
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")

-- The set of all active apps and links in the system.
Expand Down Expand Up @@ -67,11 +68,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 @@ -127,7 +130,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 @@ -139,7 +144,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 @@ -43,7 +45,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 @@ -70,6 +72,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 c72460c

Please sign in to comment.