From patchwork Sat Jan 3 01:18:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1197 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403177; bh=SX6z3+fCoLPBn06Xn7Q0TTUr7CZfpUX4wXFr6WzS0Qc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=OX/8e9f63hg1hAwZCIipePeTliFV4TEUZzfrBfSleonJnHkELZe1X4rTWRI0/fcD9 hniLE5wuCtLjDF3V/uftUCYmegI12/zV5wBlNB1dtKqGurWD95fZAkzmov+/MmLvVs AfZjA3Grxovr3ja8NiKZQzmDsgbgichC+J/iFODjRE+pJ63Y/g2VjFzo/INifpmawI V0/AT8mwQSNAgDXoV+6J8csrGbCxsJ7VBRh1tltAITBktXkDBczxRTTAlXnM3eIiO5 N2RwGtgAdjM9YNMgyOf5WE1SLaTBPUKMMVLFB2OzvgoA753o+t4ZORzPg47jQslb4s Oy+h+g9Sw3vfQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 751686904E for ; Fri, 2 Jan 2026 18:19:37 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id IDd1SxL4kmk8 for ; Fri, 2 Jan 2026 18:19:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403177; bh=SX6z3+fCoLPBn06Xn7Q0TTUr7CZfpUX4wXFr6WzS0Qc=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=OX/8e9f63hg1hAwZCIipePeTliFV4TEUZzfrBfSleonJnHkELZe1X4rTWRI0/fcD9 hniLE5wuCtLjDF3V/uftUCYmegI12/zV5wBlNB1dtKqGurWD95fZAkzmov+/MmLvVs AfZjA3Grxovr3ja8NiKZQzmDsgbgichC+J/iFODjRE+pJ63Y/g2VjFzo/INifpmawI V0/AT8mwQSNAgDXoV+6J8csrGbCxsJ7VBRh1tltAITBktXkDBczxRTTAlXnM3eIiO5 N2RwGtgAdjM9YNMgyOf5WE1SLaTBPUKMMVLFB2OzvgoA753o+t4ZORzPg47jQslb4s Oy+h+g9Sw3vfQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 62FD468FAF for ; Fri, 2 Jan 2026 18:19:37 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403175; bh=8Qmf5y8pD51G4Y3MkDNjlsESCkItKZPPFUuYpYUA1ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=adGVS2+D4hMwpHTmpXbMIaTOh05VfV71SmAIF6i6zJpGcF1reDwKyo5AZE2MZTygq TZqSUHNQ4pnSxbUgzJywH/g+T4UA+Lalc4YA0kKohPrKZZs7o55APXK8PNC7768ewK 1rrqt0D2eQAvcSvE5b5FmPfbf1++U621WjovO6p8seVJb/AGnip4j3+ueoRgaRcVFj IXoKuRi1GozEv8hBa7OoyhYO4Bj2nUAIawNr0Y3c+3BQA5z9K/TC5DTFvOr+9BHSw+ OVItOW067Hk5DxctXtv0gGmn/1fsmesaUGJ0O5Ehi9xvsgA2OYPSYDPeK/YqGr04H1 bvA8t1JhEN3kg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7C25568FAF; Fri, 2 Jan 2026 18:19:35 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id EgehyaNutcsg; Fri, 2 Jan 2026 18:19:35 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767403171; bh=4ptYSo4aRpCMLsi4lXlguRPH4cS4D7zfvSE2+PtYZ9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h6Uw/5PG3Nlc3JykkV1z3CPjhaRINc0UppXWMPeN/z2ITqCXQU98WHx2W4G7TI9qr soYPn9WA3j/k0dFviK1Zzb+DZDGo7surIkqOd5UcVLtLhfUFTNSl5gadH72a4wJIw6 C7QnDUAnw8EA/hW6y50heLxzoDuD8dm53iIy1nB58HaV8Qd3Ta5ykrYU6yhwiB/E8t u1N2bR/P6GWRyCOWLLEWmnCBTWq5JExJ/1E5zB9wNptEgeIL4+4j5OzBFBEb2sLYFY uvhFP1ssF4Oa+QRJjJDKU+if7BavrYxm/mLCYbZn40ChgDZ5raek0cHep6TtUW5h2F 7It0U0cI2YhRA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2A62068F5F; Fri, 2 Jan 2026 18:19:31 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 2 Jan 2026 18:18:39 -0700 Message-ID: <20260103011908.149445-4-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103011908.149445-1-sjg@u-boot.org> References: <20260103011908.149445-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 33YBQ5DEEYAHNGO43OBABDT5EA3FRPLX X-Message-ID-Hash: 33YBQ5DEEYAHNGO43OBABDT5EA3FRPLX X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 03/24] sandbox: Add gprof profiling support List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add a GPROF=1 build option to enable gprof profiling for sandbox. This adds the -pg flag to both compiler and linker when GPROF=1 is set, following the same pattern as the existing FTRACE option. Usage: make GPROF=1 sandbox_defconfig all ./u-boot -T -c "ut dm" ... gprof u-boot gmon.out Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/config.mk | 4 ++++ config.mk | 4 ++++ doc/develop/trace.rst | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk index b92c259d2e3..92bac07963e 100644 --- a/arch/sandbox/config.mk +++ b/arch/sandbox/config.mk @@ -10,6 +10,10 @@ PLATFORM_LIBS += -L$(GCC_LIB_DIR) -lbacktrace endif PLATFORM_LIBS += -lrt +ifdef GPROF +PLATFORM_LIBS += -pg +endif + SDL_CONFIG ?= sdl2-config # Define this to avoid linking with SDL, which requires SDL libraries diff --git a/config.mk b/config.mk index e294be2a4c4..82fdbf3b4f6 100644 --- a/config.mk +++ b/config.mk @@ -63,6 +63,10 @@ ifdef FTRACE PLATFORM_CPPFLAGS += -finstrument-functions -DFTRACE endif +ifdef GPROF +PLATFORM_CPPFLAGS += -pg +endif + ######################################################################### RELFLAGS := $(PLATFORM_RELFLAGS) diff --git a/doc/develop/trace.rst b/doc/develop/trace.rst index d3c8628d124..d3393244658 100644 --- a/doc/develop/trace.rst +++ b/doc/develop/trace.rst @@ -491,6 +491,46 @@ can dramatically increase the size of the trace output as well as the execution time. +Wall-clock Profiling with gprof (Sandbox) +----------------------------------------- + +For sandbox builds, an alternative to U-Boot's internal tracing is to use +the standard GNU gprof profiler. This provides wall-clock profiling with +less overhead than function instrumentation, and produces output that can +be analysed with standard tools. + +To build sandbox with gprof support:: + + make GPROF=1 O=/tmp/b/sandbox sandbox_defconfig + make GPROF=1 O=/tmp/b/sandbox + +Then run U-Boot. A `gmon.out` file is created in the current directory when +the program exits:: + + cd /tmp/b/sandbox + ./u-boot -T -c "ut dm dm_test_rtc_set_get" + +Analyse the results with gprof:: + + gprof u-boot gmon.out | less + +This shows a flat profile (functions sorted by time) and a call graph. The +flat profile shows which functions consume the most CPU time:: + + % cumulative self self total + time seconds seconds calls ms/call ms/call name + 29.41 0.05 0.05 36922 0.00 0.00 memset + 17.65 0.08 0.03 read_uleb128 + 11.76 0.10 0.02 328472 0.00 0.00 string + ... + +The call graph shows the call hierarchy and time spent in each call chain. + +Note that gprof measures CPU time, not wall-clock time, so I/O wait time is +not captured. For boot-time optimisation where I/O is significant, use +bootstage or the internal trace system instead. + + Future Work -----------