From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 2F1DE6EFDA; Wed, 11 May 2022 11:26:27 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2F1DE6EFDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1652257587; bh=fwikthBayGaNzHYu54xs8vTu1bmrQC18/BATB805+Ko=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Cn977fWmjOsIwNAO8AB3raT4bEltjeQzpslCg9hwxdkP0TFySdkGnqximjGV25qdd I39obrzPhl/8ztjvS2WOospgYUb5cSx2d9l91sFTO/zEWtrTgGG83H4MAQHvYo1KWQ Sxg9+daQYvEeTf/MAdbO7/bq2v/HI5E2FDrtHkcM= Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 8ACD16F860 for ; Wed, 11 May 2022 11:25:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8ACD16F860 Received: by mail-lf1-f48.google.com with SMTP id j4so2206335lfh.8 for ; Wed, 11 May 2022 01:25:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Yv0s0TGlsgF1vRgeE7/4vSRgI2f/xZC/HCRogWwR04=; b=jKFCFBMW3U1hozua1CAflc9+htu4XUZKijw60JkK8xildfZV1KhfX4hYG8rPO/GVZT W5tcWUy0NDUJLIjK4UwhJ23mYveOoBuRt74Whj107MfCtnSEOGow2qvcAUD7+zPQO0zZ NGZpS23FH6XuwsU5ZKyOLO2CWi8mRy8gBEYEUGGN57UeNB9zE/TxC4kvvQWgg1Wma7tM 5sY0/cVXrKc0K7VNdKO9383WW8o/D59Ymh4SFQz/6Gkgq2qb3iJs2dHSTj+TBX12DBu2 j3lfmQNKVx3sBUZ90yY9YC95n1hYvUaM25WCdeFh8IT9Sy5hP8OIAQ5oia+RV+kzsEb9 QhaQ== X-Gm-Message-State: AOAM530o4trjJj7U2OxvLX2eN8STCWIOuelmQ6+TDGQVrgg9f161ODuy 7+TOv7USxoUYmEtffAPaKgNpyPShK2MkSQ== X-Google-Smtp-Source: ABdhPJxqYizj/9RI1YEJFxJhVhP3WxVIPNFFJOKOVKHFwj1AQZXdT610RWr79tCznGYn0araYsGvzA== X-Received: by 2002:a05:6512:3f8c:b0:45d:cb2a:8779 with SMTP id x12-20020a0565123f8c00b0045dcb2a8779mr20072693lfa.499.1652257527853; Wed, 11 May 2022 01:25:27 -0700 (PDT) Received: from localhost.localdomain ([93.175.11.199]) by smtp.gmail.com with ESMTPSA id 20-20020ac25f54000000b0047255d21167sm174724lfz.150.2022.05.11.01.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 01:25:27 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Wed, 11 May 2022 11:25:19 +0300 Message-Id: <20220511082521.389687-3-m.kokryashkin@tarantool.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220511082521.389687-1-m.kokryashkin@tarantool.org> References: <20220511082521.389687-1-m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] sysprof: enrich symtab on a new trace or a proto X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Maxim Kokryashkin via Tarantool-patches Reply-To: Maxim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This commit adds functionality introduced in 0847e71abf7db2559e2bfa35f147ccf0112035e3 ('memprof: enrich symtab when meeting new prototype') and 0243fb72b05c7c63481c50151c65bef6b04e3372 ('memprof: enrich symtab when new trace is compiled') to sysprof. Both the proto and the trace symtab extensions cannot be run from the sysprof's signal handler, so it is required to prevent sysprof from dumping anything in its signal handler during the process to keep the event stream intact. That is achieved with setting the sysprof's internal state to `SPS_IDLE`. Part of tarantool/tarantool#781 --- Branch: https://github.com/tarantool/luajit/tree/fckxorg/sysprof-rc-full-ci src/lj_bcread.c | 7 +++++++ src/lj_parse.c | 6 ++++++ src/lj_sysprof.c | 44 ++++++++++++++++++++++++++++++++++++++++- src/lj_sysprof.h | 9 ++++++++- src/lj_trace.c | 7 +++++++ tools/sysprof/parse.lua | 18 ++++++++++++----- 6 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/lj_bcread.c b/src/lj_bcread.c index cb08599d..f6c7ad25 100644 --- a/src/lj_bcread.c +++ b/src/lj_bcread.c @@ -25,6 +25,9 @@ #if LJ_HASMEMPROF #include "lj_memprof.h" #endif +#if LJ_HASSYSPROF +#include "lj_sysprof.h" +#endif /* Reuse some lexer fields for our own purposes. */ #define bcread_flags(ls) ls->level @@ -390,6 +393,10 @@ GCproto *lj_bcread_proto(LexState *ls) lj_memprof_add_proto(pt); #endif +#if LJ_HASSYSPROF + lj_sysprof_add_proto(pt); +#endif + return pt; } diff --git a/src/lj_parse.c b/src/lj_parse.c index 30b0caa0..af0dc53f 100644 --- a/src/lj_parse.c +++ b/src/lj_parse.c @@ -30,6 +30,9 @@ #if LJ_HASMEMPROF #include "lj_memprof.h" #endif +#if LJ_HASSYSPROF +#include "lj_sysprof.h" +#endif /* -- Parser structures and definitions ----------------------------------- */ @@ -1598,6 +1601,9 @@ static GCproto *fs_finish(LexState *ls, BCLine line) #if LJ_HASMEMPROF lj_memprof_add_proto(pt); #endif +#if LJ_HASSYSPROF + lj_sysprof_add_proto(pt); +#endif L->top--; /* Pop table of constants. */ ls->vtop = fs->vbase; /* Reset variable stack. */ diff --git a/src/lj_sysprof.c b/src/lj_sysprof.c index 28d7d229..23947315 100644 --- a/src/lj_sysprof.c +++ b/src/lj_sysprof.c @@ -238,7 +238,7 @@ static void stream_guest(struct sysprof *sp, uint32_t vmstate) static void stream_host(struct sysprof *sp, uint32_t vmstate) { struct lua_State *L = gco2th(gcref(sp->g->cur_L)); - lj_symtab_dump_newc(&sp->lib_adds, &sp->out, LJP_SYMTAB_EVENT, L); + lj_symtab_dump_newc(&sp->lib_adds, &sp->out, LJP_SYMTAB_CFUNC_EVENT, L); lj_wbuf_addbyte(&sp->out, (uint8_t)vmstate); stream_backtrace_host(sp); } @@ -496,6 +496,38 @@ int lj_sysprof_report(struct luam_Sysprof_Counters *counters) return PROFILE_SUCCESS; } +void lj_sysprof_add_proto(const struct GCproto *pt) +{ + struct sysprof *sp = &sysprof; + + if (sp->state != SPS_PROFILE) + return; + + /* + ** XXX: Avoid sampling during the symtab extension. That shouldn't have any + ** significant effect on profile precision, but if it does, it's better to + ** implement an async-safe queue for the symtab events. + */ + sp->state = SPS_IDLE; + lj_wbuf_addbyte(&sp->out, LJP_SYMTAB_LFUNC_EVENT); + lj_symtab_dump_proto(&sp->out, pt); + sp->state = SPS_PROFILE; +} + +void lj_sysprof_add_trace(const struct GCtrace *tr) +{ + struct sysprof *sp = &sysprof; + + if (sp->state != SPS_PROFILE) + return; + + /* See the comment about the sysprof state above. */ + sp->state = SPS_IDLE; + lj_wbuf_addbyte(&sp->out, LJP_SYMTAB_TRACE_EVENT); + lj_symtab_dump_trace(&sp->out, tr); + sp->state = SPS_PROFILE; +} + #else /* LJ_HASSYSPROF */ int lj_sysprof_configure(const struct luam_Sysprof_Config *config) @@ -522,4 +554,14 @@ int lj_sysprof_report(struct luam_Sysprof_Counters *counters) return PROFILE_ERRUSE; } +void lj_sysprof_add_proto(const struct GCproto *pt) +{ + UNUSED(pt); +} + +void lj_sysprof_add_trace(const struct GCtrace *tr) +{ + UNUSED(tr); +} + #endif /* LJ_HASSYSPROF */ diff --git a/src/lj_sysprof.h b/src/lj_sysprof.h index 2978bbd8..c31d61d8 100644 --- a/src/lj_sysprof.h +++ b/src/lj_sysprof.h @@ -15,6 +15,7 @@ #ifndef _LJ_SYSPROF_H #define _LJ_SYSPROF_H +#include "lj_jit.h" #include "lj_obj.h" #include "lmisclib.h" @@ -80,7 +81,9 @@ #define LJP_FRAME_LUA_LAST 0x80 #define LJP_FRAME_HOST_LAST NULL -#define LJP_SYMTAB_EVENT ((uint8_t)10) +#define LJP_SYMTAB_LFUNC_EVENT ((uint8_t)10) +#define LJP_SYMTAB_CFUNC_EVENT ((uint8_t)11) +#define LJP_SYMTAB_TRACE_EVENT ((uint8_t)12) #define LJP_EPILOGUE_BYTE 0x80 int lj_sysprof_configure(const struct luam_Sysprof_Config *config); @@ -91,4 +94,8 @@ int lj_sysprof_stop(lua_State *L); int lj_sysprof_report(struct luam_Sysprof_Counters *counters); +void lj_sysprof_add_proto(const struct GCproto *pt); + +void lj_sysprof_add_trace(const struct GCtrace *tr); + #endif diff --git a/src/lj_trace.c b/src/lj_trace.c index 84b957c6..d7a78d4d 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -33,6 +33,9 @@ #if LJ_HASMEMPROF #include "lj_memprof.h" #endif +#if LJ_HASSYSPROF +#include "lj_sysprof.h" +#endif /* -- Error handling ------------------------------------------------------ */ @@ -171,6 +174,10 @@ static void trace_save(jit_State *J, GCtrace *T) #if LJ_HASMEMPROF lj_memprof_add_trace(T); #endif + +#if LJ_HASSYSPROF + lj_sysprof_add_trace(T); +#endif } void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T) diff --git a/tools/sysprof/parse.lua b/tools/sysprof/parse.lua index cb271784..555b6b3b 100755 --- a/tools/sysprof/parse.lua +++ b/tools/sysprof/parse.lua @@ -33,7 +33,9 @@ M.FRAME = { } local STREAM_END = 0x80 -local SYMTAB_EVENT = 10 +local SYMTAB_LFUNC_EVENT = 10 +local SYMTAB_CFUNC_EVENT = 11 +local SYMTAB_TRACE_EVENT = 12 local function new_event() return { @@ -128,8 +130,14 @@ local function parse_trace(reader, event, symbols) -- parse_lua_callchain(reader, event) end -local function parse_symtab(reader, symbols) - symtab.parse_sym_cfunc(reader, symbols) +local function parse_symtab(reader, symbols, vmstate) + if vmstate == SYMTAB_LFUNC_EVENT then + symtab.parse_sym_lfunc(reader, symbols) + elseif vmstate == SYMTAB_CFUNC_EVENT then + symtab.parse_sym_cfunc(reader, symbols) + elseif vmstate == SYMTAB_TRACE_EVENT then + symtab.parse_sym_trace(reader, symbols) + end end local event_parsers = { @@ -152,8 +160,8 @@ local function parse_event(reader, events, symbols) if vmstate == STREAM_END then -- TODO: samples & overruns return false - elseif vmstate == SYMTAB_EVENT then - parse_symtab(reader, symbols) + elseif SYMTAB_LFUNC_EVENT <= vmstate and vmstate <= SYMTAB_TRACE_EVENT then + parse_symtab(reader, symbols, vmstate) return true end -- 2.35.1