Skip to contentSkip to conversation

kernel-shark-qt: Deal with the "no tasks" case in kshark_get_task_pids()

PATCH Applied Yordan Karadzhov (VMware) 2 participants 9 messages Jul 11, 2018 – Aug 3, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kernel-shark-qt: Deal with the "no tasks" case in kshark_get_task_pids()

kshark_get_task_pids() should not return a "memory allocation" error in the case when it is called before having trace data loaded.

---
 kernel-shark-qt/src/libkshark.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel-shark-qt/src/libkshark.c +6 -0
index 668b6df..75b88c9 100644
@@ -303,6 +303,12 @@ ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
 		}
 	}
 
+	if (!pid_count) {
+		free(*pids);
+		*pids = NULL;
+		return pid_count;
+	}
+
 	temp_pids = realloc(*pids, pid_count * sizeof(int));
 	if (!temp_pids)
 		goto fail;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 kernel-shark-qt: Fix the default value of the Event Visible flag

This patch fixes a simpel bug in the way the "Event Visible" flag of the kshark_entries is set when the data is loadded.

---
 kernel-shark-qt/src/libkshark.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark-qt/src/libkshark.c +1 -1
index 75b88c9..3299752 100644
@@ -600,7 +600,7 @@ static size_t get_records(struct kshark_context *kshark_ctx,
 				kshark_set_entry_values(kshark_ctx, rec, entry);
 				pid = entry->pid;
 				/* Apply event filtering. */
-				ret = FILTER_NONE;
+				ret = FILTER_MATCH;
 				if (adv_filter->filters)
 					ret = pevent_filter_match(adv_filter, rec);
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 2/2] kernel-shark-qt: Fix the default value of the Event Visible flag

Quoted 5 lines · On Wed, 11 Jul 2018 16:37:09 +0300 "Yordan Karadzhov (VMware)"…

This patch fixes a simpel bug in the way the "Event Visible" flag of the kshark_entries is set when the data is loadded.

---

Applied. Thanks Yordan!

-- Steve

#3 lore raw
In reply to Yordan Karadzhov (VMware)
Quoted 15 lines · On Wed, 11 Jul 2018 16:37:08 +0300 "Yordan Karadzhov (VMware)"…

kshark_get_task_pids() should not return a "memory allocation" error in the case when it is called before having trace data loaded.

---
 kernel-shark-qt/src/libkshark.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel-shark-qt/src/libkshark.c +0 -0
index 668b6df..75b88c9 100644
@@ -303,6 +303,12 @@ ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
 		}
 	}

kernel-shark-qt/src/libkshark.c ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids) · line 314

Quoted 10 lines
kernel-shark-qt/src/libkshark.c +6 -0
 
+	if (!pid_count) {
+		free(*pids);
+		*pids = NULL;
+		return pid_count;
+	}
+
 	temp_pids = realloc(*pids, pid_count * sizeof(int));
 	if (!temp_pids)
 		goto fail;

What about doing it this way:

kernel-shark-qt/src/libkshark.c +10 -5
index 668b6df8..34daa25e 100644
@@ -303,12 +303,17 @@ ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
 		}
 	}
 
-	temp_pids = realloc(*pids, pid_count * sizeof(int));
-	if (!temp_pids)
-		goto fail;
+	if (pid_count) {
+		temp_pids = realloc(*pids, pid_count * sizeof(int));
+		if (!temp_pids)
+			goto fail;
 
-	/* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */
-	*pids = temp_pids;
+		/* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */
+		*pids = temp_pids;
+	} else {
+		free(*pids);
+		*pids = NULL;
+	}
 
 	return pid_count;
 

?

-- Steve

#4 lore raw
Quoted 48 lines · Steven Rostedt
Quoted 15 lines · On Wed, 11 Jul 2018 16:37:08 +0300 "Yordan Karadzhov (VMware)"…

kshark_get_task_pids() should not return a "memory allocation" error in the case when it is called before having trace data loaded.

---
  kernel-shark-qt/src/libkshark.c | 6 ++++++
  1 file changed, 6 insertions(+)
