From patchwork Fri Oct 5 15:49:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 148214 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp629328lji; Fri, 5 Oct 2018 09:05:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV61oEQFnXGahGmB1HvtvjjRGuh29hYpEa9nEUUjVV3LeIE/weuEmtyeWgubAihGSIkLp7eAu X-Received: by 2002:ae9:df02:: with SMTP id t2-v6mr8995313qkf.161.1538755526402; Fri, 05 Oct 2018 09:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538755526; cv=none; d=google.com; s=arc-20160816; b=vSb9ObDSWaFP1OHefur0VktDcKZf5B57H/wrg3XHtDRCujR+R/pCFoV38C/qVH05u3 jqD3EjuJNxoHqVCBUsVunP9N99d9URNEe2fNdcba5qhNolgUvu6Tp3hbosykSiq51bQw fWrpCrcFkiwfvkSifOccmvk+dxNIm5fpwRE/pFtjz6h/7PgrHlCLJgLauTT6QQP5H1pe zdAGF2Z2qJ/42jS0G0jW19FE4FYhC0BVH6jABhJjYybo8447Z9TKKExV6WbaEK1SUO9V HrZjQNtHMbpoZBdc2EkoL+PfIQmxh4MviC99Kr51IncKYNCIh0+IpQ3yadMHK58paWBx a2pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=Gy6oZ4WvtbPxi9/JzF6atrZp6ZtERY/PrwaMhunFanw=; b=SpM835CJC/aB42ibmC0ilGJZ3ZhUEHCx26Za6BdgnntgL2QvBRILzYlMIhVwO/eG60 A8U2kcLB83qgQ34XFlta7LsV/vjOv9w3x+pZCEaab7ykGWhkY+CSoEx+LWODnfiHGBKh ZBmapg/hQ4sWaKuT0p7exJBW9i+RX5vvEnYDLHUXx+pSKeDJIZN6PCf3+L5ejjCwX68b 3nrLZvNnp9AGsJ+gEHu1bS3Jn+kWXtjZOfA+lXMA3EK4iIrMvu+UC0U8mUrIDHAhl6KS 56992CbLBBuk7COhdamIYoLWhZ7JY4VMg7FpJFi/01KSoxY1NrtCqvj2cAbJUkKZszLF I2fQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="E3JUZd/d"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u5-v6si5425002qvi.102.2018.10.05.09.05.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 05 Oct 2018 09:05:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="E3JUZd/d"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8SbV-0006Si-ST for patch@linaro.org; Fri, 05 Oct 2018 12:05:25 -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) 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-Received: by 2002:adf:afdd:: with SMTP id y29-v6mr9322390wrd.176.1538754949744; Fri, 05 Oct 2018 08:55:49 -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) From: =?utf-8?q?Alex_Benn=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 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_?= =?utf-8?q?Benn=C3=A9e?= , vilanova@ac.upc.edu, Pavel.Dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée --- trace/plugins/hotblocks/hotblocks.c | 69 +++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 trace/plugins/hotblocks/hotblocks.c -- 2.17.1 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ée + * + * 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 = g_hash_table_new(NULL, g_direct_equal); + return true; +} + +char *plugin_status(void) +{ + GString *report = 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 = 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 = (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) pc); + if (cnt) { + cnt->hits++; + cnt->total_time += current.tv_nsec - cnt->last.tv_nsec; + cnt->last = current; + } else { + cnt = g_new0(ExecCount, 1); + cnt->pc = pc; + cnt->last = current; + cnt->hits = 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; +}