Skip to content

Commit

Permalink
Disable vmprofile on lwAFTR by default
Browse files Browse the repository at this point in the history
Add a --profile option to control whether vmprofile is enabled or not.
  • Loading branch information
wingo committed Dec 4, 2019
1 parent 9a787b5 commit 7a0c6c8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
20 changes: 13 additions & 7 deletions src/core/app.lua
Expand Up @@ -76,6 +76,8 @@ busywait = false

-- Profiling with vmprofile --------------------------------

vmprofile_enabled = true

-- Low-level FFI
ffi.cdef[[
int vmprofile_get_profile_size();
Expand All @@ -93,17 +95,21 @@ local function getvmprofile (name)
end

function setvmprofile (name)
C.vmprofile_set_profile(getvmprofile(name))
if vmprofile_enabled then
C.vmprofile_set_profile(getvmprofile(name))
end
end

function clearvmprofiles ()
jit.vmprofile.stop()
for name, profile in pairs(vmprofiles) do
shm.unmap(profile)
shm.unlink("vmprofile/"..name..".vmprofile")
vmprofiles[name] = nil
if vmprofile_enabled then
jit.vmprofile.stop()
for name, profile in pairs(vmprofiles) do
shm.unmap(profile)
shm.unlink("vmprofile/"..name..".vmprofile")
vmprofiles[name] = nil
end
jit.vmprofile.start()
end
jit.vmprofile.start()
end

-- True when the engine is running the breathe loop.
Expand Down
8 changes: 3 additions & 5 deletions src/lib/ptree/worker.lua
Expand Up @@ -21,6 +21,7 @@ local worker_config_spec = {
duration = {},
measure_latency = {default=true},
measure_memory = {default=true},
profile = {default=true},
no_report = {default=false},
report = {default={showapps=true,showlinks=true}},
Hz = {default=1000},
Expand All @@ -46,6 +47,7 @@ function new_worker (conf)
if conf.measure_memory then
timer.activate(memory_info.HeapSizeMonitor.new():timer())
end
engine.vmprofile_enabled = conf.profile
return ret
end

Expand Down Expand Up @@ -100,16 +102,12 @@ function Worker:handle_actions_from_manager()
end

function Worker:main ()
local vmprofile = require("jit.vmprofile")
local stop = engine.now() + self.duration
local next_time = engine.now()

-- Setup vmprofile.
engine.setvmprofile("engine")
vmprofile.start()

if not engine.auditlog_enabled then engine.enable_auditlog() end

engine.setvmprofile("engine")
repeat
self.breathe()
if next_time < engine.now() then
Expand Down
7 changes: 7 additions & 0 deletions src/lib/scheduling.lua
Expand Up @@ -16,6 +16,7 @@ local scheduling_opts = {
cpu = {}, -- CPU index (integer).
real_time = {}, -- Boolean.
ingress_drop_monitor = {}, -- Action string: one of 'flush' or 'warn'.
profile = {default=true}, -- Boolean.
busywait = {default=true}, -- Boolean.
eval = {} -- String.
}
Expand All @@ -42,6 +43,12 @@ function sched_apply.busywait (busywait)
engine.busywait = busywait
end

function sched_apply.profile (profile)
engine.vmprofile_enabled = profile
local vmprofile = require('jit.vmprofile')
if profile then vmprofile.start() else vmprofile.stop() end
end

function sched_apply.eval (str)
loadstring(str)()
end
Expand Down
5 changes: 2 additions & 3 deletions src/program/lwaftr/run/README
Expand Up @@ -49,11 +49,10 @@ Optional arguments:

Optional arguments for debugging and profiling:
-v Verbose (repeat for more verbosity).
--profile Enable the low-overhead sampling
profiler.
-t FILE, --trace FILE Record a trace of any run-time "snabb
config" commands to FILE.
-jv, -jv=FILE Print out when traces are recorded.
-jp, -jp=MODE,FILE Profile the system by method.
-jtprof Profile the system by trace.
-b FILENAME, --bench-file FILENAME
Write any benchmarking data to FILENAME.
-D SECONDS Stop after SECONDS, for debugging
Expand Down
8 changes: 4 additions & 4 deletions src/program/lwaftr/run/run.lua
Expand Up @@ -50,7 +50,7 @@ function parse_args(args)
local conf_file, v4, v6
local ring_buffer_size
local opts = { verbosity = 0 }
local scheduling = { ingress_drop_monitor = 'flush' }
local scheduling = { ingress_drop_monitor = 'flush', profile = false }
local handlers = {}
function handlers.n (arg) opts.name = assert(arg) end
function handlers.v () opts.verbosity = opts.verbosity + 1 end
Expand Down Expand Up @@ -100,13 +100,13 @@ function parse_args(args)
.." (valid values: flush, warn, off)")
end
end
function handlers.j(arg) scheduling.j = arg end
function handlers.profile() scheduling.profile = true end
function handlers.h() show_usage(0) end
lib.dogetopt(args, handlers, "b:c:vD:yhir:n:j:t:",
lib.dogetopt(args, handlers, "b:c:vD:yhir:n:t:",
{ conf = "c", name = "n", cpu = 1, v4 = 1, v6 = 1,
["on-a-stick"] = 1, virtio = "i", ["ring-buffer-size"] = "r",
["real-time"] = 0, mirror = 1, ["ingress-drop-monitor"] = 1,
verbose = "v", trace = "t", ["bench-file"] = "b",
verbose = "v", trace = "t", ["bench-file"] = "b", ["profile"] = 0,
duration = "D", hydra = "y", help = "h" })
if ring_buffer_size ~= nil then
if opts.virtio_net then
Expand Down

0 comments on commit 7a0c6c8

Please sign in to comment.