diff mbox series

[v2,5/5] kernel-shark-qt: Fix a bug in kshark_data_collection_alloc()

Message ID 20181001135921.32379-6-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series Final preparation before adding the KernelShark GUI | expand

Commit Message

Yordan Karadzhov Oct. 1, 2018, 1:59 p.m. UTC
The margin data added at the end of the data interval of the collection
may actually include the beginning of another interval. Because of this
we have to iterate over the margin data and check for "good" entries. In
the case of a "good" entry being found, we have to continue extending the
last interval.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/libkshark-collection.c | 26 +++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)

Comments

Steven Rostedt Oct. 2, 2018, 9:18 p.m. UTC | #1
On Mon,  1 Oct 2018 16:59:21 +0300
Yordan Karadzhov <ykaradzhov@vmware.com> wrote:

> The margin data added at the end of the data interval of the collection
> may actually include the beginning of another interval. Because of this
> we have to iterate over the margin data and check for "good" entries. In
> the case of a "good" entry being found, we have to continue extending the
> last interval.
> 
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>  kernel-shark-qt/src/libkshark-collection.c | 26 +++++++++++++++-------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/kernel-shark-qt/src/libkshark-collection.c b/kernel-shark-qt/src/libkshark-collection.c
> index 79b6fff..c01eb59 100644
> --- a/kernel-shark-qt/src/libkshark-collection.c
> +++ b/kernel-shark-qt/src/libkshark-collection.c
> @@ -157,14 +157,24 @@ kshark_data_collection_alloc(struct kshark_context *kshark_ctx,
>  			 * number of margin entries requested, keep adding
>  			 * until you fill the margin.
>  			 */
> -			if (i + margin < j)
> -				i = j;
> -			else
> -				i += margin;
> -
> -			last_added = i;
> -			collection_add_entry(&temp, i, COLLECTION_BREAK);
> -			++break_count;
> +			if (i + margin >= j) {
> +				for (;j < i + margin; ++j) {
> +					if (cond(kshark_ctx, data[j], val)) {
> +						/* Good data has been found.

Nit, but have comments of the format:

						/*
						 * Good data has been found
> +						 * Continue extending the
> +						 * previous data interval.
> +						 */

Note, the Networking folks like the way you did it here, but the rest
of the Linux maintainers find it funny ;-)

-- Steve

> +						good_data = true;
> +						break;
> +					}
> +				}
> +			}
> +
> +			last_added = i = j;
> +			if (!good_data) {
> +				collection_add_entry(&temp, i, COLLECTION_BREAK);
> +				++break_count;
> +			}
>  		}
>  	}
>
diff mbox series

Patch

diff --git a/kernel-shark-qt/src/libkshark-collection.c b/kernel-shark-qt/src/libkshark-collection.c
index 79b6fff..c01eb59 100644
--- a/kernel-shark-qt/src/libkshark-collection.c
+++ b/kernel-shark-qt/src/libkshark-collection.c
@@ -157,14 +157,24 @@  kshark_data_collection_alloc(struct kshark_context *kshark_ctx,
 			 * number of margin entries requested, keep adding
 			 * until you fill the margin.
 			 */
-			if (i + margin < j)
-				i = j;
-			else
-				i += margin;
-
-			last_added = i;
-			collection_add_entry(&temp, i, COLLECTION_BREAK);
-			++break_count;
+			if (i + margin >= j) {
+				for (;j < i + margin; ++j) {
+					if (cond(kshark_ctx, data[j], val)) {
+						/* Good data has been found.
+						 * Continue extending the
+						 * previous data interval.
+						 */
+						good_data = true;
+						break;
+					}
+				}
+			}
+
+			last_added = i = j;
+			if (!good_data) {
+				collection_add_entry(&temp, i, COLLECTION_BREAK);
+				++break_count;
+			}
 		}
 	}