Message ID | 20230110222003.1591436-1-irogers@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2996574wrt; Tue, 10 Jan 2023 14:21:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXv9zTBCCCUMVMpbVDoQ9A3532BnOV4WDqNHV6iLqmWFXjtV3zBOYLBCIF5BukhInfmTJcN6 X-Received: by 2002:a17:902:ce05:b0:193:3b4b:1a4d with SMTP id k5-20020a170902ce0500b001933b4b1a4dmr6960236plg.63.1673389298003; Tue, 10 Jan 2023 14:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673389297; cv=none; d=google.com; s=arc-20160816; b=Tpa55ak/3IR0FdUvFBHpmJArZjU/KyV7PtwK2Z+J5BJWfyIQR48nRAD3XLfaYu1bE0 HJr8ir/cRSEKHjC320lSXqJVsMcPar4+BrXLuyi2rXAbPIRC2apH4rFKWFv+7s/0PW2F oLEd/01pw4m6VKE3G4EkxidxXjiMMdFapfsXA9xjreHFS2QTV6FSoyaUXco90/7XdfDZ lN+ISPgfeccBkbVRNI2NiLzzC6YUyBQiXyDBmCid2ELuZnNsjNkY/3zKTzwNA4mc06aK BzjaCAl18pM/8ZkOwW9UpEMz1odfTkiTfnOmHG0KXTc6FHu7mT7tYdkP0qGXJOshE7GI VMHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=Nlle/Ds4SGPTSO3cAFMNWJvr6o/XSd9jrGxltpsb3Is=; b=QYfPXggzsMQHaoN6/8ZCNMsvx/twhITjWoDtWoTlRw/o+USWQPWoia2FxQqv2H8Wxb 8clu8OhdX+fzNieyzyF+VO6JeqCvD2UGmk6n6YqynCmON0QcZuF8/Hjz0kwSowRttF2+ 62ZN8wW+mJlZ5s/8kXOm4hpq8Sf60yheIWY5hGQaApn3fzBsKgKvcnPc0vTBpKLnVbOy FLzmLtaIVeWlXXkyJ3t1qh0csZuBO+8jd5BF7hFdddNCkmCS35X69cX7Q01YJBRRHLP2 AxqVvhCJi5qoTm9HS5ibMT8wdXtbVC9moZhdueQAlbrdESyXJA81R0B7V93QQsrcfdRi GKaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ftX8xF0c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a17090311c600b0018938988ea9si13137011plh.520.2023.01.10.14.21.25; Tue, 10 Jan 2023 14:21:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ftX8xF0c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234780AbjAJWUb (ORCPT <rfc822;syz17693488234@gmail.com> + 99 others); Tue, 10 Jan 2023 17:20:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231265AbjAJWUV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 10 Jan 2023 17:20:21 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 095865D89C for <linux-kernel@vger.kernel.org>; Tue, 10 Jan 2023 14:20:18 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id e12-20020a25500c000000b007b48c520262so14248322ybb.14 for <linux-kernel@vger.kernel.org>; Tue, 10 Jan 2023 14:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=Nlle/Ds4SGPTSO3cAFMNWJvr6o/XSd9jrGxltpsb3Is=; b=ftX8xF0c4UQtCj8N+r4KjGdZEM2Q89eJAcT0lc5k/816CbQ+dPH3JYa+OAjFdHDNVd QyNvH3IJFde6G23zqfZ76D+IjfOJOEJQC8/srm5Q4JQO34ZQ6PHCNQNnk3T97ACazfYQ HHQBjOaNCkKCHAbfEPLr9p1YUIFhxolo+DlVnsz+cKtev8lxSLSXqjvP+LHfkU1/k/jk qPt0UvhGHIZTQfM9cCSp12yKvJbykIDjFeZDqP1xycj4bpUaMhu7YD3N+s012svSe704 7D2j18A1UUV+BbCbxOCelY+whUXsx9mWkDkQvlwuDsyBryuamdZKE2ycCj+IlrBL6lUX Zfeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Nlle/Ds4SGPTSO3cAFMNWJvr6o/XSd9jrGxltpsb3Is=; b=MDdbOXm4y8NeekJQliYcma+6cAotq7/r/eC4mU87uLq0c7klE53wpN7UVQLChf2WUM vXjqHHm8NBxkR1Ewowa6c8o8muAvy0DOdA9NwmoREz261y/o6ilmNMJRSAYug+0Jy04y gZ+88RBf93pJ3sNBM4HFtAjJdu8c/MoBccup8IpPIS+MdmCzudwaUalp/oBcJVrRC0Y4 P6ZuGwcXQj9lyjgEI6i+3USzfxWKfN0wMMC6vwcsemyluu+Vno3kJu/KEAcApk1C0Q6s FuzuTTY2hRe7RgiPWM6s4RlQpyqTGaGXaEE6fb06nNMRvU2yOHadypBFSn1XAIROHc/R MZkw== X-Gm-Message-State: AFqh2krD4QW6QLdNdT/aL4Hrl2eu0r0TY8YkcLEEBu9GB97EFETNUaEG QmbEcReFnJH9lWXDr4a1wCHkCKNrYIUm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:cebf:c37e:8184:56]) (user=irogers job=sendgmr) by 2002:a25:8a8c:0:b0:7a7:c930:e66c with SMTP id h12-20020a258a8c000000b007a7c930e66cmr3763503ybl.644.1673389217080; Tue, 10 Jan 2023 14:20:17 -0800 (PST) Date: Tue, 10 Jan 2023 14:19:56 -0800 Message-Id: <20230110222003.1591436-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v1 0/7] Add and use run_command_strbuf From: Ian Rogers <irogers@google.com> To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Arnaldo Carvalho de Melo <acme@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Alexander Shishkin <alexander.shishkin@linux.intel.com>, Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Nicolas Schier <nicolas@fjasle.eu>, Masahiro Yamada <masahiroy@kernel.org>, Athira Rajeev <atrajeev@linux.vnet.ibm.com>, Christy Lee <christylee@fb.com>, Andrii Nakryiko <andrii@kernel.org>, Ravi Bangoria <ravi.bangoria@amd.com>, Leo Yan <leo.yan@linaro.org>, Yang Jihong <yangjihong1@huawei.com>, Qi Liu <liuqi115@huawei.com>, James Clark <james.clark@arm.com>, Adrian Hunter <adrian.hunter@intel.com>, "Masami Hiramatsu (Google)" <mhiramat@kernel.org>, Kan Liang <kan.liang@linux.intel.com>, Sean Christopherson <seanjc@google.com>, Zhengjun Xing <zhengjun.xing@linux.intel.com>, Rob Herring <robh@kernel.org>, Xin Gao <gaoxin@cdjrlc.com>, Zechuan Chen <chenzechuan1@huawei.com>, Jason Wang <wangborong@cdjrlc.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, Stephane Eranian <eranian@google.com>, German Gomez <german.gomez@arm.com>, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers <irogers@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754675856394965357?= X-GMAIL-MSGID: =?utf-8?q?1754675856394965357?= |
Series |
Add and use run_command_strbuf
|
|
Message
Ian Rogers
Jan. 10, 2023, 10:19 p.m. UTC
It is commonly useful to run a command using "/bin/sh -c" (like popen) and to place the output in a string. Move strbuf to libapi, add a new run_command that places output in a strbuf, then use it in help and llvm in perf. Some small strbuf efficiency improvements are included. Whilst adding a new function should increase lines-of-code, by sharing two similar usages in perf llvm and perf help, the overall lines-of-code is moderately reduced. First "perf llvm: Fix inadvertent file creation" is cherry-picked from: https://lore.kernel.org/lkml/20230105082609.344538-1-irogers@google.com/ to avoid a merge conflict. The next patches deal with moving strbuf, adding the run_command function with Makefile dependency from libsubcmd to libapi, and improving the strbuf performance. The final two patches add usage from the perf command. Ian Rogers (7): perf llvm: Fix inadvertent file creation tools lib: Move strbuf to libapi tools lib subcmd: Add run_command_strbuf tools lib api: Minor strbuf_read improvements tools lib api: Tweak strbuf allocation size computation perf help: Use run_command_strbuf perf llvm: Remove read_from_pipe tools/lib/api/Build | 1 + tools/lib/api/Makefile | 2 +- tools/{perf/util => lib/api}/strbuf.c | 28 ++-- tools/{perf/util => lib/api}/strbuf.h | 0 tools/lib/subcmd/Makefile | 32 +++- tools/lib/subcmd/run-command.c | 30 ++++ tools/lib/subcmd/run-command.h | 14 ++ tools/perf/bench/evlist-open-close.c | 2 +- tools/perf/builtin-help.c | 49 ++---- tools/perf/builtin-list.c | 2 +- tools/perf/tests/bpf.c | 12 +- tools/perf/tests/llvm.c | 18 +-- tools/perf/tests/llvm.h | 3 +- tools/perf/util/Build | 1 - tools/perf/util/bpf-loader.c | 9 +- tools/perf/util/cache.h | 2 +- tools/perf/util/dwarf-aux.c | 2 +- tools/perf/util/env.c | 2 +- tools/perf/util/header.c | 2 +- tools/perf/util/llvm-utils.c | 207 ++++++++------------------ tools/perf/util/llvm-utils.h | 6 +- tools/perf/util/metricgroup.c | 2 +- tools/perf/util/pfm.c | 2 +- tools/perf/util/pmu.c | 2 +- tools/perf/util/probe-event.c | 2 +- tools/perf/util/probe-file.c | 2 +- tools/perf/util/probe-finder.c | 2 +- tools/perf/util/sort.c | 2 +- 28 files changed, 201 insertions(+), 237 deletions(-) rename tools/{perf/util => lib/api}/strbuf.c (87%) rename tools/{perf/util => lib/api}/strbuf.h (100%)
Comments
On Tue, Jan 10, 2023 at 2:20 PM Ian Rogers <irogers@google.com> wrote: > > It is commonly useful to run a command using "/bin/sh -c" (like popen) > and to place the output in a string. Move strbuf to libapi, add a new > run_command that places output in a strbuf, then use it in help and > llvm in perf. Some small strbuf efficiency improvements are > included. Whilst adding a new function should increase lines-of-code, > by sharing two similar usages in perf llvm and perf help, the overall > lines-of-code is moderately reduced. > > First "perf llvm: Fix inadvertent file creation" is cherry-picked > from: > https://lore.kernel.org/lkml/20230105082609.344538-1-irogers@google.com/ > to avoid a merge conflict. The next patches deal with moving strbuf, > adding the run_command function with Makefile dependency from > libsubcmd to libapi, and improving the strbuf performance. The final > two patches add usage from the perf command. > > Ian Rogers (7): > perf llvm: Fix inadvertent file creation > tools lib: Move strbuf to libapi > tools lib subcmd: Add run_command_strbuf > tools lib api: Minor strbuf_read improvements > tools lib api: Tweak strbuf allocation size computation > perf help: Use run_command_strbuf > perf llvm: Remove read_from_pipe This isn't ready yet. Kernel test robot reported legitimate build breakages in other tools outside of perf, I'm looking to address those in separate patch series. https://lore.kernel.org/lkml/20230116215751.633675-1-irogers@google.com/ Thanks, Ian > tools/lib/api/Build | 1 + > tools/lib/api/Makefile | 2 +- > tools/{perf/util => lib/api}/strbuf.c | 28 ++-- > tools/{perf/util => lib/api}/strbuf.h | 0 > tools/lib/subcmd/Makefile | 32 +++- > tools/lib/subcmd/run-command.c | 30 ++++ > tools/lib/subcmd/run-command.h | 14 ++ > tools/perf/bench/evlist-open-close.c | 2 +- > tools/perf/builtin-help.c | 49 ++---- > tools/perf/builtin-list.c | 2 +- > tools/perf/tests/bpf.c | 12 +- > tools/perf/tests/llvm.c | 18 +-- > tools/perf/tests/llvm.h | 3 +- > tools/perf/util/Build | 1 - > tools/perf/util/bpf-loader.c | 9 +- > tools/perf/util/cache.h | 2 +- > tools/perf/util/dwarf-aux.c | 2 +- > tools/perf/util/env.c | 2 +- > tools/perf/util/header.c | 2 +- > tools/perf/util/llvm-utils.c | 207 ++++++++------------------ > tools/perf/util/llvm-utils.h | 6 +- > tools/perf/util/metricgroup.c | 2 +- > tools/perf/util/pfm.c | 2 +- > tools/perf/util/pmu.c | 2 +- > tools/perf/util/probe-event.c | 2 +- > tools/perf/util/probe-file.c | 2 +- > tools/perf/util/probe-finder.c | 2 +- > tools/perf/util/sort.c | 2 +- > 28 files changed, 201 insertions(+), 237 deletions(-) > rename tools/{perf/util => lib/api}/strbuf.c (87%) > rename tools/{perf/util => lib/api}/strbuf.h (100%) > > -- > 2.39.0.314.g84b9a713c41-goog >
Em Thu, Jan 19, 2023 at 08:05:36AM -0800, Ian Rogers escreveu: > On Tue, Jan 10, 2023 at 2:20 PM Ian Rogers <irogers@google.com> wrote: > > > > It is commonly useful to run a command using "/bin/sh -c" (like popen) > > and to place the output in a string. Move strbuf to libapi, add a new > > run_command that places output in a strbuf, then use it in help and > > llvm in perf. Some small strbuf efficiency improvements are > > included. Whilst adding a new function should increase lines-of-code, > > by sharing two similar usages in perf llvm and perf help, the overall > > lines-of-code is moderately reduced. > > > > First "perf llvm: Fix inadvertent file creation" is cherry-picked > > from: > > https://lore.kernel.org/lkml/20230105082609.344538-1-irogers@google.com/ > > to avoid a merge conflict. The next patches deal with moving strbuf, > > adding the run_command function with Makefile dependency from > > libsubcmd to libapi, and improving the strbuf performance. The final > > two patches add usage from the perf command. > > > > Ian Rogers (7): > > perf llvm: Fix inadvertent file creation > > tools lib: Move strbuf to libapi > > tools lib subcmd: Add run_command_strbuf > > tools lib api: Minor strbuf_read improvements > > tools lib api: Tweak strbuf allocation size computation > > perf help: Use run_command_strbuf > > perf llvm: Remove read_from_pipe > > This isn't ready yet. Kernel test robot reported legitimate build > breakages in other tools outside of perf, I'm looking to address those > in separate patch series. > https://lore.kernel.org/lkml/20230116215751.633675-1-irogers@google.com/ Thanks for the heads up, I recall seeing a build bot report. It's great to have that build bot testing perf patches, thanks to whoever put it in place! - Arnaldo