kernel-shark-qt/src/libkshark.c +0 -0
index 668b6df..75b88c9 100644
@@ -303,6 +303,12 @@ ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
  		}
  	}

kernel-shark-qt/src/libkshark.c ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids) · line 314

Quoted 10 lines
kernel-shark-qt/src/libkshark.c +6 -0
 
+	if (!pid_count) {
+		free(*pids);
+		*pids = NULL;
+		return pid_count;
+	}
+
  	temp_pids = realloc(*pids, pid_count * sizeof(int));
  	if (!temp_pids)
  		goto fail;

What about doing it this way:

kernel-shark-qt/src/libkshark.c +4 -4
index 668b6df8..34daa25e 100644
@@ -303,12 +303,17 @@ ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids)
  		}
  	}
 
-	temp_pids = realloc(*pids, pid_count * sizeof(int));
-	if (!temp_pids)
-		goto fail;
+	if (pid_count) {
+		temp_pids = realloc(*pids, pid_count * sizeof(int));
+		if (!temp_pids)
+			goto fail;
 
-	/* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */

kernel-shark-qt/src/libkshark.c ssize_t kshark_get_task_pids(struct kshark_context *kshark_ctx, int **pids) · line 319

Quoted 10 lines
kernel-shark-qt/src/libkshark.c +6 -1
-	*pids = temp_pids;
+		/* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */
+		*pids = temp_pids;
+	} else {
+		free(*pids);
+		*pids = NULL;
+	}
 
  	return pid_count;
 

Yes, this way is better.

Thanks!
Yordan

Quoted 5 lines

?

-- Steve

#5 lore raw

Hi Steven,
Should I send this patch again?

Thanks!
Yordan

Quoted 40 lines · Yordan Karadzhov (VMware)
Quoted 21 lines

What about doing it this way:

kernel-shark-qt/src/libkshark.c +4 -4
index 668b6df8..34daa25e 100644
@@ -303,12 +303,17 @@ ssize_t kshark_get_task_pids(struct 
 kshark_context *kshark_ctx, int **pids)
           }
       }
-    temp_pids = realloc(*pids, pid_count * sizeof(int));
-    if (!temp_pids)
-        goto fail;
+    if (pid_count) {
+        temp_pids = realloc(*pids, pid_count * sizeof(int));
+        if (!temp_pids)
+            goto fail;
-    /* Paranoid: In the unlikely case of shrinking *pids, realloc 

moves it */
-    *pids = temp_pids;

Quoted 8 lines

+        /* Paranoid: In the unlikely case of shrinking *pids, realloc moves it */
+        *pids = temp_pids;
+    } else {
+        free(*pids);
+        *pids = NULL;
+    }
      return pid_count;

Yes, this way is better.

Thanks!
Yordan

Quoted 4 lines

?

-- Steve

#6 lore raw
Quoted 2 lines · On Fri, 3 Aug 2018 16:06:24 +0300 "Yordan Karadzhov (VMware)"…

Hi Steven,
Should I send this patch again?

Yes, with the updates.

Thanks!

-- Steve

#7 lore raw
Quoted 8 lines · On Fri, 3 Aug 2018 13:46:22 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 2 lines · On Fri, 3 Aug 2018 16:06:24 +0300 "Yordan Karadzhov (VMware)"…

Hi Steven,
Should I send this patch again?

Yes, with the updates.

I take this back. I'll do the updates and apply your other patches on top.

Thanks!

-- Steve

#8 lore raw
Quoted 6 lines · On Fri, 3 Aug 2018 14:18:27 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Fri, 3 Aug 2018 13:46:22 -0400 Steven Rostedt <[email protected]> wrote:

On Fri, 3 Aug 2018 16:06:24 +0300
"Yordan Karadzhov (VMware)" <[email protected]> wrote:

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Hi Steven,
Should I send this patch again?

Yes, with the updates.

I take this back. I'll do the updates and apply your other patches on top.

And this is what I get when I work on too many projects at once. I already have the update applied to my local tree :-p.

-- Steve