From patchwork Sat Jan 3 20:04: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: 1226 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=1767470765; bh=WgrJl0yBgGiImTfO39U2SmkJnH+yg0wZuHbBgMNXVWA=; 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=QlFWq+3v6ndpjfsEUGiNd4CsKpNMqM0stWBoG1anNfkQdi3+CgPR4CS9QU19hnoJU 1Eo+5h9SbqwyyBVru0lPZQ8ctB3MwxobhavkOqAXWExfFM5DlJ3YhXYJqr2unBrrQT sbs0cU4OIzNQsU4pDIFUiR47WRRontpW/6t0e6rcndV3mclNrJNZdzEgLPGHehms0I BpdfOYtCd7kwefyeFgdxZKTIPtYX3K9dZ224YTOh+P8dajRzhrcSRXxFBSr5ggr3rA 0V4titJDu0yu/NCEzLfzVoltQ+nNJGg8pykFCXZq81HuGTgYAjQFp2seTgYJ8uCp5p 3XQOFFaYEg0aA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1366368FCC for ; Sat, 3 Jan 2026 13:06:05 -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 9DbM10559wZQ for ; Sat, 3 Jan 2026 13:06:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470765; bh=WgrJl0yBgGiImTfO39U2SmkJnH+yg0wZuHbBgMNXVWA=; 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=QlFWq+3v6ndpjfsEUGiNd4CsKpNMqM0stWBoG1anNfkQdi3+CgPR4CS9QU19hnoJU 1Eo+5h9SbqwyyBVru0lPZQ8ctB3MwxobhavkOqAXWExfFM5DlJ3YhXYJqr2unBrrQT sbs0cU4OIzNQsU4pDIFUiR47WRRontpW/6t0e6rcndV3mclNrJNZdzEgLPGHehms0I BpdfOYtCd7kwefyeFgdxZKTIPtYX3K9dZ224YTOh+P8dajRzhrcSRXxFBSr5ggr3rA 0V4titJDu0yu/NCEzLfzVoltQ+nNJGg8pykFCXZq81HuGTgYAjQFp2seTgYJ8uCp5p 3XQOFFaYEg0aA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 005AB68FD2 for ; Sat, 3 Jan 2026 13:06:04 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470763; bh=7pC190S5Co4GL6FFyASwPRK3PbYiFUqkawCO1WQAOiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNqv+/fTV8kwWXsickuNX4f49bRuNnBlZuaDEyMh+MbmT6pvtRYrU8aTsc8IFVZCY pyHonHs4v6Bq9zyowQN1SneaUoiY7dtHlmo9EB96PAKH4YYMHGr1fa6YuC+9QIht2L OfdHQ1UsLtFxGM+8EWkzeI0h39flNFgSgH3IrBsS3Ig1NofK67rhIgeVZD9OuUTOXd OU+eK1dnQ2twE7ZUAWrfCDGZtKzbHCWvVNjgqKKYQC003UvcRWLaWrkz+L3amURgzz tLl42/0jSHjMxqFriuaApGXnNxUR8KLCVuNGyNwRrqfcdcJOg/lVDsM8qjOcDhtQar AvizqSACN6tqw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E644A69095; Sat, 3 Jan 2026 13:06:03 -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 I4FXjgN2Fpat; Sat, 3 Jan 2026 13:06:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767470759; bh=4PZxrPa7jCbPB9CttD4+55qRP08v3lnl5gsimchxxmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KaNcZEzfgBn814NFEo8IJ1HWjFHPNML51ps4UGCXt5ixvIbfAfT9JT+6koq6VSByr MxrGjBvatPWTE5caMD4/de5tPDJP8BG7iplhG+iPwUW1MD+BAwpvNn9YI33yF3Gqo3 L7gN0suQXKmic0MflKxEWqV7clbyYkvpNFpa8IRJC1XvhkuDMK/Qa8925gj3JSGFeI RTOMkyNUANoHpkwVyLSa7gytsfx0sbdmrBK4zD7nqqIBdfpb15x36kkHnuxCyxPdkq li7GtqO3qsvQZovXBXRxYni0ogEliadRfNjtlZrOfgWkaT2UaY3tjLY4PG8YHBQxhI QzV6bgl2M0/cw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 59B1B68FCC; Sat, 3 Jan 2026 13:05:59 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 3 Jan 2026 13:04:39 -0700 Message-ID: <20260103200510.3605009-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260103200510.3605009-1-sjg@u-boot.org> References: <20260103200510.3605009-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 4NMWV5H4Y5BOPXXZ5PZ4FMQHV575TUWK X-Message-ID-Hash: 4NMWV5H4Y5BOPXXZ5PZ4FMQHV575TUWK 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 v2 08/29] 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 --- (no changes since v1) 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 -----------