Tarantool development patches archive
 help / color / mirror / Atom feed
From: Maxim Kokryashkin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: tarantool-patches@dev.tarantool.org, skaplun@tarantool.org,
	sergeyb@tarantool.org
Subject: [Tarantool-patches] [PATCH luajit v3 6/6] profilers: introduce event reader module
Date: Wed, 13 Mar 2024 17:40:18 +0300	[thread overview]
Message-ID: <0203bed32763ed20c596326d5ca9670491269c67.1710340671.git.m.kokryashkin@tarantool.org> (raw)
In-Reply-To: <cover.1710340671.git.m.kokryashkin@tarantool.org>

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
---
 Makefile.original      |  2 +-
 tools/CMakeLists.txt   |  4 ++++
 tools/utils/evread.lua | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 tools/utils/evread.lua

diff --git a/Makefile.original b/Makefile.original
index d0834fe6..4a1e1d9d 100644
--- a/Makefile.original
+++ b/Makefile.original
@@ -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
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index a4adc15b..695c079a 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -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)
@@ -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
@@ -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)
@@ -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
diff --git a/tools/utils/evread.lua b/tools/utils/evread.lua
new file mode 100644
index 00000000..394a4a03
--- /dev/null
+++ b/tools/utils/evread.lua
@@ -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
-- 
2.44.0


  parent reply	other threads:[~2024-03-13 14:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 14:40 [Tarantool-patches] [PATCH luajit v3 0/6] profilers: refactor parsers Maxim Kokryashkin via Tarantool-patches
2024-03-13 14:40 ` [Tarantool-patches] [PATCH luajit v3 1/6] build: purge sysprof.collapse module Maxim Kokryashkin via Tarantool-patches
2024-03-13 14:40 ` [Tarantool-patches] [PATCH luajit v3 2/6] build: fix tool components handling Maxim Kokryashkin via Tarantool-patches
2024-03-13 14:40 ` [Tarantool-patches] [PATCH luajit v3 3/6] memprof: refactor `heap_chunk` data structure Maxim Kokryashkin via Tarantool-patches
2024-03-13 14:40 ` [Tarantool-patches] [PATCH luajit v3 4/6] memprof: remove unused arguments Maxim Kokryashkin via Tarantool-patches
2024-03-13 14:40 ` [Tarantool-patches] [PATCH luajit v3 5/6] memprof: introduce the `--human-readable` option Maxim Kokryashkin via Tarantool-patches
2024-03-13 14:40 ` Maxim Kokryashkin via Tarantool-patches [this message]
2024-03-15  8:44 ` [Tarantool-patches] [PATCH luajit v3 0/6] profilers: refactor parsers Sergey Kaplun via Tarantool-patches
2024-03-20 15:08 ` Sergey Kaplun via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0203bed32763ed20c596326d5ca9670491269c67.1710340671.git.m.kokryashkin@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=max.kokryashkin@gmail.com \
    --cc=sergeyb@tarantool.org \
    --cc=skaplun@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH luajit v3 6/6] profilers: introduce event reader module' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox