From nobody Sat Feb 03 07:20:55 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TRkZh29tzz58Xy1 for ; Sat, 3 Feb 2024 07:21:00 +0000 (UTC) (envelope-from paulf2718@gmail.com) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TRkZg2Ndgz4FNv for ; Sat, 3 Feb 2024 07:20:59 +0000 (UTC) (envelope-from paulf2718@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=GAVPjU0g; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of paulf2718@gmail.com designates 2a00:1450:4864:20::332 as permitted sender) smtp.mailfrom=paulf2718@gmail.com Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40e800461baso24424735e9.3 for ; Fri, 02 Feb 2024 23:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706944856; x=1707549656; darn=freebsd.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=Tx4oM0H2YgZ6B3c221EzZGyfLa7G4nIL24kbM9B0Fho=; b=GAVPjU0gZ/D2HfK7G0JV1Q8YNt/PIEzJldLvHJvNYvyzcQpWVg5wHDkR8iyd/Zb51i jXNcCSatmisGTuNGVks5cmAxnNIxV5k4dHI0m16KoZXsBFS7MbINRibPHdF9UGmGdm47 W1nmHOM9CZ2DirKmWqUq+hlHWARdivIt5lhxQClBf3fbR1rFE3YJ0+lpY8YA+DJ/Vuu8 9wlbkS/LD/VhCI3MBVcZJdRJ09IS9LzxCjbjIkavo837lfYhW03NCwUMHcxSOvmNEhls xIzfOwEyVXtANu14Sw6223WT4nw2AQvwNd9B7PqdNQXrRmMDvdCPvAu5opc2W9mU7UfZ PCDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706944856; x=1707549656; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tx4oM0H2YgZ6B3c221EzZGyfLa7G4nIL24kbM9B0Fho=; b=ZTW0hosla7UDLFJoCCG2Q+75AqIXJU2VP3RVTcYfn3FVoHg9DYiYkq8sOS8GtrWFlC +zcGJTXNcORXE3LH0QcHLem+g/aRdYvE8qPh2OHWhVDV+5ZTbCGPPHfOxUnOiNRA+QNj ggC1RwxxwXNAFnh+k9ti7iflqedAipiqvRMB4X+h9rIJAclxGxu4B3XBgvl0jX8UyymF knV6qglc+cMT/aSJeliRwTVVwaUzpjPMjlZt9KBTiOJePN6Y9BV3KAcUbyLmgBmahqZ0 Kl4WvTXQNrh7rddxkslVXEEp8IdynbhbWYtW8rxHl/X9NHmUDaoHpO2lvx1aZJWnyoet Ta7w== X-Gm-Message-State: AOJu0Yy/qwPzUk+TCkd8B0ifUpRnPfgnfEzDuuN8yQTKg+k2Ysn3zV2n gurwAGD52SUDjeuupq4dBoRI6vqhB7vwrP4P52LlT8TEYS7UePpg647Ew9nQ X-Google-Smtp-Source: AGHT+IHaEewdeZ7XbPeC2eIk2tKDSMRD8igKjBkvjxtIQVLyTO3/yFdan5ETP4+AutJfjxtMLe86Eg== X-Received: by 2002:a05:600c:3ca6:b0:40f:c234:1fd5 with SMTP id bg38-20020a05600c3ca600b0040fc2341fd5mr380225wmb.11.1706944856504; Fri, 02 Feb 2024 23:20:56 -0800 (PST) Received: from ?IPV6:2a01:cb15:8010:2f00:1aa9:5ff:fe16:2efb? ([2a01:cb15:8010:2f00:1aa9:5ff:fe16:2efb]) by smtp.gmail.com with ESMTPSA id l20-20020a05600c4f1400b0040ef622799fsm1999147wmq.37.2024.02.02.23.20.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Feb 2024 23:20:56 -0800 (PST) Message-ID: <03729a10-8b55-416f-beb4-3a4275d880b7@gmail.com> Date: Sat, 3 Feb 2024 08:20:55 +0100 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Profiling applications To: freebsd-hackers@freebsd.org References: Content-Language: en-US From: Paul Floyd In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.79 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.80)[-0.796]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::332:from] X-Rspamd-Queue-Id: 4TRkZg2Ndgz4FNv On 03-02-24 01:16, Chuck Tuffli wrote: > What is the recommended way of profiling applications on FreeBSD these > days? I’m looking for information like “28% of the execution time is > spent in function X”. > > —chuck First off, you will get best results with DWARF debuginfo. If you can, build your test exe with "-g -O3" or similar. The first answer should be pmcstat. When I've used it, it didn't inspire a great amount of confidence. The wiki page https://wiki.freebsd.org/PmcTools hasn't been updated in 15 years, so I've no idea if it is still relevant. pmc and pmcstat are in base. No commits for the last 2 or 3 years, and low activity before that. Using a non-debug kernel I get lots of addr2line: dwarf_init: Debug info NULL [_dwarf_consumer_init(66)] pmcstat: WARNING: addr2line function name read error pmcstat: WARNING: addr2line pipe error messages. Still, I can get to see some measurements with it. To see sampling data 0. pkg install kcachegrind 1. kldload hwpmc 2. profile: pmcstat -P inst_retired.any_p -O /tmp/pmctest.bin -d [your command and arguments] 3. convert to callgrind format: pmcstat -R/tmp/pmctest.bin -F/tmp/pmctest.cg 4. view results: kcachegrind /tmp/pmctest.cg The next thing that I would suggest is Google perftools. You will need to install google-perftools. Roughly, you will need to link with their library (iirc LD_PRELOAD should also work), set some environment variables and then run your exe. You'll need to do some postprocessing similar to pmcstat. perftools are fairly well documented on the web. Lastly, you could try cachegrind and callgrind. They are slow, do not accurately model the cache or branch prediction and not at all speculative execution. What they measure is accurate and as close to deterministic as you can get. A+ Paul