Skip to contentSkip to conversation

perf: Use strcmp() for "ftrace:function" check

PATCH New Steven Rostedt 1 participant 1 message Dec 20, 2018 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: Use strcmp() for "ftrace:function" check

As strncmp(str, "const", sizeof("const") is exactly the same as strcmp(str, "const") use that instead, otherwise it is confusing.

The test if the event name is "ftrace:function" in perf_evsel__set_sample_id() is rather strange as it makes an unnecessary macro of FUNCTION_EVENT to equal "ftrace:function" and uses that twice so that it can do the sizeof(). But since sizeof("const") includes the nul terminator ('\0') of the string "const" that compare is the same as using strcmp().

With strcmp() there's no need to use the string twice, and that also means the FUNCTION_EVENT macro is not needed.

---

tools/perf/util/evsel.c +1 -6
index d37bb1566cd9..58a452d77951 100644
@@ -215,12 +215,7 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel,
  */
 bool perf_evsel__is_function_event(struct perf_evsel *evsel)
 {
-#define FUNCTION_EVENT "ftrace:function"
-
-	return evsel->name &&
-	       !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
-
-#undef FUNCTION_EVENT
+	return evsel->name && !strcmp("ftrace:function", evsel->name);
 }
 
 void perf_evsel__init(struct perf_evsel *evsel,