Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Maxim Kokryashkin <max.kokryashkin@gmail.com>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit v3 4/4] sysprof: improve parser's memory footprint
Date: Tue, 15 Aug 2023 18:52:00 +0000	[thread overview]
Message-ID: <ZNvJUHnUDSsqlKNS@tarantool.org> (raw)
In-Reply-To: <fccbf7a01164e2b75a88239b25202fd53efc068f.1690834846.git.m.kokryashkin@tarantool.org>

Max,

Thanks for the patch! Everything is OK in general, but please consider
my comments below.

On 31.07.23, Maxim Kokryashkin wrote:
> This patch reduces sysprof's parser memory footprint,
> by avoiding reading all callchains before collapsing them.
> Instead of it, parser merges stacks immediately after
> reading them and stores counts in a lua table.
> 
> The `collapse.lua` module is purged as a result of the
> patch, but it is left as a stub to keep the integrational
> testing intact. This stub should be removed in the next
> series.
> 
> Resolves tarantool/tarantool#8700
> ---
>  tools/CMakeLists.txt       |   4 ++
>  tools/sysprof.lua          |  21 +------
>  tools/sysprof/collapse.lua | 123 +-----------------------------------
>  tools/sysprof/parse.lua    | 126 ++++++++++++++++++++++++++-----------
>  4 files changed, 101 insertions(+), 173 deletions(-)
> 
> diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
> index dd7ec6bd..1ae559ee 100644
> --- a/tools/CMakeLists.txt
> +++ b/tools/CMakeLists.txt
> @@ -112,6 +112,8 @@ else()
>    add_custom_target(tools-parse-sysprof EXCLUDE_FROM_ALL DEPENDS
>      luajit-parse-sysprof
>      sysprof/parse.lua
> +    # FIXME: This line is not deleted only for the sake of integrational
> +    # testing. It should be deleted in the next series.

Minor: I'd rather left TODO instead of FIXME, but this is not a big
deal, so feel free to ignore.

>      sysprof/collapse.lua
>      sysprof.lua
>      utils/bufread.lua
> @@ -121,6 +123,8 @@ else()
>  
>    install(FILES
>        ${CMAKE_CURRENT_SOURCE_DIR}/sysprof/parse.lua
> +      # FIXME: This line is not deleted only for the sake of integrational
> +      # testing. It should be deleted in the next series.

Ditto.

>        ${CMAKE_CURRENT_SOURCE_DIR}/sysprof/collapse.lua
>      DESTINATION ${LUAJIT_DATAROOTDIR}/sysprof
>      PERMISSIONS

<snipped>

> diff --git a/tools/sysprof/collapse.lua b/tools/sysprof/collapse.lua
> index ac5269ea..9e815e0d 100755
> --- a/tools/sysprof/collapse.lua
> +++ b/tools/sysprof/collapse.lua
> @@ -1,120 +1,3 @@

<snipped>

> +-- FIXME: This line is not deleted only for the sake of
> +-- integrational testing. It should be deleted in the
> +-- next series.

Honestly, I would literally "purge" collapse.lua the following way:
replace all of its contents with the only assert call to check that
nobody will use it. However, if it breaks Tarantool, I agree to left it
intact until the file is removed completely from the source tree.

> diff --git a/tools/sysprof/parse.lua b/tools/sysprof/parse.lua
> index 5b52f104..19add4f3 100755
> --- a/tools/sysprof/parse.lua
> +++ b/tools/sysprof/parse.lua

<snipped>

> @@ -143,18 +153,63 @@ local function parse_symtab(reader, symbols, vmstate)

<snipped>

>  
> +local function insert_lua_callchain(chain, lua)
> +  local ins_cnt = 0
> +  local name_lua
> +  for _, fr in ipairs(lua.callchain) do
> +    ins_cnt = ins_cnt + 1
> +    if fr.type == FRAME.CFUNC then
> +      -- C function encountered, the next chunk
> +      -- of frames is located on the C stack.
> +      break
> +    end
> +    name_lua = fr.name
> +
> +    if fr.type == FRAME.LFUNC
> +    and lua.trace.traceno ~= nil
> +    and lua.trace.addr == fr.addr
> +    and lua.trace.line == fr.line
> +    then
> +            name_lua = lua.trace.name
> +    end

Something bad with indentation. I guess there should be something
similar to this:
| if fr.type == FRAME.LFUNC
|   and lua.trace.traceno ~= nil
|   and lua.trace.addr == fr.addr
|   and lua.trace.line == fr.line
| then
|   name_lua = lua.trace.name
| end

> +
> +    table.insert(chain, name_lua)
> +  end
> +  table.remove(lua.callchain, ins_cnt)
> +end

<snipped>

> @@ -171,8 +226,9 @@ local function parse_event(reader, events, symbols)
>    event.lua.vmstate = vmstate
>  
>    event_parsers[vmstate](reader, event, symbols)
> -
> -  table.insert(events, event)
> +  local callchain = merge(event)
> +  local cur_cnt = events[callchain]
> +  events[callchain] = (cur_cnt or 0) + 1

Minor: The following line looks better (IMHO), but feel free to ignore.
| events[callchain] = (events[callchain] or 0) + 1

>    return true
>  end
>  
> -- 
> 2.41.0
> 

-- 
Best regards,
IM

  reply	other threads:[~2023-08-15 19:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-31 20:30 [Tarantool-patches] [PATCH luajit v3 0/4] sysprof: parser refactoring Maxim Kokryashkin via Tarantool-patches
2023-07-31 20:30 ` [Tarantool-patches] [PATCH luajit v3 1/4] utils: remove unnecessary insertion in AVL-tree Maxim Kokryashkin via Tarantool-patches
2023-08-15 18:50   ` Igor Munkin via Tarantool-patches
2023-07-31 20:30 ` [Tarantool-patches] [PATCH luajit v3 2/4] sysprof: remove `split by vmstate` option Maxim Kokryashkin via Tarantool-patches
2023-08-15 18:51   ` Igor Munkin via Tarantool-patches
2023-07-31 20:30 ` [Tarantool-patches] [PATCH luajit v3 3/4] tools: add execution permission to sysprof parser Maxim Kokryashkin via Tarantool-patches
2023-08-15 18:51   ` Igor Munkin via Tarantool-patches
2023-07-31 20:30 ` [Tarantool-patches] [PATCH luajit v3 4/4] sysprof: improve parser's memory footprint Maxim Kokryashkin via Tarantool-patches
2023-08-15 18:52   ` Igor Munkin via Tarantool-patches [this message]
2023-08-15 18:54 ` [Tarantool-patches] [PATCH luajit v3 0/4] sysprof: parser refactoring Igor Munkin 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=ZNvJUHnUDSsqlKNS@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=max.kokryashkin@gmail.com \
    --subject='Re: [Tarantool-patches] [PATCH luajit v3 4/4] sysprof: improve parser'\''s memory footprint' \
    /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