[v2,4/9] trace: rework loop on trace points

Message ID 20221004094418.196544-5-david.marchand@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Trace subsystem fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand Oct. 4, 2022, 9:44 a.m. UTC
  Directly skip the block when a trace point does not match the user
criteria.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_trace.c | 34 +++++++++++++++++--------------
 1 file changed, 19 insertions(+), 15 deletions(-)
  

Comments

Jerin Jacob Oct. 11, 2022, 2:21 p.m. UTC | #1
On Tue, Oct 4, 2022 at 3:15 PM David Marchand <david.marchand@redhat.com> wrote:
>
> Directly skip the block when a trace point does not match the user
> criteria.
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Jerin Jacob <jerinj@marvell.com>


> ---
>  lib/eal/common/eal_common_trace.c | 34 +++++++++++++++++--------------
>  1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> index 1db11e3e14..6b8660c318 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c
> @@ -186,15 +186,18 @@ rte_trace_pattern(const char *pattern, bool enable)
>         int rc = 0, found = 0;
>
>         STAILQ_FOREACH(tp, &tp_list, next) {
> -               if (fnmatch(pattern, tp->name, 0) == 0) {
> -                       if (enable)
> -                               rc = rte_trace_point_enable(tp->handle);
> -                       else
> -                               rc = rte_trace_point_disable(tp->handle);
> -                       found = 1;
> +               if (fnmatch(pattern, tp->name, 0) != 0)
> +                       continue;
> +
> +               if (enable)
> +                       rc = rte_trace_point_enable(tp->handle);
> +               else
> +                       rc = rte_trace_point_disable(tp->handle);
> +               if (rc < 0) {
> +                       found = 0;
> +                       break;
>                 }
> -               if (rc < 0)
> -                       return rc;
> +               found = 1;
>         }
>
>         return rc | found;
> @@ -211,17 +214,18 @@ rte_trace_regexp(const char *regex, bool enable)
>                 return -EINVAL;
>
>         STAILQ_FOREACH(tp, &tp_list, next) {
> -               if (regexec(&r, tp->name, 0, NULL, 0) == 0) {
> -                       if (enable)
> -                               rc = rte_trace_point_enable(tp->handle);
> -                       else
> -                               rc = rte_trace_point_disable(tp->handle);
> -                       found = 1;
> -               }
> +               if (regexec(&r, tp->name, 0, NULL, 0) != 0)
> +                       continue;
> +
> +               if (enable)
> +                       rc = rte_trace_point_enable(tp->handle);
> +               else
> +                       rc = rte_trace_point_disable(tp->handle);
>                 if (rc < 0) {
>                         found = 0;
>                         break;
>                 }
> +               found = 1;
>         }
>         regfree(&r);
>
> --
> 2.37.3
>
  
Sunil Kumar Kori Oct. 12, 2022, 9:13 a.m. UTC | #2
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: Tuesday, October 4, 2022 3:14 PM
> To: dev@dpdk.org
> Cc: skori@mavell.com; Jerin Jacob Kollanukkaran <jerinj@marvell.com>;
> Sunil Kumar Kori <skori@marvell.com>
> Subject: [EXT] [PATCH v2 4/9] trace: rework loop on trace points
> 
> External Email
> 
> ----------------------------------------------------------------------
> Directly skip the block when a trace point does not match the user criteria.
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  lib/eal/common/eal_common_trace.c | 34 +++++++++++++++++--------------
>  1 file changed, 19 insertions(+), 15 deletions(-)
> 

Acked-by: Sunil Kumar Kori <skori@marvell.com>

> diff --git a/lib/eal/common/eal_common_trace.c
> b/lib/eal/common/eal_common_trace.c
> index 1db11e3e14..6b8660c318 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c

[snip]

> 2.37.3
  

Patch

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 1db11e3e14..6b8660c318 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -186,15 +186,18 @@  rte_trace_pattern(const char *pattern, bool enable)
 	int rc = 0, found = 0;
 
 	STAILQ_FOREACH(tp, &tp_list, next) {
-		if (fnmatch(pattern, tp->name, 0) == 0) {
-			if (enable)
-				rc = rte_trace_point_enable(tp->handle);
-			else
-				rc = rte_trace_point_disable(tp->handle);
-			found = 1;
+		if (fnmatch(pattern, tp->name, 0) != 0)
+			continue;
+
+		if (enable)
+			rc = rte_trace_point_enable(tp->handle);
+		else
+			rc = rte_trace_point_disable(tp->handle);
+		if (rc < 0) {
+			found = 0;
+			break;
 		}
-		if (rc < 0)
-			return rc;
+		found = 1;
 	}
 
 	return rc | found;
@@ -211,17 +214,18 @@  rte_trace_regexp(const char *regex, bool enable)
 		return -EINVAL;
 
 	STAILQ_FOREACH(tp, &tp_list, next) {
-		if (regexec(&r, tp->name, 0, NULL, 0) == 0) {
-			if (enable)
-				rc = rte_trace_point_enable(tp->handle);
-			else
-				rc = rte_trace_point_disable(tp->handle);
-			found = 1;
-		}
+		if (regexec(&r, tp->name, 0, NULL, 0) != 0)
+			continue;
+
+		if (enable)
+			rc = rte_trace_point_enable(tp->handle);
+		else
+			rc = rte_trace_point_disable(tp->handle);
 		if (rc < 0) {
 			found = 0;
 			break;
 		}
+		found = 1;
 	}
 	regfree(&r);