From patchwork Fri Oct 5 15:49:09 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: 148218 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp637746lji; Fri, 5 Oct 2018 09:12:26 -0700 (PDT) X-Google-Smtp-Source: ACcGV600fz63i9LMloz6A14AOTYKGDgCE5/YBH6+Y65ZxbLXxxUfngc3b+WZV1pnOCDS8SqIRg9s X-Received: by 2002:a0c:d585:: with SMTP id g5-v6mr10060776qvi.50.1538755946668; Fri, 05 Oct 2018 09:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538755946; cv=none; d=google.com; s=arc-20160816; b=FqqO5dukPcCymxClwOHyoY8ybhgjlWmybYA3NiK469tMe/Y3uwu6O3JQgcpMAGMYXX Lmna61yX7JPZ4lYxMzDEXthCaHkjZ4Ze0mrn95mu2HKrpBbjwiPUNflB8J5wGWlaBDkL ue5p207RMK20tac62M53E8tfpNXilOsR8/CqG1YfGIf3/U2kD73jn958CdBz3iZ4+uW0 SdIRwYjtHOHusZdxTIjju8g9aD6U4Ast7U0A+cvP9blK70HFLeAumKmV66Cx6kXcTSu7 3+Ipli2dkch3F+eA354c0uqyoJldIIVu6NSmktqx7qPRRrbTbdrULxFSj3jj8c44Q4Hv wOZg== 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=niBrZfxJaKwm3OTekaz9i84MMz3w9A8+1X4ToD1jQC0=; b=uIrmFHJSKAvggG8R9b3QMY50hoEwUC45PeZJTjkWJrSrB0UqAvIrTxRnPpgk+Hv/vX H4btbMPxrILCJM8/UBxAad2Lw+JuynrUv6qlC4ir0x0U8ywKCQQjEZVeY5jV1r3mnFFm al0R38DX0Z2nruphm2rOqdEWqNe4xZ/FM+JNmCTkLIn9jedQfo4JmkfL2u5bioPH85Im snv+WHWAuGr7ZP7aEPM+0zvLld2dEB5gVK/efiXorzITpX3yCQZN7w7iZrTfkyyO+vcF 62GEPZB1qWc7c3wOGYynWhXlLjBLM8sewo+EiFTr9SN6QeVafKIOT/UkVQxgGfpevaA4 T6cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=g1cDv6yw; 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 k190-v6si5733919qkd.243.2018.10.05.09.12.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 05 Oct 2018 09:12: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=g1cDv6yw; 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]:35922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8SiI-0004Sm-3T for patch@linaro.org; Fri, 05 Oct 2018 12:12:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g8SSH-0005zs-86 for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:55:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g8SSE-0004fY-BW for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:55:53 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:34059) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g8SSE-0004er-4c for qemu-devel@nongnu.org; Fri, 05 Oct 2018 11:55:50 -0400 Received: by mail-wr1-x435.google.com with SMTP id z4-v6so14074890wrb.1 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=niBrZfxJaKwm3OTekaz9i84MMz3w9A8+1X4ToD1jQC0=; b=g1cDv6ywi8TZkmeFL4aIMJMCHyLOJgi0/zdkIID0Xoes/8HN1QiFaStiCVVuXVffUc NpafP7JFp5p7Ra6gYQmwj67JgZFdlfcqy49CEgRh72bhuBrHbgBMNAlR7hFgGzcyBph+ hB/SzcFX7b6pGune6TnqGMGYXQr2SIsl3mlNY= 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=niBrZfxJaKwm3OTekaz9i84MMz3w9A8+1X4ToD1jQC0=; b=hqyPlZmt7f+h9aWZ06icgWSsYkkw4TDr+vA3f8JAGi1qRn3VkAyjhYYt9oSG2CZiGu wunnJ2S2L9XAubdL/2qbmGSSi9K02Ry7SsI4pBxb9w4/9Q8FZK4rMqn1lHnsR0mrV+CW wFAUXpmkus/564ShTKCHxmdfiZOH8UFgXMEgFPhRRho06y7r8alztBiJS2ljiNaMNU7W uxLGQyZzQQAvG1CrqY57J+mIiwPyQHXTLG8CnwDT8L7zj4xVbbXzc4B8QOWudqsupj+c BB0wcTq2oZElNvbLN4st6AHnYATAOvgMngEAvzFlyJg+0BHpk60Y/z9vVpchJvPdOA2m EVNg== X-Gm-Message-State: ABuFfoiIFXB5YTfrcnKJ143BPUlY9/cOFCfQM2Nj/8WfXziK8NvXvUqE fV+Ft06KXR/EVk87Cimhl1jItwd0870= X-Received: by 2002:adf:ba06:: with SMTP id o6-v6mr8241430wrg.249.1538754948937; Fri, 05 Oct 2018 08:55:48 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id i15-v6sm4943516wro.58.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 55E5D3E0893; 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:09 +0100 Message-Id: <20181005154910.3099-21-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::435 Subject: [Qemu-devel] [RFC PATCH 20/21] plugins: add hotness summary to hotblocks 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" Signed-off-by: Alex Bennée --- trace/plugins/hotblocks/hotblocks.c | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/trace/plugins/hotblocks/hotblocks.c b/trace/plugins/hotblocks/hotblocks.c index e9166ad1a5..d2333ad866 100644 --- a/trace/plugins/hotblocks/hotblocks.c +++ b/trace/plugins/hotblocks/hotblocks.c @@ -11,11 +11,13 @@ #include #include #include +#include #include "plugins.h" /* Plugins need to take care of their own locking */ GMutex lock; GHashTable *hotblocks; +guint64 limit = 20; typedef struct { uintptr_t pc; @@ -24,20 +26,49 @@ typedef struct { unsigned long total_time; } ExecCount; +static gint cmp_hits(gconstpointer a, gconstpointer b) +{ + ExecCount *ea = (ExecCount *) a; + ExecCount *eb = (ExecCount *) b; + return ea->hits > eb->hits ? -1 : 1; +} + bool plugin_init(const char *args) { + guint64 count = g_ascii_strtoull(args, NULL, 10); + if (count > 0) { + limit = count; + } + hotblocks = g_hash_table_new(NULL, g_direct_equal); return true; } char *plugin_status(void) { - GString *report = g_string_new("We have "); + GString *report = g_string_new("collected "); + GList *counts, *it; char *r; + int i; + g_mutex_lock(&lock); g_string_append_printf(report, "%ud entries in the hash table\n", g_hash_table_size(hotblocks)); + counts = g_hash_table_get_values(hotblocks); + it = g_list_sort(counts, cmp_hits); + + for (i = 0; i < limit && it->next; i++, it = it->next) { + ExecCount *rec = (ExecCount *) it->data; + g_string_append_printf(report, + " pc: %#016" PRIxPTR + " (%d hits)" + " %lu ns between returns\n", + rec->pc, rec->hits, + rec->total_time / rec->hits); + } + g_mutex_unlock(&lock); + g_list_free(it); r = report->str; g_string_free(report, FALSE); return r;