[Tarantool-patches] [PATCH luajit v2 7/7] tools: introduce a memory profile parser

Sergey Kaplun skaplun at tarantool.org
Mon Dec 28 09:28:27 MSK 2020


This is a patch for workaround of Tarantool's work with builtins.
It is necessary to be able launch profiler parser something like
this (with Tarantool only):

| src/tarantool -e 'require"memprof"(arg[1])' - ~/tmp/uj_memprof/memprof_new.bin

Branch is force-pushed.

===================================================================
diff --git a/tools/memprof.lua b/tools/memprof.lua
index a98e192..9f96208 100644
--- a/tools/memprof.lua
+++ b/tools/memprof.lua
@@ -90,22 +90,30 @@ local function parseargs(args)
   return args[args.argn]
 end
 
-local inputfile = parseargs(arg)
+local function dump(inputfile)
+  local reader = bufread.new(inputfile)
+  local symbols = symtab.parse(reader)
+  local events = memprof.parse(reader, symbols)
 
-local reader = bufread.new(inputfile)
-local symbols = symtab.parse(reader)
-local events = memprof.parse(reader, symbols)
+  stdout:write("ALLOCATIONS", "\n")
+  view.render(events.alloc, symbols)
+  stdout:write("\n")
 
-stdout:write("ALLOCATIONS", "\n")
-view.render(events.alloc, symbols)
-stdout:write("\n")
+  stdout:write("REALLOCATIONS", "\n")
+  view.render(events.realloc, symbols)
+  stdout:write("\n")
 
-stdout:write("REALLOCATIONS", "\n")
-view.render(events.realloc, symbols)
-stdout:write("\n")
+  stdout:write("DEALLOCATIONS", "\n")
+  view.render(events.free, symbols)
+  stdout:write("\n")
 
-stdout:write("DEALLOCATIONS", "\n")
-view.render(events.free, symbols)
-stdout:write("\n")
+  os.exit(0)
+end
 
-os.exit(0)
+-- FIXME: this script should be application-independent.
+local args = {...}
+if #args == 1 and args[1] == "memprof" then
+  return dump
+else
+  dump(parseargs(args))
+end
===================================================================

-- 
Best regards,
Sergey Kaplun


More information about the Tarantool-patches mailing list