From: "Alex Bennée" <alex.bennee@linaro.org>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Cc: qemu-devel@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Gustavo Romero" <gustavo.romero@linaro.org>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"rowan Hart" <rowanbhart@gmail.com>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH v4 4/7] contrib/plugins/uftrace: add timestamp-based-on-real-time option
Date: Tue, 05 Aug 2025 11:23:20 +0100 [thread overview]
Message-ID: <87v7n23w4n.fsf@draig.linaro.org> (raw)
In-Reply-To: <20250724204527.3175839-5-pierrick.bouvier@linaro.org> (Pierrick Bouvier's message of "Thu, 24 Jul 2025 13:45:23 -0700")
Pierrick Bouvier <pierrick.bouvier@linaro.org> writes:
> usage: timestamp-based-on-real-time=[on|off]
>
> Instead of using number of instructions executed (which is per vcpu), we
> use the wall time for timestamps. This is useful when tracing user mode
> programs as well.
Arguably it is the more useful default when examining flame graphs. The
instruction count is entirely artificial and wouldn't map onto real
execution time anyway.
Maybe use-icount-for-ts and default to off?
>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
> contrib/plugins/uftrace.c | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c
> index bd4219db693..9211f273700 100644
> --- a/contrib/plugins/uftrace.c
> +++ b/contrib/plugins/uftrace.c
> @@ -94,8 +94,28 @@ enum uftrace_record_type {
> static struct qemu_plugin_scoreboard *score;
> static uint64_t trace_sample;
> static bool trace_privilege_level;
> +static bool timestamp_based_on_real_time;
> static CpuOps arch_ops;
>
> +static uint64_t gettime_ns(void)
> +{
> +#ifdef _WIN32
> + /*
> + * On Windows, timespec_get is available only with UCRT, but not with
> + * MinGW64 environment. Simplify by using only gettimeofday on this
> + * platform.
> + */
> + struct timeval tv;
> + gettimeofday(&tv, NULL);
> + uint64_t now_ns = tv.tv_sec * 1000 * 1000 * 1000 + tv.tv_usec * 1000;
> +#else
> + struct timespec ts;
> + timespec_get(&ts, TIME_UTC);
> + uint64_t now_ns = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
Why use timspec_get here, QEMU's own timer uses:
/* get host real time in nanosecond */
static inline int64_t get_clock_realtime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000000LL + (tv.tv_usec * 1000);
}
> +#endif
> + return now_ns;
> +}
> +
> static void uftrace_write_map(bool system_emulation)
> {
> const char *path = "./uftrace.data/sid-0.map";
> @@ -454,6 +474,9 @@ static void cpu_set_new_sample(Cpu *cpu, uint64_t timestamp)
>
> static uint64_t cpu_get_timestamp(const Cpu *cpu)
> {
> + if (timestamp_based_on_real_time) {
> + return gettime_ns();
> + }
> return cpu->insn_count;
> }
>
> @@ -866,6 +889,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
> return -1;
> }
> + } else if (g_strcmp0(tokens[0], "timestamp-based-on-real-time") == 0) {
> + if (!qemu_plugin_bool_parse(tokens[0], tokens[1],
> + ×tamp_based_on_real_time)) {
> + fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
> + return -1;
> + }
> } else {
> fprintf(stderr, "option parsing failed: %s\n", opt);
> return -1;
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
next prev parent reply other threads:[~2025-08-05 10:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 20:45 [PATCH v4 0/7] contrib/plugins: uftrace Pierrick Bouvier
2025-07-24 20:45 ` [PATCH v4 1/7] contrib/plugins/uftrace: new uftrace plugin Pierrick Bouvier
2025-08-05 10:04 ` Alex Bennée
2025-08-06 0:41 ` Pierrick Bouvier
2025-07-24 20:45 ` [PATCH v4 2/7] contrib/plugins/uftrace: add trace-sample option Pierrick Bouvier
2025-07-24 20:45 ` [PATCH v4 3/7] contrib/plugins/uftrace: add trace-privilege-level option Pierrick Bouvier
2025-07-24 20:45 ` [PATCH v4 4/7] contrib/plugins/uftrace: add timestamp-based-on-real-time option Pierrick Bouvier
2025-08-05 10:23 ` Alex Bennée [this message]
2025-08-06 0:44 ` Pierrick Bouvier
2025-07-24 20:45 ` [PATCH v4 5/7] contrib/plugins/uftrace_symbols.py Pierrick Bouvier
2025-08-05 10:28 ` Alex Bennée
2025-07-24 20:45 ` [PATCH v4 6/7] contrib/plugins/uftrace: add documentation Pierrick Bouvier
2025-07-24 20:45 ` [PATCH v4 7/7] contrib/plugins/uftrace: add support for x64 Pierrick Bouvier
2025-08-04 16:19 ` [PATCH v4 0/7] contrib/plugins: uftrace Pierrick Bouvier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v7n23w4n.fsf@draig.linaro.org \
--to=alex.bennee@linaro.org \
--cc=erdnaxe@crans.org \
--cc=gustavo.romero@linaro.org \
--cc=ma.mandourr@gmail.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=rowanbhart@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).