From patchwork Tue May 21 02:27:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Mezentsev X-Patchwork-Id: 90507 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 81302385840F for ; Tue, 21 May 2024 02:28:51 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id EA0183858C62 for ; Tue, 21 May 2024 02:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA0183858C62 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EA0183858C62 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1716258498; cv=pass; b=X3mDndVnfU1SNzEAZOMRzklkrELrStZIFG6+xPrKHcxi+9Kr4law4+zT/KHImDovJ5Oa1qDLp9rgR9wEAIOaMasHyLeJFBaCc76ISS4oteAvkF3QNCd6KW+qjRF0Jtn12tbhNEool2qgQPUbXKfAXU/62nVGB0+bTF8SihoJEII= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1716258498; c=relaxed/simple; bh=0tQ01uccEurnWKNAFvdH4LlEJlQonaQbCsVaAp6hq2E=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=tTqqEOwO21H1vWHQ3h54/ltGvF0y0LPcteKmdcoQrrc+rtmrMm0xe7ew+vFIk+UmKxdrmKUR0DPSaAf4z34royNlS4Huw/MnHmen2wYIUVBZF04k1vmpVZ25vyctpBPnvD0bUoMN1phyzsZ9/WwlVlTdxtokKlj0GiMr7wNrZdA= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44KNK424001096 for ; Tue, 21 May 2024 02:28:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=J3YI6Z1uLyQi3FSVK5nfERvSU7K7UOfma6BHx4VzhSk=; b=QJNLGH6WNFnNrEQfy7Tflzh+yciOL5NHcTPxl6vYtKw+c4w+/5E/mZqWJbr+UUYHI6iq UTayHM6kb9+cCfqqATRw1TT7j/EHB84ha31uVDBJV9WASQItmCIkf+9OfZSf35hU143b Og2Vjovu5n6srxL2CIm2wMzHzeHCaa5DaoTZksbYbeZ8POGWpQ6Y4pZFwxfeOQJhpUCU sqaW/l5QjRhk1/C+vuWKaBDGp2beNeZCEdyGl6GV7W32veyz1QmPLmspnjDvP7YZtjYx raXV8ukcicHBcnEUZDqvb7fNXzGg5HGiclYE+AN0glDUfhHFUTVXAift/+5p/Pac91Ja 3Q== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3y6m7b3ud6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 21 May 2024 02:28:11 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 44L1xJFU038449 for ; Tue, 21 May 2024 02:28:10 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3y6jsd2rfk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 21 May 2024 02:28:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JD/ONXmiDXU/BF8fyFg7eWp4/xF5sSLC5FidUm3SvasrlGPf19Pd6sj4Onr/S5MA/46m5aXgjxs/XPAatv6U8DEb94u9OwxXnWdvpKdu1SrgG32PzxAdItQ45Z2KfE5E1VwAzwEcknFRMmC0M8SqcB8BjH/SPqm4xlUBDeSKGMgIZXYoxX1L9V2pwiroZpHwWxUM9IBxfgLO1GtE0lb3McMMbb6y6W4fmXRyj5KmwhwKKCS8e/+5tVIkUYu17RSr2agD/GaIrtBmhO5dUAlq8GBHOFSGIC8AkPQitfBZuuYLQn6TQ7f/RTMnYQO7L2tjDDvFTLJgw263m1Zr+0nPTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J3YI6Z1uLyQi3FSVK5nfERvSU7K7UOfma6BHx4VzhSk=; b=CrQira78hSAwW1RfXgnYQTE4RPSqTjBQ2YSBdNVL4Xon34chblXuWw1rI94JYhET28MzyP5jkeCMhFXtpGgP2ESkkSVv5X8oOffcuDp5wAU3XGxjGd+xbOijNNJ8nzJ1UmY/C+HLVZsDeiCIaraLM8nvhn2KUNipB51YC9rTYyIwmDDEjtKA9yxHjrnx8cavZ6zOkhbPCnVTGdbKPEP7fAf2pliKurux+Y+Dz3O+M0wrtP+1mG+92Ep79bTAeyhZtj7PZanYdeVFiRwqpdgPZDRo2OrWfXhktddKPoW7irt2mawIFrkqt+kv4REpwXz/WoG23MWBLTQ1HVl8d8AU+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J3YI6Z1uLyQi3FSVK5nfERvSU7K7UOfma6BHx4VzhSk=; b=t9IP8ao+TLMo7mDoCNIToOZywHpT3rPmN8tUO3fNf714DLP5ieeOSpbOMJjXMFgTcWWpnLmhSRX0SRnYOOAb5Fblixq459+YStXUGULVQ5w9wvQOrZxiAZvLfD49a7uaDgK8zuwOL/r6VksGkmENXjYA0jZ1K3xPScSd2yEqI08= Received: from SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10) by DS7PR10MB5152.namprd10.prod.outlook.com (2603:10b6:5:3a9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Tue, 21 May 2024 02:28:08 +0000 Received: from SA2PR10MB4636.namprd10.prod.outlook.com ([fe80::1b3d:bd64:9100:c3fb]) by SA2PR10MB4636.namprd10.prod.outlook.com ([fe80::1b3d:bd64:9100:c3fb%7]) with mapi id 15.20.7587.035; Tue, 21 May 2024 02:28:08 +0000 From: vladimir.mezentsev@oracle.com To: binutils@sourceware.org Cc: Vladimir Mezentsev Subject: [PATCH 3/3] gprofng: use StringBuilder to create long messages Date: Mon, 20 May 2024 19:27:50 -0700 Message-Id: <20240521022750.3876393-1-vladimir.mezentsev@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: LO4P265CA0120.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c6::7) To SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PR10MB4636:EE_|DS7PR10MB5152:EE_ X-MS-Office365-Filtering-Correlation-Id: e1bd1e47-fa7d-4e0b-e53b-08dc793da6aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|376005|1800799015; X-Microsoft-Antispam-Message-Info: HEG252w/irYxI72Sj5x6tGvDZQmPEObaYy4I/aNSZvEfe8+pj2sBVPLi9qCzrXQ6sJd11aGbvJlXTL1LE3cY5O7SQnTOr4a4Um0ivpR7KI8fzW6zWd+oP6JIf0HDvCLfCqaA/VjhjMQjCOTdY2R+VsKMqm822V7gU5xJ4BFpV4sW6JFf6Req0NTzxkZHzk2NA/n01cdNZEIUcNl2arvnNvVgiJi/yM2YDJVp3RjKyYMTWUjo0b6flxx2OqSMo7tf4BK4Xobcz8S5j3ORFI6GY6uaVYK8pMAzJr4XJh1PcE28GQanktYRZZ+7LLDFtcqLmZHHr4jfySQ3pbHhPqB6pdNiC0xny5ougoG16zPxBUp4Qi3GT9VtW3MxpKh0vzqFy59Woo4BJTgZY9DJyqfVXpmQvj7x849ndG8JH1zjVNBIdQ705tYeRbM2q9yiUIutH+FB3HWYZKn4Zj645rta0gaF3e/hi412A+rynMwx67cy/BFSpZ004NnIwyAEMngTHZOIg8Ko2z+uWdMVWbUMbLwRZ9YBG1C73371wNBHAJtpkYRbwBIL4cm7wVsxD4ZVWGZyxpmic8sOZ07eLjs37EFh4786r5vHePJYWWox/dolMFlLpN8eNuS9XiN22DuZgptortNd1T9lc/8gM3g5HrEcg3GmYXMd2hlCzu686KIBfHoKtyO16CtMgmCRVMYXqlGE3KCDLoyb/dQTrUlu0zb24oiP/5dvDOtXAYuG80RqmuW7yGJDX9dX5HEZx72iGb+jBoJi8cOyyi9hLlMKunHSPirvf5xO8b+NjiNpBlR4UDYa1xrRELNMJU6YKqakssmRilBxPYKJVHjE/Xjd9Cb/ISrrzry7CZvibtjcRRFRvcex6RjRfpcTAIkR7u86PPQQ1dsV0H7e/egY9T+AdLMEzl4fpBhg04LYZDZLoYG2Tv1Sy8u5yR3bC0y7/rQTy4znOvBd3HL2VzUaJYJVCQHEXYyC5QrGc4hzJzbp7tjHGTrXJdWa/ZkELo9XzkQHEQUpexkQznbfpj5mN29z6YHyf6iuG4WWbjXAcVCosqdtcvsDTahtjviIP7lOhRXuPLhwyDYWLjtTtGYV4826P9fh4SUDRKTXTGgDtZvabZSdMjJ1ihtb5NEWJ+W30w1MW4EjVpygYhUdXmBIZxU5vynPfJkVAsCrTAEEUAtYkZXbzbuEjVy36RgfV4Q1C9IbnccNbaQHzMMoQxzWKMz4BzgZF5CyDCuqxhGhlvsBHXJNO1cjPHbkaJeJoFFLnlLYRAh63K+GQTPlJb3Y8KJy6Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA2PR10MB4636.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366007)(376005)(1800799015); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jUiBWzauZ4RRefE+9jlDeZ2VdZt7jD0h648DiFneCVMwhnZQW9CYaCRUP9U0oJoA3Nsa9c8Us2ytuEOnncTlwR6oQ/KTu8RIDzHZ2/kmX/qboUlLXPLvZrqzzsFdwnka7f3qSn7w5ToVokqGKdchGydYDAgbM7gCgjNjMiWMp+40ReGnd2GqJmFpc7Mfu0yHgb+Ko/EudCziZrxTSWkrK+CJ2p96/SIEkOiSjaGfeN/du9cZ39julg1x1HW0DAmMSERYkS5Z7DMW2tWFyw1hhVPTMiecav+8O3dPeqED6j4A7tMfOMhxaFFFytqzd8I/Dhd5dh01kfoMj6flegcOuJvZJGzB7Rgyqyp1Q7nZOtSushOgxpl/8quh/1x9SWqYm2gHF7tvmLNxfBmqbfHU/ojeNt5vmq2F2urE+Kco9F3k72f+bLaGHxVXoaEsUykDnQfDP/s+B2K8sQRvS1NvUhCdhxar2sHg192sbepuHmngVTEOMQ9F3rr+PxSvoZRpbY4SlLMhlyCV7YL3SHLuSQzVdFlrtyRqSQmkMTPbKUPA1TwhFq2FObHIR3hBmO/Tgsfi/TlYes0fCS5xlT4lJvlB2HtIZ3JC2bIg5W2jJ5lBzL2Ijsvj3avvj4fsz7SYiwjcHOpGDi+hFwisPkNPEYFjcPzfYqjKoLTNSJg6l66JacBFIUug00Cgv/Zdapopr6JyTIhtQq9KaWixM/RXLjiSmtmqJYzpUxoh57J8pCjIU2w+SBYbmATTAoFlC89tNoHvPSbTVIYpRn7NKWe7dBZ26ysCKt+mdi5ZcazbJzda03KImSuAN2pX6loLbaR3JCvvD0j/gzmq8kyury/NGtCfA9i+J4vUmKnBeH4Q2jd7bLwIpC7koFCzJFG2UTH2pNk2VwS6vM8ppHZTgqAbI4xjagt6PMuQ8LoOOcLAkqwccNtINROD6320xCr6idAdl1oM33bucE7tlok3kmsXAWKmuwSbjMQbhQhwrKaSPLs1JUqCIgdo7W0rFpVbH+dckWba7xvLbIzleohPaNNem3ynJ9mu+Nm4piuzNAaknhEGezOpQrlj2pN0UQfghVYfdUHOg+QalPTmLSqkCwDWznnh+k9JNsUIsXz0uURxdyaayJBBwDDVDioarLFsq+zEIrclUioA23WFoOvy0Z9bLZ6lh3AjhLhG3EcWZI6AF+nzb8rrfJs0snZEvqLnJwrOLj5qTwOdX32rkCUz/XIQUaB8kuHGaH7/jRSm+Plw2gdc8Ym14BtZKHBvSq1ckL/kpTWP7dbk3+GfCvs/uooIUi1brLSsJLnWfpvH7RXVv+W7MtUoDZcH2bWmZHnGG6CIYJJTuEKU4rbGtez3U5Y6F/yZf5AVZZaOG8tyP9syPLO44cJmeitl+tA3Fojaq31eZJHQnYXyR3s9yHDPEJgfoIKzTCCkZPF0Wm29DXKd1PayuiD194GMA2AcgLSMqm5ejA1d53y3OT1ltZkNzOHrPMSWRLWq1zHDE+PGEF5BJFBueViyq6NpVG1PDdAbZYuMXQLaTBiMl+LFj/1iz7AQWqi7AZtlxr8Ud+CsZC9U5vC43M8KguIorcuBFY4aE+rjvJI0fahRJu6hDmNDuQxwTKUE1ffSMFStNrUzj84lBoDzpDcy1Lt8cyyRlo67cC/w X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Or45gNN+jWqeUxA0lS6Cpr95su0ugTsBh+1VoQDvK8SsI5UYXYYajag6h7VNrlVuBeVqRUrhNQpNhfLyceGt18H0P5Fsrwv8rFzaiY8DUQsh7qLuLkyv2WMt8m4oOKm4zgprNEJ0s/A5cI7VYLaE3SRg9U7QMJDx73C9RBweqPeh4mgw/UCvLFWxihWSW/Q2WqXOBXu3c+3b9n6RvKffpf7G9ItAreQimLuIabkDEJ3loVYVBNHY5tRjWgm0xYHGGh9BTi6nBZI8lpPCLvs9QL5p+LgEyP/qf5AIazng82BHS4QQ+GPy4+pIrOzF2U7ojQlzbVhVJuPNThBt7znkElkpS39Rn029xYXXi4ahVMqWm1GELWt8YUmjuqf9Qpb/rAJ3TuU+JaWhlSwVkbos3FfT/6TTHaz0uiidwWa4BSi8gW5+/qVRnn6EOWZyX4XCDtoW1j5noP8G7FTliAtqCBfg11WQrio5qwD8mJQecP7oxdgkQdy12uI0QffwoJAhwHo06NwuGA+u7dmpKr7jbx74ju2i7cVCt3DF2OtnZVWOyZseGLlOfK4lpUpfL61718aMd7dLrXqYg9QsNP6r1pOAj6lksHLklHOvMYP1EQ8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1bd1e47-fa7d-4e0b-e53b-08dc793da6aa X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4636.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2024 02:28:07.9592 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wkL/0UxEKopr0yLwWT0Veavyi3JvY9fPDkKONk/CmunHBCcLrW6yboiwNP0kNqCkBpEUoxPL8C6qhpjym6yKdNisZB7pkl7NXrmV9iG3+ZA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR10MB5152 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-21_01,2024-05-17_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405210018 X-Proofpoint-ORIG-GUID: ybuw7M3eKU_EBT7RU-pWzC26cOgkKQGx X-Proofpoint-GUID: ybuw7M3eKU_EBT7RU-pWzC26cOgkKQGx X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org From: Vladimir Mezentsev ChangeLog 2024-05-20 Vladimir Mezentsev * src/collctrl.cc: Use StringBuilder to create messages. Remove unused variables and arrays. * src/collctrl.h: Remove unused variables. --- gprofng/src/collctrl.cc | 460 ++++++++++++++++------------------------ gprofng/src/collctrl.h | 2 - 2 files changed, 179 insertions(+), 283 deletions(-) diff --git a/gprofng/src/collctrl.cc b/gprofng/src/collctrl.cc index 28fdb0b577e..7c0219b13f0 100644 --- a/gprofng/src/collctrl.cc +++ b/gprofng/src/collctrl.cc @@ -42,7 +42,6 @@ #include "StringBuilder.h" #define SP_GROUP_HEADER "#analyzer experiment group" -#define DD_MAXPATHLEN (MAXPATHLEN * 4) /* large, to build up data descriptor */ /* If the system doesn't provide strsignal, we get it defined in libiberty but no declaration is supplied. */ @@ -50,11 +49,6 @@ extern const char *strsignal (int); #endif -// _SC_CPUID_MAX is not available on 2.6/2.7 -#ifndef _SC_CPUID_MAX -#define _SC_CPUID_MAX 517 -#endif - static const char *get_fstype (char *); static cpu_info_t cpu_info; @@ -70,7 +64,7 @@ read_str (char *from, char **to) { if (s[i] != '\n' && s[i] != ' ' && s[i] != '\t') { - *to = strndup(s, i + 1); + *to = strndup (s, i + 1); return; } } @@ -88,7 +82,7 @@ read_int (char *from) } cpu_info_t * -read_cpuinfo() +read_cpuinfo () { static int inited = 0; if (inited) @@ -141,7 +135,6 @@ read_cpuinfo() Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC) { char hostname[MAXPATHLEN]; - long ncpumax; interactive = _interactive; defHWC = _defHWC; kernelHWC = _kernelHWC; @@ -154,24 +147,12 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC) *p = 0; default_stem = strdup ("test"); - /* get CPU count and processor clock rate */ - ncpumax = sysconf (_SC_CPUID_MAX); - if (ncpumax == -1) - { - ncpus = sysconf (_SC_NPROCESSORS_CONF); - /* add 2048 to count, since on some systems CPUID does not start at zero */ - ncpumax = ncpus + 2048; - } - cpu_info_t *cpu_p = read_cpuinfo(); + cpu_info_t *cpu_p = read_cpuinfo (); ncpus = cpu_p->cpu_cnt; cpu_clk_freq = cpu_p->cpu_clk_freq; /* check resolution of system clock */ sys_resolution = sysconf (_SC_CLK_TCK); - if (sys_resolution == 0) - sys_period = 10000; - else - sys_period = MICROSEC / (int) sys_resolution; /* determine memory page size and number of pages */ npages = sysconf (_SC_PHYS_PAGES); @@ -238,7 +219,7 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC) setup_hwc (); hwcprof_default = 1; } - else // disable the default, and reset the counters + else // disable the default, and reset the counters hwcprof_enabled_cnt = 0; synctrace_enabled = 0; synctrace_thresh = -1; @@ -358,7 +339,6 @@ Coll_Ctrl::Coll_Ctrl (Coll_Ctrl * cc) opened = 0; nofswarn = cc->nofswarn; sys_resolution = cc->sys_resolution; - sys_period = cc->sys_period; // ensure that the default name is updated (void) preprocess_names (); @@ -457,6 +437,7 @@ Coll_Ctrl::delete_expt () // Check the experiment settings for consistency. Returns NULL if OK, // or an error message if there are invalid combinations of settings + char * Coll_Ctrl::check_consistency () { @@ -491,7 +472,7 @@ Coll_Ctrl::check_expt (char **warn) char *ret; *warn = NULL; ret = check_consistency (); - if (ret != NULL) /* something is wrong, return the error */ + if (ret != NULL) /* something is wrong, return the error */ return ret; /* check for heaptrace and java -- warn that it covers native allocations only */ if (heaptrace_enabled == 1 && java_mode == 1 && java_default == 0) @@ -510,7 +491,7 @@ Coll_Ctrl::check_expt (char **warn) store_dir, strerror (errno)); if (access (store_dir, W_OK) != 0) return dbe_sprintf (GTXT ("Store directory %s is not writeable: %s\n"), - store_dir, strerror (errno)); + store_dir, strerror (errno)); /* if an experiment-group, verify that it can be written */ ret = check_group (); @@ -522,218 +503,172 @@ Coll_Ctrl::check_expt (char **warn) char * Coll_Ctrl::show (int i) { - char UEbuf[4096]; - UEbuf[0] = 0; + StringBuilder sb; if (i == 0) { - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("Collection parameters:\n")); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT (" experiment enabled\n")); + sb.append (GTXT ("Collection parameters:\n")); + sb.append (GTXT (" experiment enabled\n")); } if (target_name != NULL) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\ttarget = %s\n"), target_name); + sb.appendf (GTXT ("\ttarget = %s\n"), target_name); if (uexpt_name != NULL) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tuser_expt_name = %s\n"), uexpt_name); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\texpt_name = %s\n"), - ((expt_name != NULL) ? expt_name : NTXT (""))); + sb.appendf (GTXT ("\tuser_expt_name = %s\n"), uexpt_name); + sb.appendf (GTXT ("\texpt_name = %s\n"), + ((expt_name != NULL) ? expt_name : "")); if (udir_name != NULL) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdir_name = %s\n"), udir_name); + sb.appendf (GTXT ("\tdir_name = %s\n"), udir_name); if (expt_group != NULL) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\texpt_group = %s\n"), expt_group); + sb.appendf (GTXT ("\texpt_group = %s\n"), expt_group); if (debug_mode == 1) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdebug_mode enabled\n")); + sb.append (GTXT ("\tdebug_mode enabled\n")); if (clkprof_enabled != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tclock profiling enabled, %.3f millisec.\n"), + sb.appendf (GTXT ("\tclock profiling enabled, %.3f millisec.\n"), (double) (clkprof_timer) / 1000.); if (synctrace_enabled != 0) { if (synctrace_thresh < 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tsynchronization tracing enabled, threshold: calibrate; ")); + sb.append (GTXT ("\tsynchronization tracing enabled, threshold: calibrate; ")); else if (synctrace_thresh == 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tsynchronization tracing enabled, threshold: all; ")); + sb.append (GTXT ("\tsynchronization tracing enabled, threshold: all; ")); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tsynchronization tracing enabled, threshold: %d micros.; "), synctrace_thresh); + sb.appendf (GTXT ("\tsynchronization tracing enabled, threshold: %d micros.; "), + synctrace_thresh); switch (synctrace_scope) { case SYNCSCOPE_NATIVE: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("Native-APIs\n")); + sb.append (GTXT ("Native-APIs\n")); break; case SYNCSCOPE_JAVA: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("Java-APIs\n")); + sb.append (GTXT ("Java-APIs\n")); break; case SYNCSCOPE_NATIVE | SYNCSCOPE_JAVA: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("Native- and Java-APIs\n")); + sb.append (GTXT ("Native- and Java-APIs\n")); break; default: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("ERR -- unexpected synctrace_scope %d\n"), synctrace_scope); + sb.appendf (GTXT ("ERR -- unexpected synctrace_scope %d\n"), + synctrace_scope); break; } } if (hwcprof_enabled_cnt != 0) { char ctrbuf[MAXPATHLEN]; - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\thardware counter profiling%s enabled:\n"), - (hwcprof_default == 1 ? GTXT (" (default)") : "")); + if (hwcprof_default == 1) + sb.append (GTXT ("\thardware counter profiling (default) enabled:\n")); + else + sb.append (GTXT ("\thardware counter profiling enabled:\n")); for (int ii = 0; ii < hwcprof_enabled_cnt; ii++) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t %u. %s\n"), ii + 1, - hwc_hwcentry_specd_string (ctrbuf, MAXPATHLEN, &hwctr[ii])); + sb.appendf ("\t %u. %s\n", ii + 1, + hwc_hwcentry_specd_string (ctrbuf, sizeof (ctrbuf), &hwctr[ii])); } if (heaptrace_enabled != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\theap tracing enabled, %s\n"), - (heaptrace_checkenabled == 0 ? GTXT ("no checking") : - (heaptrace_checkenabled == 1 ? GTXT ("over/underrun checking") : - GTXT ("over/underrun checking and pattern storing")))); + { + if (heaptrace_checkenabled == 0) + sb.append (GTXT ("\theap tracing enabled, no checking\n")); + else if (heaptrace_checkenabled == 1) + sb.append (GTXT ("\theap tracing enabled, over/underrun checking\n")); + else + sb.append (GTXT ("\theap tracing enabled, over/underrun checking and pattern storing\n")); + } if (iotrace_enabled != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tI/O tracing enabled\n")); + sb.append (GTXT ("\tI/O tracing enabled\n")); switch (count_enabled) { case 0: break; case 1: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tcount data enabled\n")); + sb.append (GTXT ("\tcount data enabled\n")); break; case -1: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tstatic count data will be generated (for a.out only)\n")); + sb.append (GTXT ("\tstatic count data will be generated (for a.out only)\n")); break; } switch (follow_mode) { case FOLLOW_ON: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdescendant processes will be followed\n")); + sb.append (GTXT ("\tdescendant processes will be followed\n")); break; case FOLLOW_ALL: if (follow_spec_usr && follow_spec_cmp) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\texperiments will be recorded for descendant processes that match pattern '%s'\n"), - follow_spec_usr); + sb.appendf (GTXT ("\texperiments will be recorded for descendant processes that match pattern '%s'\n"), + follow_spec_usr); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdescendant processes will all be followed\n")); + sb.append (GTXT ("\tdescendant processes will all be followed\n")); break; case FOLLOW_NONE: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdescendant processes will not be followed\n")); + sb.append (GTXT ("\tdescendant processes will not be followed\n")); break; default: - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tfollowing descendant processes: \n")); + sb.append (GTXT ("\tfollowing descendant processes: \n")); break; } if (java_mode == 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tjava profiling disabled\n")); + sb.append (GTXT ("\tjava profiling disabled\n")); if (pauseresume_sig != 0) { const char *buf = strsignal (pauseresume_sig); if (buf != NULL) { if (pauseresume_pause == 1) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tpause-resume (delayed initialization) signal %s (%d) -- paused\n"), buf, pauseresume_sig); + sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %s (%d) -- paused\n"), + buf, pauseresume_sig); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tpause-resume (delayed initialization) signal %s (%d)\n"), buf, pauseresume_sig); + sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %s (%d)\n"), + buf, pauseresume_sig); } else { if (pauseresume_pause == 1) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tpause-resume (delayed initialization) signal %d -- paused\n"), pauseresume_sig); + sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %d -- paused\n"), + pauseresume_sig); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tpause-resume (delayed initialization) signal %d\n"), pauseresume_sig); + sb.appendf (GTXT ("\tpause-resume (delayed initialization) signal %d\n"), + pauseresume_sig); } } if (sample_sig != 0) { const char *buf = strsignal (sample_sig); if (buf != NULL) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tsample signal %s (%d)\n"), buf, sample_sig); + sb.appendf (GTXT ("\tsample signal %s (%d)\n"), buf, sample_sig); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tsample signal %d\n"), sample_sig); + sb.appendf (GTXT ("\tsample signal %d\n"), sample_sig); } if (time_run != 0 || start_delay != 0) { if (start_delay != 0) { if (time_run != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdata-collection duration, %d-%d secs.\n"), start_delay, time_run); + sb.appendf (GTXT ("\tdata-collection duration, %d-%d secs.\n"), + start_delay, time_run); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdata-collection duration, %d- secs.\n"), start_delay); + sb.appendf (GTXT ("\tdata-collection duration, %d- secs.\n"), + start_delay); } else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdata-collection duration, %d secs.\n"), time_run); + sb.appendf (GTXT ("\tdata-collection duration, %d secs.\n"), time_run); } if (sample_period != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tperiodic sampling, %d secs.\n"), sample_period); + sb.appendf (GTXT ("\tperiodic sampling, %d secs.\n"), sample_period); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tno periodic sampling\n")); + sb.append (GTXT ("\tno periodic sampling\n")); if (size_limit != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\texperiment size limit %d MB.\n"), size_limit); + sb.appendf (GTXT ("\texperiment size limit %d MB.\n"), size_limit); else - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tno experiment size limit set\n")); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\texperiment archiving: -a %s\n"), archive_mode); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\tdata descriptor: \"%s\"\n"), + sb.append (GTXT ("\tno experiment size limit set\n")); + sb.appendf (GTXT ("\texperiment archiving: -a %s\n"), archive_mode); + sb.appendf (GTXT ("\tdata descriptor: \"%s\"\n"), ((data_desc != NULL) ? data_desc : NTXT (""))); -#if 0 - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t expt_dir: %s\n"), - ((expt_dir != NULL) ? expt_dir : NTXT (""))); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t base_name: %s\n"), - ((base_name != NULL) ? base_name : NTXT (""))); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t store_dir: %s\n"), - ((store_dir != NULL) ? store_dir : NTXT (""))); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t store_ptr: %s\n"), - ((store_ptr != NULL) ? store_ptr : NTXT (""))); -#endif - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t\thost: `%s', ncpus = %d, clock frequency %d MHz.\n"), + sb.appendf (GTXT ("\t\thost: `%s', ncpus = %d, clock frequency %d MHz.\n"), ((node_name != NULL) ? node_name : NTXT ("")), (int) ncpus, (int) cpu_clk_freq); if (npages > 0) { long long memsize = ((long long) npages * (long long) page_size) / (1024 * 1024); - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("\t\tmemory: %ld pages @ %ld bytes = %lld MB.\n"), + sb.appendf (GTXT ("\t\tmemory: %ld pages @ %ld bytes = %lld MB.\n"), npages, page_size, memsize); } - return strdup (UEbuf); + return sb.toString (); } #define MAX_COLLECT_ARGS 100 @@ -741,10 +676,9 @@ Coll_Ctrl::show (int i) char ** Coll_Ctrl::get_collect_args () { - char buf[DD_MAXPATHLEN]; char **p; char **argv = (char **) calloc (MAX_COLLECT_ARGS, sizeof (char *)); - if (argv == NULL) // poor way of dealing with calloc failure + if (argv == NULL) // poor way of dealing with calloc failure abort (); p = argv; *p++ = strdup ("collect"); @@ -753,25 +687,27 @@ Coll_Ctrl::get_collect_args () if (clkprof_enabled != 0) { *p++ = strdup ("-p"); - snprintf (buf, sizeof (buf), "%du", clkprof_timer); - *p++ = strdup (buf); + *p++ = dbe_sprintf ("%du", clkprof_timer); } if (hwcprof_enabled_cnt > 0) { - *buf = 0; + StringBuilder sb; *p++ = strdup ("-h"); for (int ii = 0; ii < hwcprof_enabled_cnt; ii++) { char*rateString = hwc_rate_string (&hwctr[ii], 1); //"1" is for temporary goldfile compatibility. TBR YXXX!! - snprintf (buf + strlen (buf), sizeof (buf) - strlen (buf), - "%s%s,%s%s", ii ? "," : "", hwctr[ii].name, - rateString ? rateString : "", - (ii + 1 < hwcprof_enabled_cnt) ? "," : ""); - free (rateString); + if (ii > 0) + sb.append (','); + sb.append (hwctr[ii].name); + if (rateString) + { + sb.append (rateString); + free (rateString); + } + if (ii + 1 < hwcprof_enabled_cnt) + sb.append (','); } - if (strlen (buf) + 1 >= sizeof (buf)) - abort (); - *p++ = strdup (buf); + *p++ = sb.toString (); } if (heaptrace_enabled != 0) { @@ -870,28 +806,14 @@ Coll_Ctrl::show_expt () { if (enabled == 0) return NULL; - char UEbuf[4096]; - UEbuf[0] = 0; - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("Creating experiment directory %s (Process ID: %ld) ...\n"), - ((store_ptr != NULL) ? store_ptr : NTXT ("")), (long) getpid ()); + StringBuilder sb; + sb.appendf (GTXT ("Creating experiment directory %s (Process ID: %ld) ...\n"), + store_ptr != NULL ? store_ptr : "", (long) getpid ()); char *caller = getenv ("SP_COLLECTOR_FROM_GUI"); // Collector from GUI - if (caller != NULL) // Print non-localized message - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - NTXT ("\nCreating experiment directory %s (Process ID: %ld) ...\n"), - ((store_ptr != NULL) ? store_ptr : NTXT ("")), (long) getpid ()); -#if 0 - char *fstype = get_fstype (store_dir); - if ((fstype != NULL) && (nofswarn == 0)) - { - // only warn if clock or hwc profiling is turned on - if (clkprof_enabled || hwcprof_enabled_cnt != 0) - snprintf (UEbuf + strlen (UEbuf), sizeof (UEbuf) - strlen (UEbuf), - GTXT ("this experiment is being recorded to a file system \nof type \"%s\", which may distort the measured performance."), - fstype); - } -#endif - return strdup (UEbuf); + if (caller != NULL) // Print non-localized message + sb.appendf ("\nCreating experiment directory %s (Process ID: %ld) ...\n", + store_ptr != NULL ? store_ptr : "", (long) getpid ()); + return sb.toString (); } void @@ -913,8 +835,8 @@ Coll_Ctrl::reset_clkprof (int val) { // profiler has had to reset to a different value; warn user char *msg = dbe_sprintf ( - GTXT ("Warning: Clock profiling timer reset from %.3f millisec. to %.3f millisec. as required by profiling driver\n\n"), - (double) (clkprof_timer) / 1000., (double) (val) / 1000.); + GTXT ("Warning: Clock profiling timer reset from %.3f millisec. to %.3f millisec. as required by profiling driver\n\n"), + (double) (clkprof_timer) / 1000., (double) (val) / 1000.); adjust_clkprof_timer (val); return msg; } @@ -954,7 +876,7 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn) double dval = strtod (string, &endchar); if (*endchar == 'm' || *endchar == 0) /* user specified milliseconds */ dval = dval * 1000.; - else if (*endchar == 'u') /* user specified microseconds */ + else if (*endchar == 'u') /* user specified microseconds */ dval = dval; else return dbe_sprintf (GTXT ("Unrecognized clock-profiling interval `%s'\n"), string); @@ -983,8 +905,8 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn) { /* value too small, use minimum value, with warning */ *warn = dbe_sprintf ( - GTXT ("Warning: Clock profiling at %.3f millisec. interval is not supported on this system; minimum %.3f millisec. used\n"), - (double) (nclkprof_timer) / 1000., (double) (clk_params.min) / 1000.); + GTXT ("Warning: Clock profiling at %.3f millisec. interval is not supported on this system; minimum %.3f millisec. used\n"), + (double) (nclkprof_timer) / 1000., (double) (clk_params.min) / 1000.); nclkprof_timer = clk_params.min; } @@ -992,8 +914,8 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn) if (nclkprof_timer > clk_params.max) { *warn = dbe_sprintf ( - GTXT ("Clock profiling at %.3f millisec. interval is not supported on this system; maximum %.3f millisec. used\n"), - (double) (nclkprof_timer) / 1000., (double) (clk_params.max) / 1000.); + GTXT ("Clock profiling at %.3f millisec. interval is not supported on this system; maximum %.3f millisec. used\n"), + (double) (nclkprof_timer) / 1000., (double) (clk_params.max) / 1000.); nclkprof_timer = clk_params.max; } @@ -1005,9 +927,9 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn) { /* no, we need to reset to a multiple */ *warn = dbe_sprintf ( - GTXT ("Clock profile interval rounded from %.3f to %.3f (system resolution = %.3f) millisec."), - (double) (nclkprof_timer) / 1000., (double) (ticks) / 1000., - (double) (clk_params.res) / 1000.); + GTXT ("Clock profile interval rounded from %.3f to %.3f (system resolution = %.3f) millisec."), + (double) (nclkprof_timer) / 1000., (double) (ticks) / 1000., + (double) (clk_params.res) / 1000.); nclkprof_timer = ticks; } } @@ -1068,7 +990,7 @@ Coll_Ctrl::set_synctrace (const char *string) /* clear the comma for the threshold determination */ *comma_p = 0; } - else /* no "," -- default to native and Java */ + else /* no "," -- default to native and Java */ synctrace_scope = SYNCSCOPE_NATIVE | SYNCSCOPE_JAVA; if (!strlen (val) || !strcmp (val, "calibrate") || !strcmp (val, "on")) { @@ -1241,7 +1163,7 @@ Coll_Ctrl::set_time_run (const char *valarg) { if (opened == 1) return strdup (GTXT ("Experiment is active; command ignored.\n")); - if (valarg == NULL) /* invalid setting */ + if (valarg == NULL) /* invalid setting */ return strdup (GTXT ("time parameter can not be NULL\n")); /* the string should be a number >= 0 */ int prev_start_delay = start_delay; @@ -1260,7 +1182,7 @@ Coll_Ctrl::set_time_run (const char *valarg) val = val * 60; /* convert to seconds */ endchar++; } - else if (*endchar == 's') /* no conversion needed */ + else if (*endchar == 's') /* no conversion needed */ endchar++; if (*endchar == 0) { @@ -1285,7 +1207,7 @@ Coll_Ctrl::set_time_run (const char *valarg) val = val * 60; /* convert to seconds */ endchar++; } - else if (*endchar == 's') /* no conversion needed */ + else if (*endchar == 's') /* no conversion needed */ endchar++; if (*endchar != 0) { @@ -1366,6 +1288,7 @@ Coll_Ctrl::hwcentry_dup (Hwcentry *hnew, Hwcentry *_hwc) } // Routine to initialize the HWC tables, set up the default experiment, etc. + void Coll_Ctrl::setup_hwc () { @@ -1451,15 +1374,10 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg) int rc = 0; int old_cnt = hwcprof_enabled_cnt; int prev_cnt = hwcprof_enabled_cnt; - // int old_hwcprof_default = hwcprof_default; - char UEbuf[MAXPATHLEN * 5]; - int UEsz; Hwcentry tmpctr[MAX_PICS]; Hwcentry * ctrtable[MAX_PICS]; char *emsg; char *wmsg; - UEbuf[0] = 0; - UEsz = sizeof (UEbuf); if (opened == 1) return strdup (GTXT ("Experiment is active; command ignored.\n")); if (hwcprof_default == 0) @@ -1468,7 +1386,7 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg) for (int ii = 0; ii < prev_cnt; ii++) tmpctr[ii] = hwctr[ii]; } - else /* the previously-defined counters were defaulted; don't copy them */ + else /* the previously-defined counters were defaulted; don't copy them */ prev_cnt = 0; /* look up the CPU version */ @@ -1509,22 +1427,28 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg) hwcprof_default = 0; hwcprof_enabled_cnt = rc; free (hwc_string); + StringBuilder sb; for (int ii = 0; ii < hwcprof_enabled_cnt; ii++) { /* shallow copy of new counters */ hwctr[ii] = tmpctr[ii]; char *rateString = hwc_rate_string (&hwctr[ii], 0); - snprintf (UEbuf + strlen (UEbuf), UEsz - strlen (UEbuf), - NTXT (",%s,%s"), hwctr[ii].name, - rateString ? rateString : ""); - free (rateString); + if (ii > 0) + sb.append (','); + sb.append (hwctr[ii].name); + sb.append (','); + if (rateString) + { + sb.append (rateString); + free (rateString); + } } - /* now duplicate that string, skipping the leading comma */ - hwc_string = strdup (&UEbuf[1]); + hwc_string = sb.toString (); return NULL; } /* add default HWC counters to counter set with resolution (on, hi, or lo) */ + /* Note that the resultion will also be used to set the clock-profiling default */ char * /* return an error string */ Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool add, bool forKernel) @@ -1591,7 +1515,7 @@ Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool a strncat (retp, stringp, (retsize - strlen (retp) - 1)); strncat (retp, ",", (retsize - strlen (retp) - 1)); strncat (retp, resolution, (retsize - strlen (retp) - 1)); - if (nextc == 0) /* string ended in comma; we're done */ + if (nextc == 0) /* string ended in comma; we're done */ break; } else @@ -1606,7 +1530,7 @@ Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool a } /* string had ,, between fields; move to next field */ stringp = next + 1; - if (* (stringp + 1) == 0) /* name ended in ,, -- we're done */ + if (* (stringp + 1) == 0) /* name ended in ,, -- we're done */ break; continue; } @@ -1765,10 +1689,10 @@ Coll_Ctrl::build_data_desc () if (ii > 0) sb.append (','); sb.appendf ("%d:%d:%lld:%s:%s:%lld:%d:m%lld:%d:%d:0x%x", - h->use_perf_event_type, h->type, (long long) h->config, - strcmp (h->name, h->int_name) ? h->name : "", - h->int_name, (long long) h->reg_num, h->val, - (long long) min_time, ii, /*tag*/ h->timecvt, h->memop); + h->use_perf_event_type, h->type, (long long) h->config, + strcmp (h->name, h->int_name) ? h->name : "", + h->int_name, (long long) h->reg_num, h->val, + (long long) min_time, ii, /*tag*/ h->timecvt, h->memop); } sb.append (";"); } @@ -1801,7 +1725,7 @@ Coll_Ctrl::check_group () // Is the group an relative path, with a store directory set? if ((expt_group[0] == '/') || ((udir_name == NULL) || (udir_name[0] == '0'))) snprintf (group_file, sizeof (group_file), "%s", expt_group); - else // relative path, store directory; make group_file in that directory + else // relative path, store directory; make group_file in that directory snprintf (group_file, sizeof (group_file), "%s/%s", udir_name, expt_group); // See if we can write the group file int ret = access (group_file, W_OK); @@ -1814,11 +1738,11 @@ Coll_Ctrl::check_group () ret = access (dir, W_OK); if (ret != 0) // group file does not exist; return dbe_sprintf (GTXT ("Directory (%s) for group file %s is not writeable: %s\n"), - dir, group_file, strerror (errno)); + dir, group_file, strerror (errno)); } else return dbe_sprintf (GTXT ("Group file %s is not writeable: %s\n"), - group_file, strerror (errno)); + group_file, strerror (errno)); } return NULL; } @@ -1841,8 +1765,8 @@ Coll_Ctrl::join_group () // Is the group an relative path, with a store directory set? if (expt_group[0] == '/' || udir_name == NULL || udir_name[0] == '0') snprintf (group_file, sizeof (group_file), "%s", expt_group); - else // relative path, store directory; make group_file in that directory - snprintf (group_file, sizeof (group_file), "%s/%s", udir_name, expt_group); + else // relative path, store directory; make group_file in that directory + snprintf (group_file, sizeof (group_file), "%s/%s", udir_name, expt_group); for (;;) { tries++; @@ -1910,7 +1834,7 @@ Coll_Ctrl::join_group () // If the error was not that the file did not exist, report it if (errno != ENOENT) return dbe_sprintf (GTXT ("Can't open group file %s: %s\n"), - group_file, strerror (errno)); + group_file, strerror (errno)); // the file did not exist, try to create it groupfd = open (group_file, O_CREAT | O_EXCL | O_RDWR, 0666); if (groupfd < 0) @@ -1919,7 +1843,7 @@ Coll_Ctrl::join_group () if (errno == EEXIST) continue; return dbe_sprintf (GTXT ("Can't create group file %s: %s\n"), - group_file, strerror (errno)); + group_file, strerror (errno)); } // we created the group file, now lock it, waiting for the lock while (fcntl (groupfd, F_SETLKW, &flockbuf) == -1) @@ -1989,7 +1913,7 @@ Coll_Ctrl::set_directory (char *dir, char **warn) } else (void) update_expt_name (false, false); - return NULL; // All is OK + return NULL; // All is OK } int @@ -2020,7 +1944,7 @@ Coll_Ctrl::set_expt (const char *ename, char **warn, bool overwriteExp) uexpt_name = NULL; return NULL; } - char *exptname = canonical_path(strdup(ename)); + char *exptname = canonical_path (strdup (ename)); size_t i = strlen (exptname); if (i < 4 || strcmp (&exptname[i - 3], ".er") != 0) { @@ -2116,7 +2040,7 @@ Coll_Ctrl::set_java_mode (const char *string) java_default = prev_java_default; return ret; } - free (java_path); + free (java_path); java_path = NULL; return NULL; } @@ -2240,11 +2164,6 @@ Coll_Ctrl::set_follow_mode (const char *string) return NULL; } // syntax error in parsing string -#if 0 - char errbuf[256]; - regerror (ercode, ®ex_desc, errbuf, sizeof (errbuf)); - fprintf (stderr, "Coll_Ctrl::set_follow_mode: regerror()=%s\n", errbuf); -#endif free (str); } return dbe_sprintf (GTXT ("Unrecognized follow-mode parameter `%s'\n"), string); @@ -2397,23 +2316,23 @@ Coll_Ctrl::create_exp_dir () int err = errno; if (err == EACCES) return dbe_sprintf (GTXT ("Store directory %s is not writeable: %s\n"), - store_dir, strerror (err)); + store_dir, strerror (err)); if (i + 1 >= max) // no more attempts return dbe_sprintf (GTXT ("Unable to create directory `%s' -- %s\n%s: %d\n"), - store_ptr, strerror (err), - GTXT ("collect: Internal error: loop count achieved"), - max); + store_ptr, strerror (err), + GTXT ("collect: Internal error: loop count achieved"), + max); char *ermsg = update_expt_name (false, false, true); if (ermsg != NULL) { char *msg = dbe_sprintf (GTXT ("Unable to create directory `%s' -- %s\n"), - store_ptr, ermsg); + store_ptr, ermsg); free (ermsg); return msg; } continue; } - return NULL; // All is OK + return NULL; // All is OK } return dbe_sprintf (GTXT ("Unable to create directory `%s'\n"), store_ptr); } @@ -2428,9 +2347,7 @@ Coll_Ctrl::get_exp_name (const char *stembase) char * Coll_Ctrl::preprocess_names () { - char buf[MAXPATHLEN]; - char msgbuf[MAXPATHLEN]; - char *ret = NULL; + StringBuilder sb; /* convert the experiment name and directory into store name/dir */ /* free the old strings */ @@ -2492,34 +2409,23 @@ Coll_Ctrl::preprocess_names () expt_name = c; free (stem); } - snprintf (buf, sizeof (buf), NTXT ("%s"), expt_name); - if (buf[0] == '/') - { - // it's a full path name - if (udir_name != NULL) - { - snprintf (msgbuf, sizeof (msgbuf), - GTXT ("Warning: Experiment name is an absolute path; directory name %s ignored.\n"), - udir_name); - ret = strdup (msgbuf); - } - } + if (*expt_name == '/' && udir_name != NULL) + sb.appendf (GTXT ("Warning: Experiment name is an absolute path; directory name %s ignored.\n"), + udir_name); // now extract the directory and basename - int lastslash = 0; - for (int i = 0;; i++) + char *s = strrchr (expt_name, '/'); + if (s == NULL) { - if (buf[i] == 0) - break; - if (buf[i] == '/') - lastslash = i; + expt_dir = strdup ("."); + base_name = strdup (expt_name); } - expt_dir = strdup (buf); - if (lastslash != 0) - base_name = strdup (&buf[lastslash + 1]); else - base_name = strdup (buf); - expt_dir[lastslash] = 0; + { + expt_dir = dbe_strndup (expt_name, s - expt_name - 1); + base_name = strdup (s + 1); + } + if (expt_dir[0] == '/') store_dir = strdup (expt_dir); else if ((udir_name == NULL) || (udir_name[0] == 0)) @@ -2535,19 +2441,13 @@ Coll_Ctrl::preprocess_names () if (expt_dir[0] == 0) store_dir = strdup (udir_name); else - { - snprintf (buf, sizeof (buf), "%s/%s", udir_name, expt_dir); - store_dir = strdup (buf); - } + store_dir = dbe_sprintf ("%s/%s", udir_name, expt_dir); } free (store_ptr); if (strcmp (store_dir, ".") == 0) store_ptr = strdup (base_name); else - { - snprintf (buf, sizeof (buf), "%s/%s", store_dir, base_name); - store_ptr = strdup (buf); - } + store_ptr = dbe_sprintf ("%s/%s", store_dir, base_name); // determine the file system type if (strcmp (store_dir, prev_store_dir) != 0) @@ -2556,15 +2456,13 @@ Coll_Ctrl::preprocess_names () prev_store_dir = strdup (store_dir); const char *fstype = get_fstype (store_dir); if (interactive && enabled && (fstype != NULL) && (nofswarn == 0)) - { - snprintf (msgbuf, sizeof (msgbuf), - GTXT ("%sExperiment directory is set to a file system of type \"%s\",\n which may distort the measured performance;\n it is preferable to record to a local disk.\n"), - (ret == NULL ? "" : ret), fstype); - free (ret); - ret = strdup (msgbuf); - } + sb.appendf (GTXT ("Experiment directory is set to a file system of type \"%s\",\n" + " which may distort the measured performance;\n" + " it is preferable to record to a local disk.\n"), fstype); } - return ret; + if (sb.length () == 0) + return NULL; + return sb.toString (); } char * @@ -2600,15 +2498,15 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname) while (isdigit ((int) (base_name[pcount])) != 0) { pcount--; - if (pcount == 0) // name is of the form 12345.er; don't update it + if (pcount == 0) // name is of the form 12345.er; don't update it return dbe_sprintf (GTXT ("name %s is in use and cannot be updated\n"), - base_name); + base_name); digits++; } - if (digits == 0) // name is of form xyz.er (or xyz..er); don't update it + if (digits == 0) // name is of form xyz.er (or xyz..er); don't update it return dbe_sprintf (GTXT ("name %s is in use and cannot be updated\n"), base_name); - if (base_name[pcount] != '.') // name is of form xyz123.er; don't update it + if (base_name[pcount] != '.') // name is of form xyz123.er; don't update it return dbe_sprintf (GTXT ("name %s is in use and cannot be updated\n"), base_name); if (chkonly) @@ -2619,7 +2517,7 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname) // the name is of the from prefix.nnn.er; extract the value of nnn int version = atoi (&base_name[pcount + 1]); - if (newname) // do not try to use old name + if (newname) // do not try to use old name version++; int max_version = version - 1; @@ -2664,7 +2562,7 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname) if ((strcmp (oldbase, newbase) != 0) && chgmsg) { ret = dbe_sprintf (GTXT ("name %s is in use; changed to %s\n"), - oldbase, newbase); + oldbase, newbase); free (oldbase); } else @@ -2730,17 +2628,17 @@ Coll_Ctrl::determine_profile_params () // now reset the timer to turn it off itimer.it_value.tv_sec = 0; itimer.it_value.tv_usec = 0; - if (setitimer (ITIMER_REALPROF, &itimer, &otimer) == -1) // call failed + if (setitimer (ITIMER_REALPROF, &itimer, &otimer) == -1) // call failed nperiod = -1; else nperiod = otimer.it_interval.tv_sec * MICROSEC + otimer.it_interval.tv_usec; // check the returned value: is the what we asked for? - if (period == nperiod) // arbitrary precision is OK + if (period == nperiod) // arbitrary precision is OK set_clk_params (PROFINT_MIN, 1, PROFINT_MAX, PROFINT_HIGH, PROFINT_NORM, PROFINT_LOW); else if (nperiod < 10000) // hi resolution allowed, but not arbitrary precision set_clk_params ((int) nperiod, 1000, PROFINT_MAX, 1000, 10000, 100000); - else // low resolution only allowed + else // low resolution only allowed set_clk_params (10000, 10000, PROFINT_MAX, 1000, 10000, 100000); // If old handler was default, ignore it; otherwise restore it @@ -2791,7 +2689,7 @@ const char *ipc_str_synctrace = "synctrace"; const char *ipc_str_heaptrace = "heaptrace"; const char *ipc_str_iotrace = "iotrace"; const char *ipc_str_count = "count"; -const char *ipc_str_prof_idle = "prof_idle"; // -x option +const char *ipc_str_prof_idle = "prof_idle"; // -x option // Standard answers const char *ipc_str_empty = ""; const char *ipc_str_on = "on"; @@ -2870,7 +2768,7 @@ Coll_Ctrl::get (char * control) } if (!strncmp (control, ipc_str_clkprof, len)) { - if (clkprof_default == 1 && clkprof_enabled == 1) // Default value + if (clkprof_default == 1 && clkprof_enabled == 1) // Default value return strdup (ipc_str_empty); if (clkprof_enabled == 0) return strdup (ipc_str_off); @@ -2894,7 +2792,7 @@ Coll_Ctrl::get (char * control) } if (!strncmp (control, ipc_str_sample, len)) { - if (sample_default == 1 && sample_period == 1) // Default value + if (sample_default == 1 && sample_period == 1) // Default value return strdup (ipc_str_empty); if (sample_period == 0) return strdup (ipc_str_off); diff --git a/gprofng/src/collctrl.h b/gprofng/src/collctrl.h index 5f1ee26d902..a41647440ac 100644 --- a/gprofng/src/collctrl.h +++ b/gprofng/src/collctrl.h @@ -87,7 +87,6 @@ public: void set_clk_params(int min, int res, int max, int hi, int norm, int lo); char *set_clkprof(const char *valptr, char **warn); char *reset_clkprof(int val); /* called if profiler must reset value */ - int get_sys_period() { return clk_params.min; }; int get_clk_min() { return clk_params.min; }; int get_clk_max() { return clk_params.max; }; int get_clk_res() { return clk_params.res; }; @@ -275,7 +274,6 @@ private: int cpu_clk_freq; /* chip clock (MHz.), as reported from processor_info */ int cpc_cpuver; /* chip version, as reported from libcpc */ long sys_resolution; /* system clock resolution */ - int sys_period; /* profiling clock resolution on the system */ int sample_period; /* period for sampling, seconds */ int sample_default; /* if period for sampling set by default */ int size_limit; /* experiment size limit, MB */