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 9E2F5F28BEB; Mon, 10 Feb 2025 17:53:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9E2F5F28BEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1739199236; bh=brkrp237ZzwmxsDMjLpxot1KtT2cEYQB2tyRqwCD9jQ=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=dBkeoRZmjt0CXbNbchnFSVpuTX2+Vozv2VjFOCmbDPTki1k6EKDVr63hhdtZu2hKp 1de1sj6gUCUVooPXAW9qG7brbn4cVXht7RJpl9NxCLjT2YQPZ1AlAd2EE0KJb40dNK jTNQrmazI+wCvQ+4+JN+PwRm3zC6Cj0VEDTmvpzg= Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.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 3B3ABF28BEE for ; Mon, 10 Feb 2025 17:53:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3B3ABF28BEE Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5de75004cd9so1755368a12.1 for ; Mon, 10 Feb 2025 06:53:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739199210; x=1739804010; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ycumDGCFvdny+iSg0eKKwCEIISnHiufkUE+BD+eDpmg=; b=blCRrxoqRZ4bL2btzTWGOBJ1gd1Sg+tNbjO/l3Oa+5ZZXCDNtZI2BtZqTMNNSnzDR3 tWTLpPnjb4yIR8W5uB3m5q49zvE7wMkuA60EXPvGoglzhRQWMqdk1PXHiv4GndthVLHh KgIMIj789zoP7GQXc5iN+enU5fkCxuihSdb9Vacl7QifV6TLYK9i1mlIhzsWos8YCHsd WOfxNL5gUchiZSqwIwf7gxGfTxNLNOMt3Jlr/l1ukU4F84o2z/EGLx89j+Ip1c3XlJB7 7FHWUEiggMvscNu6DGRRRo4fvK0zk7wkmBRsmQRRV9v9+YoVVPMQnOxk9pnJvPIRVu1r xPuw== X-Gm-Message-State: AOJu0YzhMItcq1WsM6Jp4KbHKfPE77XmzV8bzWT4AHaP54AsZix9WVW4 K619y+OEcn6tjSEg2vwCaxJqpYKEqo4Bua4RxLUylA/cjoZESJWkDRUMTZRI X-Gm-Gg: ASbGncu8jvdAj8uDgsb5vmi2ZDr580NW1KVxmTHHTkW13dJJPCYokxDWLfWLBSgOrTF LhxFRasQEQryJEbD6OZtgjV688WUlIfnmWBR+P3L3HQTWLtffArQSTb1yuTQyY6SBrTAHC4QKfp M4Rs90GuAS5wQOkyUlX6vVr2T2jgVyXELvzpIJzY5kg0QkloqrpOXsD+uh9IKxcc9z9JY+BSaMy 7AQK0WN0mXtkBOmFGZ75DopEeDXySwgaMh+/eB18w83/PNBPtBiIsFMhdBS4ih/L6vCXzbpa8hy wD9G X-Google-Smtp-Source: AGHT+IH80zEDqxPPufhwUCCMxpHuiV5qxTkF5vpQAYdpy49NHFCiEGRLNoaeJkQ5epEfThXURWEcBQ== X-Received: by 2002:a05:6402:2392:b0:5de:4a8b:4c9c with SMTP id 4fb4d7f45d1cf-5de4a8b4fc4mr24570422a12.32.1739199209685; Mon, 10 Feb 2025 06:53:29 -0800 (PST) Received: from localhost ([5.181.62.98]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab794509fcesm643750066b.34.2025.02.10.06.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 06:53:29 -0800 (PST) X-Google-Original-From: Sergey Bronnikov To: tarantool-patches@dev.tarantool.org, Sergey Kaplun Date: Mon, 10 Feb 2025 17:52:01 +0300 Message-Id: <9c71b2f18bf2d3748a189591fce710a61c9a7f86.1739199089.git.sergeyb@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit] Always close profiler 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" From: Mike Pall Reported by Guilherme Batalheiro. (cherry picked from commit fca66335d131669cf017420af6963a7565babb58) Before the patch, a function `prof_finish` wrote a string `No samples collected` to profiler output file and then exits. Due to early exit, output file handle stay opened. This patch fixes condition and file handle is closed even a number of samples is equal to 0. Sergey Bronnikov: * added the description and the test for the problem Part of tarantool/tarantool#11055 --- Branch: https://github.com/tarantool/luajit/tree/ligurio/gh-xxxx-close-file-profiler Related issues: - https://github.com/luajIT/luajIT/issues/1304 - https://github.com/tarantool/tarantool/issues/11055 src/jit/p.lua | 4 +-- ...close-profile-dump-with-0-samples.test.lua | 30 +++++++++++++++++++ .../script.lua | 14 +++++++++ test/tarantool-tests/utils/tools.lua | 4 +++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples.test.lua create mode 100644 test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples/script.lua diff --git a/src/jit/p.lua b/src/jit/p.lua index 4569d69e..89b49584 100644 --- a/src/jit/p.lua +++ b/src/jit/p.lua @@ -228,9 +228,7 @@ local function prof_finish() local samples = prof_samples if samples == 0 then if prof_raw ~= true then out:write("[No samples collected]\n") end - return - end - if prof_ann then + elseif prof_ann then prof_annotate(prof_count1, samples) else prof_top(prof_count1, prof_count2, samples, "") diff --git a/test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples.test.lua b/test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples.test.lua new file mode 100644 index 00000000..b50b5fce --- /dev/null +++ b/test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples.test.lua @@ -0,0 +1,30 @@ +local tap = require('tap') +local test = tap.test('lj-1304-close-profile-dump-with-0-samples'):skipcond({ + ['Test requires /proc filesystem'] = jit.os == 'OSX', +}) +local utils = require('utils') + +test:plan(1) + +-- Test file to demonstrate LuaJIT incorrect behaviour with missed +-- close a file handle for profile output file. +-- See also: https://github.com/luajIT/luajIT/issues/1304 + +local p_filename = '/tmp/profile' + +-- runs %testname%/script.lua by +-- with the given environment, launch options and CLI arguments. +local script = utils.exec.makecmd(arg) +-- Execute a Lua script with start and stop LuaJIT profiler, +-- it is expected no samples found by profiler. The script's +-- output is suppressed, it is not interested. +local _ = script(p_filename) + +local p_content = io.open(p_filename):read('a*') +test:is(utils.tools.trim(p_content), '[No samples collected]', + 'profile dump has no samples') + +-- Teardown. +os.remove(p_filename) + +test:done(true) diff --git a/test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples/script.lua b/test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples/script.lua new file mode 100644 index 00000000..77335a08 --- /dev/null +++ b/test/tarantool-tests/lj-1304-close-profile-dump-with-0-samples/script.lua @@ -0,0 +1,14 @@ +local p_options = 'ri1' +local p_filename = assert(arg[1], 'filename argument is missing') + +require('jit.p').start(p_options, p_filename) + +-- No code to generate profiling samples. + +-- Stop profiler to execute `jit/p.lua:prof_fmt()`. With zero +-- samples it triggers early return without closing the file. +require('jit.p').stop() + +-- Make sure LuaJIT profiler is close a file handle. +local ls_output = io.popen('ls -l /proc/$$/fd'):read('a*') +assert(ls_output:find(p_filename) == nil, 'file is open') diff --git a/test/tarantool-tests/utils/tools.lua b/test/tarantool-tests/utils/tools.lua index 33fcae78..9cb65daf 100644 --- a/test/tarantool-tests/utils/tools.lua +++ b/test/tarantool-tests/utils/tools.lua @@ -21,4 +21,8 @@ function M.read_file(path) return content end +function M.trim(str) + return (str:gsub('^%s*(.-)%s*$', '%1')) +end + return M -- 2.34.1