Skip to content

Commit

Permalink
profilers: introduce event reader module
Browse files Browse the repository at this point in the history
There is no error-checking in profilers which results in raw Lua
errors being reported in cases of non-existing paths or corrupt
file structures. This patch adds a profiler-agnostic module for
event parsing, which is going to be used to introduce
user-friendly errors. It is impossible to enable it right now
because it should be included in Tarantool's build procedure
first.

Part of tarantool/tarantool#9217
Part of tarantool/tarantool#5994
  • Loading branch information
mkokryashkin authored and Buristan committed Mar 14, 2024
1 parent 7e5aca1 commit 357a24d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.original
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ FILES_JITLIB= bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua \
dis_x86.lua dis_x64.lua dis_arm.lua dis_arm64.lua \
dis_arm64be.lua dis_ppc.lua dis_mips.lua dis_mipsel.lua \
dis_mips64.lua dis_mips64el.lua vmdef.lua
FILES_UTILSLIB= avl.lua bufread.lua symtab.lua
FILES_UTILSLIB= avl.lua bufread.lua evread.lua symtab.lua
FILES_MEMPROFLIB= humanize.lua parse.lua process.lua
FILES_SYSPROFLIB= parse.lua
FILES_TOOLSLIB= memprof.lua sysprof.lua
Expand Down
4 changes: 4 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ else()
memprof.lua
utils/avl.lua
utils/bufread.lua
utils/evread.lua
utils/symtab.lua
)
list(APPEND LUAJIT_TOOLS_DEPS tools-parse-memprof)
Expand All @@ -36,6 +37,7 @@ else()
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/utils/avl.lua
${CMAKE_CURRENT_SOURCE_DIR}/utils/bufread.lua
${CMAKE_CURRENT_SOURCE_DIR}/utils/evread.lua
${CMAKE_CURRENT_SOURCE_DIR}/utils/symtab.lua
DESTINATION ${LUAJIT_DATAROOTDIR}/utils
PERMISSIONS
Expand Down Expand Up @@ -65,6 +67,7 @@ else()
sysprof.lua
utils/avl.lua
utils/bufread.lua
utils/evread.lua
utils/symtab.lua
)
list(APPEND LUAJIT_TOOLS_DEPS tools-parse-sysprof)
Expand All @@ -81,6 +84,7 @@ else()
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/utils/avl.lua
${CMAKE_CURRENT_SOURCE_DIR}/utils/bufread.lua
${CMAKE_CURRENT_SOURCE_DIR}/utils/evread.lua
${CMAKE_CURRENT_SOURCE_DIR}/utils/symtab.lua
DESTINATION ${LUAJIT_DATAROOTDIR}/utils
PERMISSIONS
Expand Down
32 changes: 32 additions & 0 deletions tools/utils/evread.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local bufread = require('utils.bufread')
local symtab = require('utils.symtab')

local function make_error_handler(fmt, inputfile)
return function(err)
io.stderr:write(string.format(fmt, inputfile))
io.stderr:write(string.format('\n\t%s\n', err))
os.exit(1, true)
end
end

return function(parser, inputfile)
local _, reader = xpcall(
bufread.new,
make_error_handler('Failed to open %s.', inputfile),
inputfile
)

local _, symbols = xpcall(
symtab.parse,
make_error_handler('Failed to parse symtab from %s.', inputfile),
reader
)

local _, events = xpcall(
parser,
make_error_handler('Failed to parse profile data from %s.', inputfile),
reader,
symbols
)
return events, symbols
end

0 comments on commit 357a24d

Please sign in to comment.