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 97044122A180; Thu, 13 Feb 2025 14:14:33 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 97044122A180 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1739445273; bh=Sx/fjOyNsGPOmNgJR9/l5RKPugsmBHTgoMFRBgdA17I=; 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=XTxGj+WxsvDN7N5BYUZFlDTrzc6vwKueLtu+LQ5VbRDaf0+KRIaBsv5Riew76vtwo GKA6wLMBtX3XYlcZrXuXYIa2jQGPajYNalsoGyncI3q3PGCo8mjGVMB2yqEHQD33Df lrYP2C2G7hTRZCKXdH4riApEROeoPj9kEgpEIJG8= Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 DCFFD12292DC for ; Thu, 13 Feb 2025 14:11:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DCFFD12292DC Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-aaee2c5ee6eso129771166b.1 for ; Thu, 13 Feb 2025 03:11:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739445115; x=1740049915; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DQyV10p7I8g9hZdTou4yCQL9aMwGa39Uj8si/iTR40U=; b=KD2e6/tJCoHaVG4kBev4F216QF69zBV0cfGpGiOVQ2BCBCR7cplWFa8tadNr9AV6z2 pTeo1AdWkXO6GVivgc81dmqbVGqdl1udK3BBCQmB0O2g1YUcJXQNX9KfXDqMpb8qzX7o vHBgYgVw4SEakuFQG6QzMyjvYM09KpKLzAnn7u5YEmcMy9ce33xOnFH09Fhh8CpQWY90 3J3rWo5vcNmfbsTGSBmJBaJSTdRD1adD9M4dMTq4RVWgXlI5ySEBKWM3T+AKkQ0X3NFO SIvQIw9xV/WiwtgM0d1HtNiAoWq84+3g8bHIpHPRYwNa7sLa5HHFJLpvEQ0Z7gXsmJJl OUKQ== X-Gm-Message-State: AOJu0YyHHwjv57199evirAmCvI/yKELwiheKUpWaZIFS+EThIzWrqrCU 8bZUC0HxNAkuiN+lT18uszvMzZL6TFIBxTmrFqd01MqNV192i9nxhKwFlcWw X-Gm-Gg: ASbGncuuGpqCcnZ9L9d24KZw4LuzB0g6w0sWWyIrGUNHgkbEhLn2ODDphvaGmg235nv 8mrOhV8ecCvhIWj5s2Emv0TvIhS0MFfAz/PG94WRmaOsb2f4YqS3Turs/O7Rx7p+POdPSoDvb2Z LChjEvNym2l8174qM2zXCiT31DyVc+V/xUd5gHmbAkEIway4jYYEX3Gjpd+an0if+UMkTv3V1rK 2Ikw9gArG1a6hA64DTQ49CVyjaOnMRragSdJSTLCUZNI+Q/HgC3/u/Uz85gQOYRDfNz0k14LXQ3 IwLzTw== X-Google-Smtp-Source: AGHT+IErqxAkJNWE1Jfec4mFworxF9C+PooL7Saunow1YIPxpkVKyUbfetQUytCdknxVrsEPm6QlmA== X-Received: by 2002:a17:907:3da5:b0:ab7:758c:b398 with SMTP id a640c23a62f3a-ab7f339c7ebmr701339366b.20.1739445114533; Thu, 13 Feb 2025 03:11:54 -0800 (PST) Received: from localhost ([5.181.62.98]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aba533bfaabsm109290966b.181.2025.02.13.03.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 03:11:54 -0800 (PST) X-Google-Original-From: Sergey Bronnikov To: tarantool-patches@dev.tarantool.org, Sergey Kaplun Date: Thu, 13 Feb 2025 14:10:51 +0300 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit 7/7] memprof: set default path to profiling output file 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: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" sysprof has an optional parameter `path`, that set a path to profiling output file, by default the path is `sysprof.bin`. `misc.memprof.start()` requires to set a path to profiling output file. The patch fixes this inconsistency by introducing a default path to memprof profiling output file - `memprof.bin`. --- src/lib_misc.c | 5 ++- ...misclib-memprof-lapi-default-file.test.lua | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua diff --git a/src/lib_misc.c b/src/lib_misc.c index 7666d85f..4f5d72fc 100644 --- a/src/lib_misc.c +++ b/src/lib_misc.c @@ -398,6 +398,8 @@ LJLIB_CF(misc_sysprof_report) #define LJLIB_MODULE_misc_memprof +#define MEMPROF_DEFAULT_OUTPUT "memprof.bin" + /* local started, err, errno = misc.memprof.start(fname) */ LJLIB_CF(misc_memprof_start) { @@ -407,7 +409,8 @@ LJLIB_CF(misc_memprof_start) return sysprof_error(L, PROFILE_ERRUSE, err_details); #endif /* !LJ_HASMEMPROF */ struct lj_memprof_options opt = {0}; - const char *fname = strdata(lj_lib_checkstr(L, 1)); + GCstr *s = lj_lib_optstr(L, 1); + const char *fname = s ? strdata(s) : MEMPROF_DEFAULT_OUTPUT; struct profile_ctx *ctx; int memprof_status; diff --git a/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua b/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua new file mode 100644 index 00000000..b6233d4a --- /dev/null +++ b/test/tarantool-tests/profilers/misclib-memprof-lapi-default-file.test.lua @@ -0,0 +1,41 @@ +local tap = require("tap") +local test = tap.test("misc-memprof-lapi-default-file"):skipcond({ + ["Memprof is implemented for x86_64 only"] = jit.arch ~= "x86" and + jit.arch ~= "x64", + ["Memprof is disabled"] = os.getenv('LUAJIT_DISABLE_MEMPROF'), +}) + +test:plan(1) + +local tools = require "utils.tools" + +test:test("default-output-file", function(subtest) + + subtest:plan(1) + + local def_output_file = 'memprof.bin' + os.remove(def_output_file) + + local res, err = misc.memprof.start() + -- Should start successfully. + assert(res, err) + + res, err = misc.memprof.stop() + -- Should stop successfully. + assert(res, err) + + -- Want to cleanup carefully if something went wrong. + if not res then + os.remove(def_output_file) + error(err) + end + + local profile_buf = tools.read_file(def_output_file) + subtest:ok(profile_buf ~= nil and #profile_buf ~= 0, + 'default output file is not empty') + + -- We don't need it any more. + os.remove(def_output_file) +end) + +test:done(true) -- 2.34.1