diff --git a/src/core/app.lua b/src/core/app.lua index 80a4a9a29c..b997307586 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -76,6 +76,8 @@ busywait = false -- Profiling with vmprofile -------------------------------- +vmprofile_enabled = true + -- Low-level FFI ffi.cdef[[ int vmprofile_get_profile_size(); @@ -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. diff --git a/src/lib/ptree/worker.lua b/src/lib/ptree/worker.lua index 971213f230..3925fc642d 100644 --- a/src/lib/ptree/worker.lua +++ b/src/lib/ptree/worker.lua @@ -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}, @@ -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 @@ -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 diff --git a/src/lib/scheduling.lua b/src/lib/scheduling.lua index ab3ac2f0d8..2ddb9f3811 100644 --- a/src/lib/scheduling.lua +++ b/src/lib/scheduling.lua @@ -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. } @@ -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 diff --git a/src/program/lwaftr/run/README b/src/program/lwaftr/run/README index 62d0eef32e..534b20e581 100644 --- a/src/program/lwaftr/run/README +++ b/src/program/lwaftr/run/README @@ -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 diff --git a/src/program/lwaftr/run/run.lua b/src/program/lwaftr/run/run.lua index cdf11b9f72..5690aac2b1 100644 --- a/src/program/lwaftr/run/run.lua +++ b/src/program/lwaftr/run/run.lua @@ -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 @@ -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