Skip to contentSkip to conversation

perf stat: use sysfs_streq() instead of strncmp()

PATCH In review [email protected] 2 participants 2 messages Nov 22, 2022 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf stat: use sysfs_streq() instead of strncmp()

From: Xu Panda <[email protected]>

Replace the open-code with sysfs_streq().

---
 tools/perf/util/stat-display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/stat-display.c +2 -3
index f5501760ff2e..1fd9f7e9d2a1 100644
@@ -463,7 +463,7 @@ static bool valid_only_metric(const char *unit)
 static const char *fixunit(char *buf, struct evsel *evsel,
 			   const char *unit)
 {
-	if (!strncmp(unit, "of all", 6)) {
+	if (sysfs_streq(unit, "of all")) {
 		snprintf(buf, 1024, "%s %s", evsel__name(evsel),
 			 unit);
 		return buf;
@@ -767,8 +767,7 @@ static void uniquify_event_name(struct evsel *counter)
 	int ret = 0;
 
 	if (counter->uniquified_name || counter->use_config_name ||
-	    !counter->pmu_name || !strncmp(counter->name, counter->pmu_name,
-					   strlen(counter->pmu_name)))
+	    !counter->pmu_name || sysfs_streq(counter->name, counter->pmu_name))
 		return;
 
 	config = strchr(counter->name, '/');
Signature · 1 line
2.15.2
maintainer
#1 lore raw

Hello,

Quoted 4 lines · On Tue, Nov 22, 2022 at 4:11 AM <[email protected]> wrote:

From: Xu Panda <[email protected]>

Replace the open-code with sysfs_streq().

I don't think it's equivalent to strncmp() and it seems not available in the tools.

Thanks,
Namhyung

Quoted 32 lines
---
 tools/perf/util/stat-display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/stat-display.c +2 -4
index f5501760ff2e..1fd9f7e9d2a1 100644
@@ -463,7 +463,7 @@ static bool valid_only_metric(const char *unit)
 static const char *fixunit(char *buf, struct evsel *evsel,
                           const char *unit)
 {
-       if (!strncmp(unit, "of all", 6)) {
+       if (sysfs_streq(unit, "of all")) {
                snprintf(buf, 1024, "%s %s", evsel__name(evsel),
                         unit);
                return buf;
@@ -767,8 +767,7 @@ static void uniquify_event_name(struct evsel *counter)
        int ret = 0;
 
        if (counter->uniquified_name || counter->use_config_name ||
-           !counter->pmu_name || !strncmp(counter->name, counter->pmu_name,
-                                          strlen(counter->pmu_name)))
+           !counter->pmu_name || sysfs_streq(counter->name, counter->pmu_name))
                return;
 
        config = strchr(counter->name, '/');
--

2.15.2