From patchwork Thu Aug 29 16:08:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 96726 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0E9C386103A for ; Thu, 29 Aug 2024 16:09:09 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 8EA2F385E027 for ; Thu, 29 Aug 2024 16:09:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EA2F385E027 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EA2F385E027 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724947745; cv=none; b=W/Qr5i+MVe6flAG1IZecEs9ulkKNX1a8qTE17zTJ8tsTFjpBbLDCZYAYtqh1vLKX617J1fh6yNH6Sm3rZwU8wX81+N2wrQYZNnQAksCb0qmoO8XPAaE6zQckko0K7KIF+OREy05PGt50AjB0rjSWAtbFnTCystXEMde+Xy/pDC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724947745; c=relaxed/simple; bh=kYZAIo1r0aE2oRUhC0WEGaxEM0RxbUmtKXumhPmK7d8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TVNaxTbat9dnHaMYhwI8/I2lupPUQjIo0nGCgDuq3k9LqM+1FYKlvshI75RSDNExc+PukeUXfoB3Tor5RRrgdOVHAm6vAVwsbOrv2AySvRot8mDqIMAt4tA1FYwXGtTgArvnxjnvZySrElHig+YOoyhLKbcI9nF+tYo5sf9zRRM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724947741; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+T021QioQVSKhKllBCxLzYM4jyny40GrEfdKsl9LPFs=; b=H8RwqGxGu0RqqodM63N/Wt9t66w3tHKhVzZSB+GDCWcGaXEAh34wLmMswWdZlrmvKaPJIr 66HXzuj5By9kYRdMFxaSkNnlZHwuPFTp4XwSh6oq6pFHAFMeZX6YmpzP2mKvfgEpvdC2uO AarHotqkL96vOxyTGNUK8ryadjgqbWo= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-pp5Q04VtNneUwjTR_s0f5A-1; Thu, 29 Aug 2024 12:09:00 -0400 X-MC-Unique: pp5Q04VtNneUwjTR_s0f5A-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6c16da4e175so11475166d6.1 for ; Thu, 29 Aug 2024 09:09:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724947739; x=1725552539; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+T021QioQVSKhKllBCxLzYM4jyny40GrEfdKsl9LPFs=; b=r0g6ut4FlwgszsBL3Sp9rgJRtpwdAiRwMJzgcBYwOPYKYCKneX+8Cjnzs6aJOe+Fwm JlFObqxkd25HGXCzP329Idn1O9hpnuzqNi9F4teobyv1B7jnlrrd1EpueRTL5HtfAvwt bSypmGkVZPGDm9bsYVlF0sC6yHRRYTMo5wow7DcPf+T+IeOSnSOBXr14jhc/J2Ar7bIA UIzZupoxHpEKY2EpTo/dILwHFFPlGmt7a4dRwvfe0fLTXEhQhV1r4LcC1vDFR6VmQoSX PfudA7rjMmWm9Ql9kvw15iL//D65Zg65O7CiJA/Hb9Q284niseAq2DbggGBtPZj1U42h Z5jQ== X-Gm-Message-State: AOJu0YwXVS9P0CFbmBizglVuKmWU3FRwSIyju92Vp2F1t+I55G4lYYup 7lD5T9Zpp76xmRiBd57ez146f28twNt5Hvmxd0ZBSfUXjR3JzPo7qK+f+QoHWGVkilJbsX/Ukkm cC73/G6VbRc0kRJbEC8XnENYahIMx+zSlrWAOhGL8axZp97ObFd0PMhCctdVIba9R1g== X-Received: by 2002:a05:6214:3d11:b0:6bf:6934:d0bb with SMTP id 6a1803df08f44-6c33e6148e8mr43395866d6.21.1724947739067; Thu, 29 Aug 2024 09:08:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGl7+ezp70NZxM2SWINFdmHlSO4yGalwEtzQswS5GKLnL1I4KZJxzFSA/PpJgVOl+pKV1hFlQ== X-Received: by 2002:a05:6214:3d11:b0:6bf:6934:d0bb with SMTP id 6a1803df08f44-6c33e6148e8mr43395196d6.21.1724947738440; Thu, 29 Aug 2024 09:08:58 -0700 (PDT) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c340bff5bfsm6433576d6.36.2024.08.29.09.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 09:08:58 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 8C60E503C602; Thu, 29 Aug 2024 18:08:56 +0200 (CEST) From: Dodji Seketeli To: dodji@redhat.com Cc: libabigail@sourceware.org Subject: [PATCH 22/27] dwarf-reader,tools-utils: Add statistics about built/suppressed functions Organization: Me, myself and I References: <20240829154711.1883174-1-dodji@redhat.com> X-Operating-System: AlmaLinux 9.4 X-URL: http://www.seketeli.net/~dodji Date: Thu, 29 Aug 2024 18:08:56 +0200 In-Reply-To: <20240829154711.1883174-1-dodji@redhat.com> (dodji@redhat.com's message of "Thu, 29 Aug 2024 17:46:29 +0200") Message-ID: <87mskvjopz.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org Hello, When running abidw --verbose, it's useful to have information about the number of functions and variable that were actually constructed or suppressed. This is useful to see how effective a suppression specification that instructs libabigail to drop certains functions/variables actually is. This patch emits statistics about the amount of functions/variables represented in the IR and dropped on the floor. * src/abg-dwarf-reader.cc (reader::stats): Define new struct. (reader::stats_): Define a new data member of type stats. (build_or_get_fn_decl_if_not_suppressed) (build_or_get_var_decl_if_not_suppressed): Increments the stats. (reader::read_debug_info_into_corpus): Emit the stats about number of suppressed/kept functions and variables at the end of the corpus building. * src/abg-tools-utils.cc (load_vmlinux_corpus): Emit the status about the number of functions/variables in the corpus. Signed-off-by: Dodji Seketeli --- src/abg-dwarf-reader.cc | 85 ++++++++++++++++++++++++++++++++--------- src/abg-tools-utils.cc | 8 ++++ 2 files changed, 76 insertions(+), 17 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index d067a5a3..640e909a 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -1947,6 +1947,25 @@ public: } }; // end die_dependant_container_set + /// Statistics to help for debugging purposes. + struct stats + { + unsigned number_of_suppressed_functions = 0; + unsigned number_of_suppressed_variables = 0; + unsigned number_of_allowed_functions = 0; + unsigned number_of_allowed_variables = 0; + + /// Clear the statistic data members. + void + clear() + { + number_of_suppressed_functions = 0; + number_of_suppressed_variables = 0; + number_of_allowed_functions = 0; + number_of_allowed_variables = 0; + } + }; + unsigned short dwarf_version_; Dwarf_Die* cur_tu_die_; mutable dwarf_expr_eval_context dwarf_expr_eval_context_; @@ -2027,6 +2046,7 @@ public: mutable size_t canonical_propagated_count_; mutable size_t cancelled_propagation_count_; mutable optional leverage_dwarf_factorization_; + mutable stats stats_; protected: @@ -2073,6 +2093,13 @@ protected: initialize(load_all_types, linux_kernel_mode); } + /// Clear the statistics for reading the current corpus. + void + clear_stats() + { + stats_.clear(); + } + public: /// Initializer of reader. @@ -2134,9 +2161,10 @@ public: canonical_propagated_count_ = 0; cancelled_propagation_count_ = 0; load_in_linux_kernel_mode(linux_kernel_mode); + clear_stats(); } - /// Initializer of reader. + /// Initializer of reader. /// /// Resets the reader so that it can be re-used to read another binary. /// @@ -2380,7 +2408,15 @@ public: << "Number of canonical types propagated: " << canonical_propagated_count_ << "\n" << "Number of cancelled propagated canonical types:" - << cancelled_propagation_count_ << "\n"; + << cancelled_propagation_count_ << "\n" + << "Number of suppressed functions: " + << stats_.number_of_suppressed_functions << "\n" + << "Number of allowed functions: " + << stats_.number_of_allowed_functions << "\n" + << "Total number of fns in the corpus: " + << corpus()->get_functions().size() << "\n" + << "Total number of variables in the corpus: " + << corpus()->get_variables().size() << "\n"; } } @@ -15704,7 +15740,10 @@ build_or_get_var_decl_if_not_suppressed(reader& rdr, if (variable_is_suppressed(rdr, scope, die, is_declaration_only, is_required_decl_spec)) - return var; + { + ++rdr.stats_.number_of_suppressed_variables; + return var; + } if (class_decl* class_type = is_class_type(scope)) { @@ -15713,6 +15752,10 @@ build_or_get_var_decl_if_not_suppressed(reader& rdr, if ((var = class_type->find_data_member(var_name))) return var; } + + // The variable was not suppressed. + ++rdr.stats_.number_of_suppressed_variables; + var = build_var_decl(rdr, die, where_offset, result); return var; } @@ -15944,16 +15987,19 @@ function_is_suppressed(const reader& rdr, /// @return a pointer to the newly created var_decl. If the var_decl /// could not be built, this function returns NULL. static function_decl_sptr -build_or_get_fn_decl_if_not_suppressed(reader& rdr, - scope_decl *scope, - Dwarf_Die *fn_die, - size_t where_offset, - bool is_declaration_only, - function_decl_sptr result) +build_or_get_fn_decl_if_not_suppressed(reader& rdr, + scope_decl *scope, + Dwarf_Die *fn_die, + size_t where_offset, + bool is_declaration_only, + function_decl_sptr result) { function_decl_sptr fn; if (function_is_suppressed(rdr, scope, fn_die, is_declaration_only)) - return fn; + { + ++rdr.stats_.number_of_suppressed_functions; + return fn; + } string name = die_name(fn_die); string linkage_name = die_linkage_name(fn_die); @@ -15976,13 +16022,18 @@ build_or_get_fn_decl_if_not_suppressed(reader& rdr, // symbols. So re-using C++ destructors like that can lead to us // missing some destructors. if (!result && (!(is_dtor && is_virtual))) - if ((fn = is_function_decl(rdr.lookup_artifact_from_die(fn_die)))) - { - fn = maybe_finish_function_decl_reading(rdr, fn_die, where_offset, fn); - rdr.associate_die_to_decl(fn_die, fn, /*do_associate_by_repr=*/true); - rdr.associate_die_to_type(fn_die, fn->get_type(), where_offset); - return fn; - } + { + if ((fn = is_function_decl(rdr.lookup_artifact_from_die(fn_die)))) + { + fn = maybe_finish_function_decl_reading(rdr, fn_die, where_offset, fn); + rdr.associate_die_to_decl(fn_die, fn, /*do_associate_by_repr=*/true); + rdr.associate_die_to_type(fn_die, fn->get_type(), where_offset); + return fn; + } + } + + // The function was not suppressed. + ++rdr.stats_.number_of_allowed_functions; // If a member function with the same linkage name as the one // carried by the DIE already exists, then return it. diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index 9660fcfc..1bc2e233 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -3066,6 +3066,14 @@ load_vmlinux_corpus(elf_based_reader_sptr rdr, << "' (" << cur_module_index << "/" << total_nb_modules << ")" << "'\n"; } + + if (verbose) + { + std::cerr << "Total number of functions: " + << group->get_functions().size() << "\n"; + std::cerr << "Total number of variables: " + << group->get_variables().size() << "\n"; + } } /// Walk a given directory and build an instance of @ref corpus_group