From nobody Fri Nov 7 12:58:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538755474841776.3063642271721; Fri, 5 Oct 2018 09:04:34 -0700 (PDT) Received: from localhost ([::1]:35795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8Saf-0005GK-Mg for importer@patchew.org; Fri, 05 Oct 2018 12:04:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8SSH-0005zq-84 for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:55:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g8SSF-0004fi-4o for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:55:53 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40775) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g8SSE-0004fR-Ts for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:55:51 -0400 Received: by mail-wr1-x444.google.com with SMTP id d2-v6so9634363wro.7 for ; Fri, 05 Oct 2018 08:55:50 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o126-v6sm2452350wmo.3.2018.10.05.08.55.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Oct 2018 08:55:46 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 42A0E3E085D; Fri, 5 Oct 2018 16:49:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gy6oZ4WvtbPxi9/JzF6atrZp6ZtERY/PrwaMhunFanw=; b=E3JUZd/d4esfQI1xdFgrZmKr25ced+XlKLJeNAY8apCsHj+HjhsQt3/1gzPptwDmmM 99bpv8v53+I6WOnROw3RC818bJfeW6bSrunNi3iZsGO59DZiHotcc3RCHRPVdJGJtEk/ P3fr9t0OJ+ZkpbG3/V0im8EyPBBvpVw6r+aW8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gy6oZ4WvtbPxi9/JzF6atrZp6ZtERY/PrwaMhunFanw=; b=Z3gvrsZnr0Z0WeuNA5Jq/KBfjqnFbrPW++zkR2dmpHKJFpg4uHuBPgrgjjHjbBDvC2 rO+NOntSQBE+umc1ZjjOhdR9CHdo4rxOJMj7bcl4FYFGPLHnw8qtbWeDcPChMG1iP92e EXepsnrinbbzmoy/eT8X85KV3JEaZket0T2XIyFgBGtuC2lKo3TAAxH3okjC7rUI0+62 K3rWgVv8qTKj4JLRHaGJ9JSAeSlLgH1pP4JeRDviy2XcUHCFOkaROaO+ssZNAnJm+MFm WYxm/GNJsVGdphl26tvzaIJ8UBp+ZFUOSg9LbIQyDyBEMOjkDIP3VB6KWDnNoJcN46WP ZZWQ== X-Gm-Message-State: ABuFfoih2wyCosap+92BGcOlDV2jRmZmkHqf1vAv1qcnQGabAPf7UpZu qXv8XB7YIPEAzqhkera2+pumxg== X-Google-Smtp-Source: ACcGV626VB2EAMvg5gBj8XJiCoF5JP4DFdW7zT7KZE6bhmIFiWeTVD5nU1EBn5iXGw9N0lIoPYpbGg== X-Received: by 2002:adf:afdd:: with SMTP id y29-v6mr9322390wrd.176.1538754949744; Fri, 05 Oct 2018 08:55:49 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 5 Oct 2018 16:49:08 +0100 Message-Id: <20181005154910.3099-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181005154910.3099-1-alex.bennee@linaro.org> References: <20181005154910.3099-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [RFC PATCH 19/21] plugins: add an example hotblocks plugin X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Hajnoczi , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , vilanova@ac.upc.edu, Pavel.Dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 This plugin attempts to track hotblocks by total execution count and average time to return to block. It is intended to be lower impact than saving a long log file and post-processing it. Signed-off-by: Alex Benn=C3=A9e --- trace/plugins/hotblocks/hotblocks.c | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 trace/plugins/hotblocks/hotblocks.c diff --git a/trace/plugins/hotblocks/hotblocks.c b/trace/plugins/hotblocks/= hotblocks.c new file mode 100644 index 0000000000..e9166ad1a5 --- /dev/null +++ b/trace/plugins/hotblocks/hotblocks.c @@ -0,0 +1,69 @@ +/* + * Execution Hotblocks Plugin + * + * Copyright (c) 2018 + * Written by Alex Benn=C3=A9e + * + * This code is licensed under the GNU GPL v2. + */ + +#include +#include +#include +#include +#include "plugins.h" + +/* Plugins need to take care of their own locking */ +GMutex lock; +GHashTable *hotblocks; + +typedef struct { + uintptr_t pc; + unsigned int hits; + struct timespec last; + unsigned long total_time; +} ExecCount; + +bool plugin_init(const char *args) +{ + hotblocks =3D g_hash_table_new(NULL, g_direct_equal); + return true; +} + +char *plugin_status(void) +{ + GString *report =3D g_string_new("We have "); + char *r; + g_mutex_lock(&lock); + g_string_append_printf(report, "%ud entries in the hash table\n", + g_hash_table_size(hotblocks)); + g_mutex_unlock(&lock); + r =3D report->str; + g_string_free(report, FALSE); + return r; +} + +bool exec_tb(void *tb, uintptr_t pc) +{ + ExecCount *cnt; + struct timespec current; + clock_gettime(CLOCK_MONOTONIC, ¤t); + + g_mutex_lock(&lock); + cnt =3D (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) p= c); + if (cnt) { + cnt->hits++; + cnt->total_time +=3D current.tv_nsec - cnt->last.tv_nsec; + cnt->last =3D current; + } else { + cnt =3D g_new0(ExecCount, 1); + cnt->pc =3D pc; + cnt->last =3D current; + cnt->hits =3D 1; + g_hash_table_insert(hotblocks, (gpointer) pc, (gpointer) cnt); + } + g_mutex_unlock(&lock); + + /* As we are collecting up samples no reason to continue tracing */ + return false; +} --=20 2.17.1