Skip to contentSkip to conversation

pfunct: Don't print functions twice when using -f

PATCH In review Arnaldo Carvalho de Melo 2 participants 3 messages Dec 30, 2024 – Jan 9, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pfunct: Don't print functions twice when using -f

We print it in the pfunct_stealer, i.e. as soon as we load the CU containing the function information, and then, later, we were iterating all cus and printing the functions that matched.

Do it just at the stealer.

---
 pfunct.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
pfunct.c +4 -7
index 55eafe8a8e790dcb..5a6dd59a1c7a30b1 100644
@@ -415,14 +415,12 @@ static void function__show(struct function *func, struct cu *cu)
 		fstats->printed = true;
 }
 
-static int cu_function_iterator(struct cu *cu, void *cookie)
+static int cu_function_iterator(struct cu *cu, void *cookie __maybe_unused)
 {
 	struct function *function;
 	uint32_t id;
 
 	cu__for_each_function(cu, id, function) {
-		if (cookie && strcmp(function__name(function), cookie) != 0)
-			continue;
 		function__show(function, cu);
 	}
 	return 0;
@@ -816,10 +814,9 @@ try_sole_arg_as_function_name:
 		function__show(f, cu);
 	} else if (show_total_inline_expansion_stats)
 		print_total_inline_stats();
-	else if (function_name != NULL || expand_types)
-		cus__for_each_cu(cus, cu_function_iterator,
-				 function_name, NULL);
-	else
+	else if (expand_types)
+		cus__for_each_cu(cus, cu_function_iterator, NULL, NULL);
+	else if (function_name == NULL)
 		print_fn_stats(formatter);
 
 	rc = EXIT_SUCCESS;
Signature · 1 line
2.46.2
Tested-by on v1 1/1
#1 lore raw
Quoted 12 lines · Arnaldo Carvalho de Melo

We print it in the pfunct_stealer, i.e. as soon as we load the CU containing the function information, and then, later, we were iterating all cus and printing the functions that matched.

Do it just at the stealer.

Cc Alan Maguire [email protected]
Cc Andrii Nakryiko [email protected]
Quoted 8 lines
Cc Eduard Zingerman [email protected]
Cc Ihor Solodrai [email protected]
Cc Mykola Lysenko [email protected]

Can confirm this fixes double-printing of some functions when running pfunct -F dwarf

Quoted 42 lines

---
pfunct.c | 11 ++++-------

1 file changed, 4 insertions(+), 7 deletions(-)
pfunct.c +1 -3
index 55eafe8a8e790dcb..5a6dd59a1c7a30b1 100644
@@ -415,14 +415,12 @@ static void function__show(struct function *func, struct cu *cu)
 fstats->printed = true;
 
 }
 
-static int cu_function_iterator(struct cu *cu, void *cookie)
+static int cu_function_iterator(struct cu *cu, void *cookie __maybe_unused)
 {
 struct function *function;
 uint32_t id;
 
 cu__for_each_function(cu, id, function) {
- if (cookie && strcmp(function__name(function), cookie) != 0)
- continue;
 function__show(function, cu);
 }

return 0;

pfunct.c +3 -5
@@ -816,10 +814,9 @@ try_sole_arg_as_function_name:
 function__show(f, cu);
 } else if (show_total_inline_expansion_stats)
 print_total_inline_stats();
- else if (function_name != NULL || expand_types)
- cus__for_each_cu(cus, cu_function_iterator,
- function_name, NULL);
- else
+ else if (expand_types)
+ cus__for_each_cu(cus, cu_function_iterator, NULL, NULL);
+ else if (function_name == NULL)
 print_fn_stats(formatter);
 
 rc = EXIT_SUCCESS;
--

2.46.2

#2 lore raw
Quoted 20 lines · Ihor Solodrai
Quoted 18 lines · Arnaldo Carvalho de Melo

We print it in the pfunct_stealer, i.e. as soon as we load the CU containing the function information, and then, later, we were iterating all cus and printing the functions that matched.

Do it just at the stealer.

Cc Alan Maguire [email protected]
Cc Andrii Nakryiko [email protected]
Cc Eduard Zingerman [email protected]
Cc Ihor Solodrai [email protected]
Cc Mykola Lysenko [email protected]
Quoted 7 lines
Quoted 2 lines

Can confirm this fixes double-printing of some functions when running pfunct -F dwarf

Thanks, added to the cset.

- Arnaldo

Quoted 42 lines
Quoted 42 lines

---
pfunct.c | 11 ++++-------

1 file changed, 4 insertions(+), 7 deletions(-)
pfunct.c +1 -3
index 55eafe8a8e790dcb..5a6dd59a1c7a30b1 100644
@@ -415,14 +415,12 @@ static void function__show(struct function *func, struct cu *cu)
 fstats->printed = true;
 
 }
 
-static int cu_function_iterator(struct cu *cu, void *cookie)
+static int cu_function_iterator(struct cu *cu, void *cookie __maybe_unused)
 {
 struct function *function;
 uint32_t id;
 
 cu__for_each_function(cu, id, function) {
- if (cookie && strcmp(function__name(function), cookie) != 0)
- continue;
 function__show(function, cu);
 }

return 0;

pfunct.c +3 -5
@@ -816,10 +814,9 @@ try_sole_arg_as_function_name:
 function__show(f, cu);
 } else if (show_total_inline_expansion_stats)
 print_total_inline_stats();
- else if (function_name != NULL || expand_types)
- cus__for_each_cu(cus, cu_function_iterator,
- function_name, NULL);
- else
+ else if (expand_types)
+ cus__for_each_cu(cus, cu_function_iterator, NULL, NULL);
+ else if (function_name == NULL)
 print_fn_stats(formatter);
 
 rc = EXIT_SUCCESS;
--

2.46.2