From nobody Mon Apr 6 21:32:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E4D4ECAAD2 for ; Thu, 1 Sep 2022 19:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234306AbiIAT5u (ORCPT ); Thu, 1 Sep 2022 15:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234215AbiIAT5p (ORCPT ); Thu, 1 Sep 2022 15:57:45 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4B4883D6; Thu, 1 Sep 2022 12:57:44 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id c24so47263pgg.11; Thu, 01 Sep 2022 12:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=db/ALraqmP8bgCYrW21ZT7akOd/xlQBQhbt9mvTG2TE=; b=oXuXqM+8utkNlBWMslw5SNT9QFBA/xgxjoPqcI+S1z7LiiLr4oLlGZ3tC9rAF6H0cE zdQVlcrpOPTJNj4JL2q+jBVUiTF9jFCD7+xJ7iAtL8Ecgg3T7/1NuWy5J/3Ai9+p9RO5 RAmN7uOph0EuwOIjNT6xJ9eicU/S75CCS8qgmXrLmuj0Cs8SqS+5sReAqfUBdi++Fe6y sTIH9ZbgzuJmu9ANjRT0oZIf8W9p8x+HaAA4s7YJQsssiZ49UHNJ9YnGY+9yKyFyteUu 7G2K9iwD3LNkMHIF0irPfXrnevNLAkhASpG+atBFSt8IC/KyUF1ooCXMvwcY+isolLJ8 PDcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=db/ALraqmP8bgCYrW21ZT7akOd/xlQBQhbt9mvTG2TE=; b=d5/AQKwnAnvbeUXD2zCoKHXioRwsNrubOKKkKAVvkZcgFL/W3R4fXJQEyr4D+kBLJ3 TBpBs9A1iYnPwE8gLdphgXRaEz33txDnUGXESsU8kP9Z+jc19dhcp6Ad3YAy1D7Hwim8 eRmBEe3CEQkCitX09wSCiuIpkwSgDkJACVk+pQojSzSdClflmUWxgCQ0N5nwRWipy1gA 7QifTsFcTqYA+zptn8Qs1seHuVvWD9kOG1zs3srXMnQwDaifcc9aqMPaG/bPTFyNNDnu R/d5z5mc0vqgTlDrDpKK9jb6YOTY+jX32uIpG/6xxSWga/CqP1SWLOI5OImR2rjvCVgi HxXQ== X-Gm-Message-State: ACgBeo2ASF0V05S+EDQkdw9+qhb7cftle+QYSnpYgv4esjIbvbBAUHZo X/icEGiErezhPpbiXP0xPBPKq7HnnMw= X-Google-Smtp-Source: AA6agR7+YpSkZLfcLSxsA22CCZq3GDrCvWlYYfu5fxneWKerYpaAGY96RCVvOfdOIaWpxDj6t76zMw== X-Received: by 2002:a05:6a00:1691:b0:53b:3f2c:3257 with SMTP id k17-20020a056a00169100b0053b3f2c3257mr127360pfc.21.1662062263789; Thu, 01 Sep 2022 12:57:43 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:87ff:65c0:eb6a:d2b3]) by smtp.gmail.com with ESMTPSA id z10-20020a17090a1fca00b001fb23c28e9asm3728500pjz.2.2022.09.01.12.57.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:57:43 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, Adrian Hunter Subject: [PATCH 1/5] perf tools: Print LOST read format in the verbose mode Date: Thu, 1 Sep 2022 12:57:35 -0700 Message-Id: <20220901195739.668604-2-namhyung@kernel.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220901195739.668604-1-namhyung@kernel.org> References: <20220901195739.668604-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" So that we can see it with: $ perf record -vv pwd ... perf_event_attr: size 128 { sample_period, sample_freq } 4000 sample_type IP|TID|TIME|PERIOD read_format ID|LOST disabled 1 inherit 1 exclude_kernel 1 freq 1 enable_on_exec 1 precise_ip 3 sample_id_all 1 exclude_guest 1 Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/util/perf_event_attr_fprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/pe= rf_event_attr_fprintf.c index 4b0db27b7199..7e5e7b30510d 100644 --- a/tools/perf/util/perf_event_attr_fprintf.c +++ b/tools/perf/util/perf_event_attr_fprintf.c @@ -64,7 +64,7 @@ static void __p_read_format(char *buf, size_t size, u64 v= alue) #define bit_name(n) { PERF_FORMAT_##n, #n } struct bit_names bits[] =3D { bit_name(TOTAL_TIME_ENABLED), bit_name(TOTAL_TIME_RUNNING), - bit_name(ID), bit_name(GROUP), + bit_name(ID), bit_name(GROUP), bit_name(LOST), { .name =3D NULL, } }; #undef bit_name --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 21:32:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28E1DECAAD2 for ; Thu, 1 Sep 2022 19:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234520AbiIAT5y (ORCPT ); Thu, 1 Sep 2022 15:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234343AbiIAT5q (ORCPT ); Thu, 1 Sep 2022 15:57:46 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9431C88DC9; Thu, 1 Sep 2022 12:57:45 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id h13-20020a17090a648d00b001fdb9003787so68161pjj.4; Thu, 01 Sep 2022 12:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=kvFx5eRHToWhr+zoZdy15KN5PCyIzU9FkGCgn6Qywlw=; b=k3aIm4k94+8LtVnSMLD+qCpPzO6aQ1eYS1zwxmyhHQmHUMuxUmnh4r/iOqKLmKAHvz 7q8f+RGvlJHZmYGbvUsPIgMgVXIlY6YNX8R1jkwtQUb4hAz48cSU5UT9FlwDTg+Gjw43 ETulasvfCCaGvyyEpxlHxmNlCJ5nYQBzR1z9NnR/tmZxE7N3uc+2QONhmED1zDGh8CIC +xBJo94e4UMi7Nz9n/ydZ6E4Far018dQTVN9ELmil3jyjQImSzEEJZfABO3oRDhXWbER 67z8iJP2ilmYk6HBH3IjpiPzPU/gYcgAshpZ03KXPuJxd0UAqaFVcIKj5JbnmvgQD2Mf GMHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=kvFx5eRHToWhr+zoZdy15KN5PCyIzU9FkGCgn6Qywlw=; b=kKa88Gt6A4KnU4LIHelrXFMA59ZK5VMTOTXFs+YYTGkvknjAJhuB1Iflvg7ikTGnds PVvJsWS7/jSkGup/mWxRSkVQTLfh7cMtsSR4amTi0HcOYp3Jty+xSe9/XDVkN2Y/xt8i 4kf/3PHYVy47lzP6mmiDnKOvfbJrIQV/lkZhv1zKcWKB6proMKagznukHgYXBltDn6Mm SU1EAsEvbvk2Wu0hUzvvJJ14jKTMt/2LX47o2wbDb5ZVOHUXUpxj/kCTIqAKJLQEBrfR qboxwDY7vj+Dp/CjZVBEUmurLgRDtBTizAm5zSbVAa0/1wdAoNZctsLijY/eOgcX8vx+ Yr3Q== X-Gm-Message-State: ACgBeo3R7Yym1dqpw0lgvw2CoCTiFoqKSkwsTipqNVzrtpya7ucNlm4g JJaTV78P+kRN+cs3WzE331g= X-Google-Smtp-Source: AA6agR7MouHglHLgzaQYQk0XFNtZ7l2HPuZQl9bOpjF/myE7hYshc5f1XiYOSX+oFlvs3EVhWa+sRw== X-Received: by 2002:a17:90b:4a82:b0:1f5:5eaa:68a with SMTP id lp2-20020a17090b4a8200b001f55eaa068amr795635pjb.13.1662062265048; Thu, 01 Sep 2022 12:57:45 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:87ff:65c0:eb6a:d2b3]) by smtp.gmail.com with ESMTPSA id z10-20020a17090a1fca00b001fb23c28e9asm3728500pjz.2.2022.09.01.12.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:57:44 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, Adrian Hunter Subject: [PATCH 2/5] perf record: Set PERF_FORMAT_LOST by default Date: Thu, 1 Sep 2022 12:57:36 -0700 Message-Id: <20220901195739.668604-3-namhyung@kernel.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220901195739.668604-1-namhyung@kernel.org> References: <20220901195739.668604-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As we want to see the number of lost samples in the perf report, set the LOST format when it configs evsel. On old kernels, it'd fallback to disable it. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/util/evsel.c | 10 +++++++++- tools/perf/util/evsel.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index e1bc76ece117..5776bfa70f11 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1161,6 +1161,7 @@ void evsel__config(struct evsel *evsel, struct record= _opts *opts, attr->sample_id_all =3D perf_missing_features.sample_id_all ? 0 : 1; attr->inherit =3D !opts->no_inherit; attr->write_backward =3D opts->overwrite ? 1 : 0; + attr->read_format =3D PERF_FORMAT_LOST; =20 evsel__set_sample_bit(evsel, IP); evsel__set_sample_bit(evsel, TID); @@ -1856,6 +1857,8 @@ static int __evsel__prepare_open(struct evsel *evsel,= struct perf_cpu_map *cpus, =20 static void evsel__disable_missing_features(struct evsel *evsel) { + if (perf_missing_features.read_lost) + evsel->core.attr.read_format &=3D ~PERF_FORMAT_LOST; if (perf_missing_features.weight_struct) { evsel__set_sample_bit(evsel, WEIGHT); evsel__reset_sample_bit(evsel, WEIGHT_STRUCT); @@ -1907,7 +1910,12 @@ bool evsel__detect_missing_features(struct evsel *ev= sel) * Must probe features in the order they were added to the * perf_event_attr interface. */ - if (!perf_missing_features.weight_struct && + if (!perf_missing_features.read_lost && + (evsel->core.attr.read_format & PERF_FORMAT_LOST)) { + perf_missing_features.read_lost =3D true; + pr_debug2("switching off PERF_FORMAT_LOST support\n"); + return true; + } else if (!perf_missing_features.weight_struct && (evsel->core.attr.sample_type & PERF_SAMPLE_WEIGHT_STRUCT)) { perf_missing_features.weight_struct =3D true; pr_debug2("switching off weight struct support\n"); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index d927713b513e..989865e16aad 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -188,6 +188,7 @@ struct perf_missing_features { bool data_page_size; bool code_page_size; bool weight_struct; + bool read_lost; }; =20 extern struct perf_missing_features perf_missing_features; --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 21:32:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9950ECAAD2 for ; Thu, 1 Sep 2022 19:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234791AbiIAT57 (ORCPT ); Thu, 1 Sep 2022 15:57:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234747AbiIAT5s (ORCPT ); Thu, 1 Sep 2022 15:57:48 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5C49883D6; Thu, 1 Sep 2022 12:57:47 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id q63so55748pga.9; Thu, 01 Sep 2022 12:57:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=4VCsaeRAK1M38gR1W7ltGYYJiX1OmeYS/OXpgWUx2pk=; b=K91OI8cqSfGZ87/LqWuyFzhy5QO//6LNKqYC2/V9AgdqP7rpVEo6RBt9RaUSBwOsnw XXis8BSH34EeRPNIt/ND3dqiRlcWG5cSw2iUDWKO8isDLVF5MWKtCnvq0ZlsiN9V2kO2 o0O3fA3Kk5ZiwiAL5jr+NXMNK2Pau+qFMv07E+M3/Slc/wCBtCSqVOQliHzjws1plDd5 B8DA7NDFsY2vYWMurhgExRNd79fNJUduPLMxKGCTygRpwQh2glU5kdQDTqmZT53VBax2 Omu4ez105e9KI6QHRczmB+KO3XnHk6CAEoMlRSbUixh3rhpMgiwz7j6Y4B/vywEh0EPV QcLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=4VCsaeRAK1M38gR1W7ltGYYJiX1OmeYS/OXpgWUx2pk=; b=7Ng7oQBBWMAWiMPm6sVw1oygynEseW5Jisx2rVGmUwLSp0Gb61Y2a12qagSmrbfo9h kJ/ZWA7yTI1iYjZ3GVRBJ9r6maXhIUGRSIM9yZxSbwG7ziPfjTnwgaisVb/it43noU3F 86Q1JolHcxvuqtZdJ3UopWDmam0x5j4rfKRK/EPkERAl5yqKEvSIuPIFb/FejC32SL8k ytuJ97h4C8Wr9Daie1HzKJRIKrWQWgeooiw7fUtwIJz3hhBGmrAgzpK4lnTgeNKZbiW5 VqbJVnGMtrGiRGvy4iqoi5L7P1wcqXtytSfht4alzIwnAAFyV39QanRZqDv9z84VOq0d 1jKg== X-Gm-Message-State: ACgBeo1nEh0dp+URgJIpEnqfqWQE1Ucqc6xAjmY+T36tBE1ueCSv9Nz6 hS8oKFEvaR807r9Y0pxBdpK/CCSp5CY= X-Google-Smtp-Source: AA6agR5w9JVc1SBmqasK71ColFwb7McTWisATESthVANEYSTuuH84iAEjoGb5SmIL6ONqJigQedh4A== X-Received: by 2002:a05:6a00:1889:b0:538:2efa:ff7a with SMTP id x9-20020a056a00188900b005382efaff7amr21769066pfh.2.1662062267274; Thu, 01 Sep 2022 12:57:47 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:87ff:65c0:eb6a:d2b3]) by smtp.gmail.com with ESMTPSA id z10-20020a17090a1fca00b001fb23c28e9asm3728500pjz.2.2022.09.01.12.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:57:46 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, Adrian Hunter Subject: [PATCH 3/5] perf record: Read and inject LOST_SAMPLES events Date: Thu, 1 Sep 2022 12:57:37 -0700 Message-Id: <20220901195739.668604-4-namhyung@kernel.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220901195739.668604-1-namhyung@kernel.org> References: <20220901195739.668604-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When there are lost samples, it can read the number of PERF_FORMAT_LOST and convert it to PERF_RECORD_LOST_SAMPLES and write to the data file at the en= d. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/builtin-record.c | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index bce8c941d558..9df77b81a3bb 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -10,6 +10,7 @@ =20 #include "util/build-id.h" #include +#include #include "util/parse-events.h" #include "util/config.h" =20 @@ -1852,6 +1853,68 @@ record__switch_output(struct record *rec, bool at_ex= it) return fd; } =20 +static void __record__read_lost_samples(struct record *rec, struct evsel *= evsel, + struct perf_record_lost_samples *lost, + int cpu_idx, int thread_idx) +{ + struct perf_counts_values count; + struct perf_sample_id *sid; + struct perf_sample sample =3D {}; + int id_hdr_size; + + if (perf_evsel__read(&evsel->core, cpu_idx, thread_idx, &count) < 0) { + pr_err("read LOST count failed\n"); + return; + } + + if (count.lost =3D=3D 0) + return; + + lost->lost =3D count.lost; + if (evsel->core.ids) { + sid =3D xyarray__entry(evsel->core.sample_id, cpu_idx, thread_idx); + sample.id =3D sid->id; + } + + id_hdr_size =3D perf_event__synthesize_id_sample((void *)(lost + 1), + evsel->core.attr.sample_type, &sample); + lost->header.size =3D sizeof(*lost) + id_hdr_size; + record__write(rec, NULL, lost, lost->header.size); +} + +static void record__read_lost_samples(struct record *rec) +{ + struct perf_session *session =3D rec->session; + struct perf_record_lost_samples *lost; + struct evsel *evsel; + + lost =3D zalloc(PERF_SAMPLE_MAX_SIZE); + if (lost =3D=3D NULL) { + pr_debug("Memory allocation failed\n"); + return; + } + + lost->header.type =3D PERF_RECORD_LOST_SAMPLES; + + evlist__for_each_entry(session->evlist, evsel) { + struct xyarray *xy =3D evsel->core.sample_id; + + if (xyarray__max_x(evsel->core.fd) !=3D xyarray__max_x(xy) || + xyarray__max_y(evsel->core.fd) !=3D xyarray__max_y(xy)) { + pr_debug("Unmatched FD vs. sample ID: skip reading LOST count\n"); + continue; + } + + for (int x =3D 0; x < xyarray__max_x(xy); x++) { + for (int y =3D 0; y < xyarray__max_y(xy); y++) { + __record__read_lost_samples(rec, evsel, lost, x, y); + } + } + } + free(lost); + +} + static volatile int workload_exec_errno; =20 /* @@ -2710,6 +2773,7 @@ static int __cmd_record(struct record *rec, int argc,= const char **argv) if (rec->off_cpu) rec->bytes_written +=3D off_cpu_write(rec->session); =20 + record__read_lost_samples(rec); record__synthesize(rec, true); /* this will be recalculated during process_buildids() */ rec->samples =3D 0; --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 21:32:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 799CCECAAD3 for ; Thu, 1 Sep 2022 19:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233562AbiIAT6N (ORCPT ); Thu, 1 Sep 2022 15:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234751AbiIAT5u (ORCPT ); Thu, 1 Sep 2022 15:57:50 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0399288DFF; Thu, 1 Sep 2022 12:57:49 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id c66so8205761pfc.10; Thu, 01 Sep 2022 12:57:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=grEQReBW7HRZNQTYFK9rMRzxQVvmokwjNE/r8n6HAfU=; b=Ud8/YTkL7PDo59bRTaU97c94I/6HGENC8a9AWtjblbpbWu0DoEftQOIca7SuiQWA9C mbka+nTAR5GC6iW8kLsdCekajvLVVX127TnDSU9og9oWsDtyoIS/vxBCYVxvwFppxzNJ F3037Sn+fGZh5U9PffwQObzBTaSW8eOcsErpeQ7OlWqaeKS7Yvy8sybG3+bm+p+wQdjn ERakW+Ej50V7fRD6e4NgffiDrf22hozJiNc1puNGi44E6UwGg2Xydq1g7Q9nOfLlorQf byjxeBfVeek2YTreiUu8vRzxScFHyZaJ4/TfzF0jTkxPXgpMpW4NXiBmEq4mZaneUh/G g+Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=grEQReBW7HRZNQTYFK9rMRzxQVvmokwjNE/r8n6HAfU=; b=1SMhU79qX5E5bzzKZkGYZVbQfGivWPL/tL73jEDcqqcQGDIn1zCYveMXNYcXEuYQ7B TaLp50AVOXGU32C1w2Ug+GyKN59U9kv4g36zRuT/PfI8Ui+DYQswYWsjJM7Mtwi2TCuf gmZoNz54z8hnMSkYni1/5lOVge0/qtCD2bA6JJ1FvP4gl+5HsStUFWoU/apc942lAC6F 0U75VJJ0kgVLJEWC/hUB0u1u6Dcm4FcF+B9KbfP76Bz29EVLhSM1EI7qciwhFSWebYw0 4tOLLTq2GhH2mQNgQIwl0BJqdZYkhgVB1dS+oz9GruD/I1yvCXzYlJsUhLZognZwpVQW 6Wcg== X-Gm-Message-State: ACgBeo2Wx6JKACfwBa/Th288ONZX7u8gzy7LoO/qGGSxKPBWHQ19ZRqC QxHYzqAYpmy+lEkTX6pplC6doStX3pw= X-Google-Smtp-Source: AA6agR7K5WmOQl5JkJOjndV7oUwLpzHMbdCoTaayEntap+MuRSBe6VezIdFDsY0KxFIKx8zTjvDifw== X-Received: by 2002:a65:5ac4:0:b0:41b:af7f:125 with SMTP id d4-20020a655ac4000000b0041baf7f0125mr27543201pgt.224.1662062268472; Thu, 01 Sep 2022 12:57:48 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:87ff:65c0:eb6a:d2b3]) by smtp.gmail.com with ESMTPSA id z10-20020a17090a1fca00b001fb23c28e9asm3728500pjz.2.2022.09.01.12.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:57:48 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, Adrian Hunter Subject: [PATCH 4/5] perf hist: Add nr_lost_samples to hist_stats Date: Thu, 1 Sep 2022 12:57:38 -0700 Message-Id: <20220901195739.668604-5-namhyung@kernel.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220901195739.668604-1-namhyung@kernel.org> References: <20220901195739.668604-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is a preparation to display accurate lost sample counts for each evsel. Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/util/events_stats.h | 1 + tools/perf/util/hist.c | 5 +++++ tools/perf/util/hist.h | 1 + 3 files changed, 7 insertions(+) diff --git a/tools/perf/util/events_stats.h b/tools/perf/util/events_stats.h index 040ab9d0a803..8fecc9fbaecc 100644 --- a/tools/perf/util/events_stats.h +++ b/tools/perf/util/events_stats.h @@ -47,6 +47,7 @@ struct hists_stats { u64 total_non_filtered_period; u32 nr_samples; u32 nr_non_filtered_samples; + u32 nr_lost_samples; }; =20 void events_stats__inc(struct events_stats *stats, u32 type); diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 698add038cec..8cab049f7119 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -2335,6 +2335,11 @@ void hists__inc_nr_samples(struct hists *hists, bool= filtered) hists->stats.nr_non_filtered_samples++; } =20 +void hists__inc_nr_lost_samples(struct hists *hists, u32 lost) +{ + hists->stats.nr_lost_samples +=3D lost; +} + static struct hist_entry *hists__add_dummy_entry(struct hists *hists, struct hist_entry *pair) { diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 508428b2c1b2..c7a7a3fa0b87 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -201,6 +201,7 @@ void hists__reset_stats(struct hists *hists); void hists__inc_stats(struct hists *hists, struct hist_entry *h); void hists__inc_nr_events(struct hists *hists); void hists__inc_nr_samples(struct hists *hists, bool filtered); +void hists__inc_nr_lost_samples(struct hists *hists, u32 lost); =20 size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, int max_cols, float min_pcnt, FILE *fp, --=20 2.37.2.789.g6183377224-goog From nobody Mon Apr 6 21:32:34 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12A0FECAAD3 for ; Thu, 1 Sep 2022 19:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234808AbiIAT6S (ORCPT ); Thu, 1 Sep 2022 15:58:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234764AbiIAT5u (ORCPT ); Thu, 1 Sep 2022 15:57:50 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 480DF883E0; Thu, 1 Sep 2022 12:57:50 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id 199so18401445pfz.2; Thu, 01 Sep 2022 12:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date; bh=mjTaqq48hpPwmruEl0UppHlsTe3PLU+y+cRtBmXzLgw=; b=Q9BvpIsTAUlR4vleBxHM111zWZUao2bHBk/dFfA3I/Ln85EfXnWlRcr+F5GqSDKq/g glTwGNGj7Nd6bAJ6TciVMUOI81JcoXFCLTDeyTtj+gQtRfxq5Bh/NgZAIFjj+4Kax/Gh Q3j5qwyQeyGZpU8yk8Upkt6rFh7h0dlhWVontPylqeSJULa25ETQTqi2OhSsfMbr8Xf4 Gweze+IYprZ7QeOjoIOuZOnxOwR8Jk10q0OCfP7KY6Wv9Ga8QTPYp05FZiIHfs16M5pP CDy/8LnUrj01tlPuF1OG+S0t6PUli9cgMBWLPAUpj3/r4bjaOZe/r5Zu+SYDeCDj9Ad9 nC/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date; bh=mjTaqq48hpPwmruEl0UppHlsTe3PLU+y+cRtBmXzLgw=; b=kgt3txRiNCtugMH5C6S3SAb/IlTivGWvxpynmcNcThX5CtjKswuLzpOPnUqyP4mE0c 518hM4Ou69UXhq5TYW7NJJvdJcor0Z3sHC8a8A4Eb4s+f7UiCx9oW8CTvD61++gaZyzm Z83uNdaDgmUkRIEwAl17GW6Eo8I0NgmyafiOODmdPsHXUjKJyofWvR3SBkmUhnbmnbGr k/KuHgzVCdy6rr1qZ6y2SStGkDYRIEdBMDijVFnQspUjz/QMFXPrqO4vs3Siy54wFmga MvS73K6hbwzRPv3K16sMjpzu7NYlCvy6zVG3+5eW8xJAl5c5l89F8GD7cKJoreBGxz7s A0CA== X-Gm-Message-State: ACgBeo2dZqAzHEl8Kt/vHGiHftdW1Jg0vRbcEJ2sz42pn0YPKd66GwO5 Nd5lD0nZ/3PU4sba3W3SqvvaIozkjYU= X-Google-Smtp-Source: AA6agR6mJ6IczlYW6XTzx+PD5S0EUh5sHFK+wb6qMA21+Fd+hGZLupu/Vz1jOm/JWxFvtHpqiMbpew== X-Received: by 2002:a05:6a02:206:b0:427:93bb:9f99 with SMTP id bh6-20020a056a02020600b0042793bb9f99mr27174917pgb.542.1662062269660; Thu, 01 Sep 2022 12:57:49 -0700 (PDT) Received: from youngsil.svl.corp.google.com ([2620:15c:2d4:203:87ff:65c0:eb6a:d2b3]) by smtp.gmail.com with ESMTPSA id z10-20020a17090a1fca00b001fb23c28e9asm3728500pjz.2.2022.09.01.12.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:57:49 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , linux-perf-users@vger.kernel.org, Adrian Hunter Subject: [PATCH 5/5] perf report: Show per-event LOST SAMPLES stat Date: Thu, 1 Sep 2022 12:57:39 -0700 Message-Id: <20220901195739.668604-6-namhyung@kernel.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220901195739.668604-1-namhyung@kernel.org> References: <20220901195739.668604-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Display lost samples with --stat (if not zero): $ perf report --stat Aggregated stats: TOTAL events: 64 COMM events: 2 ( 3.1%) EXIT events: 1 ( 1.6%) SAMPLE events: 26 (40.6%) MMAP2 events: 4 ( 6.2%) LOST_SAMPLES events: 1 ( 1.6%) ATTR events: 2 ( 3.1%) FINISHED_ROUND events: 1 ( 1.6%) ID_INDEX events: 1 ( 1.6%) THREAD_MAP events: 1 ( 1.6%) CPU_MAP events: 1 ( 1.6%) EVENT_UPDATE events: 2 ( 3.1%) TIME_CONV events: 1 ( 1.6%) FEATURE events: 20 (31.2%) FINISHED_INIT events: 1 ( 1.6%) cycles:uH stats: SAMPLE events: 14 LOST_SAMPLES events: 1 instructions:uH stats: SAMPLE events: 12 Signed-off-by: Namhyung Kim Reviewed-by: Adrian Hunter --- tools/perf/builtin-report.c | 17 +++++++++++++++++ tools/perf/util/hist.c | 10 +++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 91ed41cc7d88..8361890176c2 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -752,6 +752,22 @@ static int count_sample_event(struct perf_tool *tool _= _maybe_unused, return 0; } =20 +static int count_lost_samples_event(struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine __maybe_unused) +{ + struct report *rep =3D container_of(tool, struct report, tool); + struct evsel *evsel; + + evsel =3D evlist__id2evsel(rep->session->evlist, sample->id); + if (evsel) { + hists__inc_nr_lost_samples(evsel__hists(evsel), + event->lost_samples.lost); + } + return 0; +} + static int process_attr(struct perf_tool *tool __maybe_unused, union perf_event *event, struct evlist **pevlist); @@ -761,6 +777,7 @@ static void stats_setup(struct report *rep) memset(&rep->tool, 0, sizeof(rep->tool)); rep->tool.attr =3D process_attr; rep->tool.sample =3D count_sample_event; + rep->tool.lost_samples =3D count_lost_samples_event; rep->tool.no_warn =3D true; } =20 diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 8cab049f7119..06f5dbf213ad 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -2683,12 +2683,16 @@ size_t evlist__fprintf_nr_events(struct evlist *evl= ist, FILE *fp, evlist__for_each_entry(evlist, pos) { struct hists *hists =3D evsel__hists(pos); =20 - if (skip_empty && !hists->stats.nr_samples) + if (skip_empty && !hists->stats.nr_samples && !hists->stats.nr_lost_samp= les) continue; =20 ret +=3D fprintf(fp, "%s stats:\n", evsel__name(pos)); - ret +=3D fprintf(fp, "%16s events: %10d\n", - "SAMPLE", hists->stats.nr_samples); + if (hists->stats.nr_samples) + ret +=3D fprintf(fp, "%16s events: %10d\n", + "SAMPLE", hists->stats.nr_samples); + if (hists->stats.nr_lost_samples) + ret +=3D fprintf(fp, "%16s events: %10d\n", + "LOST_SAMPLES", hists->stats.nr_lost_samples); } =20 return ret; --=20 2.37.2.789.g6183377224-goog