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 05E9B6EC55; Wed, 8 Sep 2021 20:53:30 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 05E9B6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1631123610; bh=ZnJtJv3re+hFJgStco2xABQT2HKT0enb2y2PI3LnXmU=; 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=auU5S28sSC+N7Z5iuYf9rXC5Sd6LquQEYpOplYc7xJa8GwGDE9GTHBiRe5aYem2aU CA7qHF3IrfwntyOn/w3RLt4+vmRP/m0k62DbVfsrCSsclBtMkmvUDNLIs95DPLayZG WzYGX9j3q/Ur3zIlG57dbbwjpYO1ClEUMOyu6lY0= Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 1C7D46EC55 for ; Wed, 8 Sep 2021 20:51:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1C7D46EC55 Received: by mail-lf1-f43.google.com with SMTP id e23so6464593lfj.9 for ; Wed, 08 Sep 2021 10:51:03 -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=UdBzfxbIuf7C4XrNiQP27R9GrvfG1paNqodQp0SloUE=; b=UFXUUA7Te4qpuRVLBSlkm9JYNddU/gSImgUu/2NDNEg9bGVhXiXs+ZMnCZkTWwd53F D3m/lGFab9gWhfLpaPry2uEDso1XqFOma9/KlYlls7DE6FwHqtt36IiYH68k2OgTGaI7 fdQsRYEt7x4Bi709cge1CrQX3CwICJvEaXVZtFhJkacx0Ob84Q4AaGr6MlSZHQ6sYDBt 7l+UI7yLM1iYmGaLYM6vQxc6HkFpxTHUWsq48X/+aneMkZuEtGo8T5Jkc19bG9Vuf6g5 g7WBDTma6SK18I9Cc1TYLPFRJYfripX7sKYoFs8LS0uuzCuqoJDrJzk84joytTZZiW4q BkjA== X-Gm-Message-State: AOAM53392WBA2luryfCwhX8MlWuYS5wVV2s2hDMhpcpOQAvSLcSj9s5M kHfxBnuucd14t5tlBOvK5ytqKzMnLRglEKNA X-Google-Smtp-Source: ABdhPJyCFC912mdpODLmIfoCaYtp3IAsv4PYmR/RCx3dhcnz/xOEpfHDgf6UbXzx3pcJ9wB1q87L5A== X-Received: by 2002:a05:6512:3f21:: with SMTP id y33mr3563049lfa.606.1631123462437; Wed, 08 Sep 2021 10:51:02 -0700 (PDT) Received: from localhost.localdomain ([93.175.11.199]) by smtp.gmail.com with ESMTPSA id x13sm249434lfq.262.2021.09.08.10.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 10:51:02 -0700 (PDT) X-Google-Original-From: Maxim Kokryashkin To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, skaplun@tarantool.org Date: Wed, 8 Sep 2021 20:50:48 +0300 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 5/7] memprof: add profile common section 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" A Lua API for sysprof needs to be introduced, but sysprof's C API is quite similar with memprof's. Considering this, there are some structures and functions that should be common between memprof's and sysprof's implementations of Lua API to avoid duplication. Part of tarantool/tarantool#781 --- src/lib_misc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib_misc.c b/src/lib_misc.c index 1dab08cc..a44476e0 100644 --- a/src/lib_misc.c +++ b/src/lib_misc.c @@ -75,9 +75,7 @@ LJLIB_CF(misc_getmetrics) #include "lj_libdef.h" -/* ----- misc.memprof module ---------------------------------------------- */ - -#define LJLIB_MODULE_misc_memprof +/* --------- profile common ---------------------------------------------- */ /* ** Yep, 8Mb. Tuned in order not to bother the platform with too often flushes. @@ -85,7 +83,7 @@ LJLIB_CF(misc_getmetrics) #define STREAM_BUFFER_SIZE (8 * 1024 * 1024) /* Structure given as ctx to memprof writer and on_stop callback. */ -struct memprof_ctx { +struct profile_ctx { /* Output file stream for data. */ FILE *stream; /* Profiled global_State for lj_mem_free at on_stop callback. */ @@ -101,7 +99,7 @@ struct memprof_ctx { static size_t buffer_writer_default(const void **buf_addr, size_t len, void *opt) { - struct memprof_ctx *ctx = opt; + struct profile_ctx *ctx = opt; FILE *stream = ctx->stream; const void * const buf_start = *buf_addr; const void *data = *buf_addr; @@ -140,19 +138,22 @@ static size_t buffer_writer_default(const void **buf_addr, size_t len, /* Default on stop callback. Just close the corresponding stream. */ static int on_stop_cb_default(void *opt, uint8_t *buf) { - struct memprof_ctx *ctx = opt; + struct profile_ctx *ctx = opt; FILE *stream = ctx->stream; UNUSED(buf); lj_mem_free(ctx->g, ctx, sizeof(*ctx)); return fclose(stream); } +/* ----- misc.memprof module ---------------------------------------------- */ + +#define LJLIB_MODULE_misc_memprof /* local started, err, errno = misc.memprof.start(fname) */ LJLIB_CF(misc_memprof_start) { struct lj_memprof_options opt = {0}; const char *fname = strdata(lj_lib_checkstr(L, 1)); - struct memprof_ctx *ctx; + struct profile_ctx *ctx; int memprof_status; /* -- 2.33.0