From patchwork Thu Oct 26 03:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 158369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp397248vqb; Wed, 25 Oct 2023 20:25:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgm/t3Lzd3ETZbUKsM2vO7CspXSP0K70s7IGqhvcA6ufraD9q5I9/rX1BhIp+efG+iEw71 X-Received: by 2002:a05:620a:4015:b0:773:ac84:3f57 with SMTP id h21-20020a05620a401500b00773ac843f57mr1754054qko.5.1698290747953; Wed, 25 Oct 2023 20:25:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698290747; cv=pass; d=google.com; s=arc-20160816; b=uvVzK14Kx6O/7o+qUl+ELmk3nBcriDBlJn5eu8f+I5PNpCKzToUr3CvAOHy0U469dJ OjZpw9hhp6tYSWGVFEguSBmOQy4R24VrTPzUh0379b/fSBukYTTHvLg+Q7gmgzY6DG+2 ht2CoGB0RklLi5y7L8//c18nyGNK6J108f+5sBJNPf/ZMedIbAe3P2JqGOM1UCpdn5nJ g0RYRWhJFqoanmLr+VxRUrn+WjacNbyil1xLnBTQcI61Lh8nRPMaczgjO4txyVA2g4wV GUjRPLKSjPSprD+yYU/ww9khD4y28kTd/2D7wKYRaA1DRcqbhaYXE5pF8doubxVHT59O UVNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=N3RSa8TG4gU9+g+bfUGI/CJL0ut6Ug8ICebgEl8Utvs=; fh=EiheM5Cq1ZOeyP3gnDxZ9vsUU+J4wX0/mH2Vj1zkMJU=; b=b2RmEZ94g7AFR8V1MJIBDIyhhX8HhzA/3Fip5rgvob05rRZZS0c3YowiK0K2XENSXP jASRbcy6JpVE7DoEhoMAnZODP+ab0+H7+puoLQgGMCTWBtS4VspLJ7hA8R1GPBIfiulV D6qHhWL18iBKQ15m181UEi8xgf+ahRbyUfUcZOUvyzWCfLJiFi1fEJZ72tXqKlUfdJEF r7uQFD89PIArTnzudCePCMNHvJ91xJQxwmCcF0BBPhKM/zJVDj/hXCzhB4JI54GX/IQH Kq4akymPnk4oPl9mcZojwOGwpdTkG4XABZ1lbdXJ+I2bKh0Y2PYwkjEzMyLYW8c3QwMB AeMQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cirZgXLw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f9-20020a05620a280900b0076da5b38bd6si9187156qkp.700.2023.10.25.20.25.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 20:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cirZgXLw; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 925623857701 for ; Thu, 26 Oct 2023 03:25:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id C9BEF3858C5F; Thu, 26 Oct 2023 03:25:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9BEF3858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C9BEF3858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698290724; cv=none; b=HkqTVRdc2aoV57R3dgkNu0zhmyJhaZGH0cUAiBSrqfufCJ5v1cg+9L60yn4AcLB6ur0K3dbrEmCYX8g1RWnyXfNzwJhlfqQZif+V+vnD3NVYhpqAi5JGPiG+DLtgzjWnP2JTxwCM4U01Tk5ODELzKNZl4jTZQS5dvGSdCkRDfvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698290724; c=relaxed/simple; bh=TUBQyhoAJDXDux8fUFcsKn3xtf8MQ0x1FplalOq/YQE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=VcQYFDiQJn4t4YWxlmP2NOdc8Xj+nh/ooPVTqd6f8KitYvpoMAR2zt6SwsBVndABybmqsdudOLUQrG/sGrqIOCqePOYmyVGuBXOb2cjo2Aku1hN6nBxPV5DWpvWsbM5WjrTOFxK9/iQXm5GpTiY9qGTdm4r7/fk8uo5A2IeMQog= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6bd73395bceso312287b3a.0; Wed, 25 Oct 2023 20:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698290721; x=1698895521; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=N3RSa8TG4gU9+g+bfUGI/CJL0ut6Ug8ICebgEl8Utvs=; b=cirZgXLwPYyPIlQhciUs7s2E0Oeuydi0orNOLQPfeWztrKvm1rjeUM6kXwPtJ/xQWH Icqbo3OsEcY98KVsSVvr/b992PWDqrePEk9EVSQUfwF+0PR4LRVWf5/sE5oO1BjY8k5G T561AVyog5CfjTL3wylrQ3IXagTOU75dYlsjPKUmIB032YULrqBVT0H+jOurc2u8oyl6 WftG1LffM792u/aEwvqmEl7btn3yAZXz+ZY+s20dmkM4eaCchY+/fSxJg3hC2keHVfl4 OdbzelGaNgLv82oJrSHJLSqbnm4fsgrCYgItKZexS1cTljgxkzfawScE6gJh/7t8/jcV xcZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698290721; x=1698895521; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=N3RSa8TG4gU9+g+bfUGI/CJL0ut6Ug8ICebgEl8Utvs=; b=b0LdZDgnl6klmpMvVK/248oz6EGeo172VHyFh6Iha0dyvxYq4k8cMXjkGN2YAnHqVa VvNE39If5Ztf7ciy8wyM1+0WqgRiZOxWfdtTmaztatiG0SGbUCzE7xAqgMKtdYVsYS2R e7paHzo1M8Nnka2J1qBgEx6Ip/gx4pSt29jFgNNKPi7U1wYlu3um5tWcAnK4I03d7U27 rqM4ywInYyavGXJ/Zjq5rHxUPko+i4F4BUxHMHRTl+il7sEQ/9qisVWPG3yckWKXxdix FL5KJ/cvCKF3Vqfrl2HGmFrfG6+AloGNObaYE+EZrK4cfLgu/0sfGuaNGNSrDLiXaJrX nZXQ== X-Gm-Message-State: AOJu0Yz6bhwIkyyKR9ha20i+psgxU8JxJa3ZIaxzczsoFwgLYV+2rM69 OJRTa6PmRDIkbzaAMFDAs/h4DIVEWLB4/g== X-Received: by 2002:a05:6a00:23d1:b0:68e:351b:15b9 with SMTP id g17-20020a056a0023d100b0068e351b15b9mr1893659pfc.4.1698290721471; Wed, 25 Oct 2023 20:25:21 -0700 (PDT) Received: from localhost ([14.22.11.162]) by smtp.gmail.com with ESMTPSA id g27-20020aa79f1b000000b006933b69f7afsm10087789pfr.42.2023.10.25.20.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 20:25:21 -0700 (PDT) From: Xionghu Luo X-Google-Original-From: Xionghu Luo To: gcc-patches@gcc.gnu.org Cc: luoxhu@gcc.gnu.org, Xionghu Luo Subject: [PATCH] libgcov: Fix gcov overlap bugs of divide to 0 Date: Thu, 26 Oct 2023 11:25:14 +0800 Message-Id: <20231026032515.2061065-1-xionghuluo@tencent.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780786919324161286 X-GMAIL-MSGID: 1780786919324161286 Fix the long lasting issue of `gcov-tool overlap xxx yyy`, divide to 0 caused the output shows a lot of nans, another problem is the counts in file are never acculated leads to incorrect results. Signed-off-by: Xionghu Luo libgcc/ChangeLog: * libgcov-util.c (compute_one_gcov): Avoid divide to 0. (accumulate_sum_counts): New. (calculate_overlap): Call accumulate_sum_countes. --- libgcc/libgcov-util.c | 58 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/libgcc/libgcov-util.c b/libgcc/libgcov-util.c index d547c103cab..26a02e66567 100644 --- a/libgcc/libgcov-util.c +++ b/libgcc/libgcov-util.c @@ -1072,6 +1072,8 @@ compute_one_gcov (const struct gcov_info *gcov_info1, for (f_ix = 0; f_ix < gcov_info1->n_functions; f_ix++) { + double func_1 = 0.0; + double func_2 = 0.0; double func_cum_1 = 0.0; double func_cum_2 = 0.0; double func_val = 0.0; @@ -1096,11 +1098,15 @@ compute_one_gcov (const struct gcov_info *gcov_info1, ci_ptr2->values[c_num], sum_1, sum_2); - func_cum_1 += ci_ptr1->values[c_num] / sum_1; - func_cum_2 += ci_ptr2->values[c_num] / sum_2; + if (sum_1) + func_1 = ci_ptr1->values[c_num] / sum_1; + func_cum_1 += func_1; + if (sum_2) + func_2 = ci_ptr2->values[c_num] / sum_2; + func_cum_2 += func_2; nonzero = 1; - if (ci_ptr1->values[c_num] / sum_1 >= overlap_hot_threshold - || ci_ptr2->values[c_num] / sum_2 >= overlap_hot_threshold) + if (func_1 >= overlap_hot_threshold + || func_2 >= overlap_hot_threshold) hot = 1; } } @@ -1322,6 +1328,47 @@ matched_gcov_info (const struct gcov_info *info1, const struct gcov_info *info2) return 1; } +static int +accumuate_sum_counts (const struct gcov_info *gcov_info1, + const struct gcov_info *gcov_info2) +{ + gcc_assert (gcov_info1 || gcov_info2); + unsigned f_ix; + + if (gcov_info1) + { + gcov_type cum_1 = 0; + for (f_ix = 0; f_ix < gcov_info1->n_functions; f_ix++) + { + const struct gcov_fn_info *gfi_ptr = gcov_info1->functions[f_ix]; + if (!gfi_ptr || gfi_ptr->key != gcov_info1) + continue; + const struct gcov_ctr_info *ci_ptr = gfi_ptr->ctrs; + unsigned c_num; + for (c_num = 0; c_num < ci_ptr->num; c_num++) + cum_1 += ci_ptr->values[c_num]; + } + overlap_sum_1 = cum_1; + } + + if (gcov_info2) + { + gcov_type cum_2 = 0; + for (f_ix = 0; f_ix < gcov_info2->n_functions; f_ix++) + { + const struct gcov_fn_info *gfi_ptr = gcov_info2->functions[f_ix]; + if (!gfi_ptr || gfi_ptr->key != gcov_info2) + continue; + const struct gcov_ctr_info *ci_ptr = gfi_ptr->ctrs; + unsigned c_num; + for (c_num = 0; c_num < ci_ptr->num; c_num++) + cum_2 += ci_ptr->values[c_num]; + } + overlap_sum_2 = cum_2; + } + return 0; +} + /* Compute the overlap score of two profiles with the head of GCOV_LIST1 and GCOV_LIST1. Return a number ranging from [0.0, 1.0], with 0.0 meaning no match and 1.0 meaning a perfect match. */ @@ -1410,6 +1457,9 @@ calculate_overlap (struct gcov_info *gcov_list1, if (overlap_func_level) printf("\n processing %36s:\n", filename); + overlap_sum_1 = overlap_sum_2 = 0.0; + accumuate_sum_counts (all_infos[i].obj1, all_infos[i].obj2); + val = compute_one_gcov (all_infos[i].obj1, all_infos[i].obj2, overlap_sum_1, overlap_sum_2, &cum_1, &cum_2);