Skip to contentSkip to conversation

Various minor modifications and fixes toward KS 1.0

PATCH In review Yordan Karadzhov 4 participants 14 messages Mar 7, 2019 – Mar 26, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover Various minor modifications and fixes toward KS 1.0

Please ignor the prevoius version of this patch set. In particular patch [2/4] which has a sintax error.

I am sorry for the SPAM!
Yordan

Yordan Karadzhov (4):
kernel-shark: Specify the OpenGL interface used by KernelShark
kernel-shark: Fix a bug in ksmodel_zoom
kernel-shark: Fix Doxygen warning from sched_events
kernel-shark: Fix a bug in KsPluginManager

 kernel-shark/CMakeLists.txt             | 1 +
 kernel-shark/src/KsUtils.cpp            | 4 ++--
 kernel-shark/src/libkshark-model.c      | 4 ++--
 kernel-shark/src/plugins/sched_events.c | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH v2 1/4 kernel-shark: Specify the OpenGL interface used by KernelShark

We instruct CMAKE to prefer using the legacy libGL library, if available. Although this is the default choice, the latest versions of CMAKE are printing a warning message in the case when no explicit preference is provided.

---
 kernel-shark/CMakeLists.txt | 1 +
 1 file changed, 1 insertion(+)
kernel-shark/CMakeLists.txt +1 -0
index 9460026..20ced14 100644
@@ -22,6 +22,7 @@ include(${KS_DIR}/build/FindJSONC.cmake)
 
 find_package(Doxygen)
 
+set(OpenGL_GL_PREFERENCE LEGACY)
 find_package(OpenGL)
 find_package(GLUT)
 
Signature · 1 line
2.19.1
#2 lore raw

PATCH v2 2/4 kernel-shark: Fix a bug in ksmodel_zoom

In reply to Yordan Karadzhov

When zooming-in the model is supposed to avoid over-zooming by recalculation the Scale factor. The new value of the Scale factor is supposed to be such that the size of the bin cannot be smaller than 5 ns. This patch fixes a naive bug in the way the new scale value is calculated. The bug was introduced in

f97e31f00 ("kernel-shark-qt: Introduce the visualization model used by the Qt-based KS")

but had no effect until

94efea960 ("kernel-shark-qt: Handle the case when the range of the model is too small")

because the ridiculous value of the Scale factor resulted in a very small model range and because of this the modification of the model was always rejected.

Fixes f97e31f00 ("kernel-shark-qt: Introduce the visualization model used by the Qt-based KS")
---
 kernel-shark/src/libkshark-model.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/src/libkshark-model.c +2 -2
index 4bd1e2c..af3440b 100644
@@ -648,8 +648,8 @@ static void ksmodel_zoom(struct kshark_trace_histo *histo,
 	 * Avoid overzooming. If needed, adjust the Scale factor to a the value
 	 * which provides bin_size >= 5.
 	 */
-	if (zoom_in && range * (1 - r) < histo->n_bins * 5)
-		r = 1 - (histo->n_bins * 5) / range;
+	if (zoom_in && (int) range * (1. - r) < histo->n_bins * 5)
+		r = 1. - (histo->n_bins * 5.) / range;
 
 	/*
 	 * Now calculate the new range of the histo. Use the bin of the marker
Signature · 1 line
2.19.1
#3 lore raw

Re: [PATCH v2 2/4] kernel-shark: Fix a bug in ksmodel_zoom

Quoted 5 lines · On Thu, 7 Mar 2019 17:43:14 +0200 Yordan Karadzhov <[email protected]>…

When zooming-in the model is supposed to avoid over-zooming by recalculation the Scale factor. The new value of the Scale factor is supposed to be such that the size of the bin cannot be smaller than 5 ns. This patch fixes a naive bug in the way the new scale value is calculated.

BTW, what if the resolution of time stamps isn't in ns, and we can have more than one event in a 5 unit bin. Does that mean we never display multiple events in that small of a time scale?

-- Steve

#4 lore raw

Re: [PATCH v2 2/4] kernel-shark: Fix a bug in ksmodel_zoom

Quoted 9 lines · Steven Rostedt
Quoted 5 lines · On Thu, 7 Mar 2019 17:43:14 +0200 Yordan Karadzhov <[email protected]>…

When zooming-in the model is supposed to avoid over-zooming by recalculation the Scale factor. The new value of the Scale factor is supposed to be such that the size of the bin cannot be smaller than 5 ns. This patch fixes a naive bug in the way the new scale value is calculated.

Quoted 3 lines

BTW, what if the resolution of time stamps isn't in ns, and we can have more than one event in a 5 unit bin. Does that mean we never display multiple events in that small of a time scale?

For the moment Yes.
We have to make this value (5 units /ns) a parameter that can be configured.

Yordan

Quoted 3 lines

-- Steve

#5 lore raw

PATCH v2 3/4 kernel-shark: Fix Doxygen warning from sched_events

In reply to Yordan Karadzhov

There is no reason for find_wakeup_pid being non-static. In the same time, because it is non-static, Doxygen complains about missing documentation for this function.

---
 kernel-shark/src/plugins/sched_events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark/src/plugins/sched_events.c +1 -1
index c52fb29..724aa19 100644
@@ -148,7 +148,7 @@ static void plugin_register_command(struct kshark_context *kshark_ctx,
 			tep_register_comm(kshark_ctx->pevent, comm, pid);
 }
 
-int find_wakeup_pid(struct kshark_context *kshark_ctx, struct kshark_entry *e,
+static int find_wakeup_pid(struct kshark_context *kshark_ctx, struct kshark_entry *e,
 		    struct tep_event *wakeup_event, struct tep_format_field *pid_field)
 {
 	struct tep_record *record;
Signature · 1 line
2.19.1
#6 lore raw

PATCH v2 4/4 kernel-shark: Fix a bug in KsPluginManager

In reply to Yordan Karadzhov

const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be invalidated when the destructor of std::string is called.

---
 kernel-shark/src/KsUtils.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/src/KsUtils.cpp +2 -2
index 34b2e2d..d7b1753 100644
@@ -439,7 +439,7 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 
 	auto lamRegUser = [&kshark_ctx](const QString &plugin)
 	{
-		const char *lib = plugin.toStdString().c_str();
+		const char *lib = plugin.toLocal8Bit().data();
 		kshark_register_plugin(kshark_ctx, lib);
 	};
 
@@ -474,7 +474,7 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 
 	auto lamUregUser = [&kshark_ctx](const QString &plugin)
 	{
-		const char *lib = plugin.toStdString().c_str();
+		const char *lib = plugin.toLocal8Bit().data();
 		kshark_unregister_plugin(kshark_ctx, lib);
 	};
 
Signature · 1 line
2.19.1
#7 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 25 lines · Yordan Karadzhov

const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be invalidated when the destructor of std::string is called.

---
 kernel-shark/src/KsUtils.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/src/KsUtils.cpp +1 -1
index 34b2e2d..d7b1753 100644
@@ -439,7 +439,7 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 
        auto lamRegUser = [&kshark_ctx](const QString &plugin)
        {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                kshark_register_plugin(kshark_ctx, lib);
        };
 

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) · line 479

Quoted 7 lines
kernel-shark/src/KsUtils.cpp +1 -1
@@ -474,7 +474,7 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 
        auto lamUregUser = [&kshark_ctx](const QString &plugin)
        {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                kshark_unregister_plugin(kshark_ctx, lib);
        };

Doesn't the new version have the same problem with the temporary QByteArray?

How about saving the data in a local std::string/QByteArray variable?

               std::string lib = plugin.toStdString();
               kshark_register_plugin(kshark_ctx, lib.c_str());

Thanks!

--
Slavomir Kaslev

#8 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 36 lines · Slavomir Kaslev
Quoted 25 lines · Yordan Karadzhov

const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be invalidated when the destructor of std::string is called.

---
  kernel-shark/src/KsUtils.cpp | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/src/KsUtils.cpp +1 -1
index 34b2e2d..d7b1753 100644
@@ -439,7 +439,7 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 
         auto lamRegUser = [&kshark_ctx](const QString &plugin)
         {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                 kshark_register_plugin(kshark_ctx, lib);
         };
 

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) · line 479

Quoted 7 lines
kernel-shark/src/KsUtils.cpp +1 -1
@@ -474,7 +474,7 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 
         auto lamUregUser = [&kshark_ctx](const QString &plugin)
         {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                 kshark_unregister_plugin(kshark_ctx, lib);
         };

Doesn't the new version have the same problem with the temporary QByteArray?

Quoted 5 lines

How about saving the data in a local std::string/QByteArray variable?

                std::string lib = plugin.toStdString();
                kshark_register_plugin(kshark_ctx, lib.c_str());

Hi Slavi,

As far I can understand toStdString() will create a fresh std::string and this string will has its own copy of the characters. However, this copy gets out-of-scope as soon as we hit the semicolon of the line.

My understanding was that toLocal8Bit().data() makes no copy so the array will go out-of-scope only when the QString is destroyed.

But anyway, your solution looks cleaner and safer. I will send another version of the patch. Thanks a lot!
Y.

Quoted 6 lines

Thanks!

--
Slavomir Kaslev

#9 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 46 lines · Yordan Karadzhov (VMware)
Quoted 36 lines · Slavomir Kaslev
Quoted 25 lines · Yordan Karadzhov

const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be invalidated when the destructor of std::string is called.

---
  kernel-shark/src/KsUtils.cpp | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/src/KsUtils.cpp +1 -1
index 34b2e2d..d7b1753 100644
@@ -439,7 +439,7 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 
         auto lamRegUser = [&kshark_ctx](const QString &plugin)
         {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                 kshark_register_plugin(kshark_ctx, lib);
         };
 

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) · line 479

Quoted 7 lines
kernel-shark/src/KsUtils.cpp +1 -1
@@ -474,7 +474,7 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 
         auto lamUregUser = [&kshark_ctx](const QString &plugin)
         {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                 kshark_unregister_plugin(kshark_ctx, lib);
         };

Doesn't the new version have the same problem with the temporary QByteArray?

Quoted 5 lines

How about saving the data in a local std::string/QByteArray variable?

                std::string lib = plugin.toStdString();
                kshark_register_plugin(kshark_ctx, lib.c_str());
Quoted 8 lines

Hi Slavi,

As far I can understand toStdString() will create a fresh std::string and this string will has its own copy of the characters. However, this copy gets out-of-scope as soon as we hit the semicolon of the line.

My understanding was that toLocal8Bit().data() makes no copy so the array will go out-of-scope only when the QString is destroyed.

I did some digging into QString's implementation. From my reading of the code, toLocal8Bit() calls into qt_convert_to_latin1()[1] which does allocation, copying/transform-to-latin1 and returns the QByteArray. So it seems that toLocal8Bit() is still making a copy.

[1] https://github.com/qt/qtbase/blob/5.12/src/corelib/tools/qstring.cpp#L5275

Cheers,

-- Slavi

Quoted 13 lines

But anyway, your solution looks cleaner and safer. I will send another version of the patch. Thanks a lot!
Y.

Quoted 6 lines

Thanks!

--
Slavomir Kaslev

Signature · 1 line
Slavomir Kaslev
#10 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 57 lines · Slavomir Kaslev
Quoted 46 lines · Yordan Karadzhov (VMware)
Quoted 36 lines · Slavomir Kaslev
Quoted 25 lines · Yordan Karadzhov

const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be invalidated when the destructor of std::string is called.

---
   kernel-shark/src/KsUtils.cpp | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shark/src/KsUtils.cpp +1 -1
index 34b2e2d..d7b1753 100644
@@ -439,7 +439,7 @@ void KsPluginManager::registerFromList(kshark_context *kshark_ctx)
 
          auto lamRegUser = [&kshark_ctx](const QString &plugin)
          {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                  kshark_register_plugin(kshark_ctx, lib);
          };
 

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) · line 479

Quoted 7 lines
kernel-shark/src/KsUtils.cpp +1 -1
@@ -474,7 +474,7 @@ void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)
 
          auto lamUregUser = [&kshark_ctx](const QString &plugin)
          {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                  kshark_unregister_plugin(kshark_ctx, lib);
          };

Doesn't the new version have the same problem with the temporary QByteArray?

Quoted 5 lines

How about saving the data in a local std::string/QByteArray variable?

                 std::string lib = plugin.toStdString();
                 kshark_register_plugin(kshark_ctx, lib.c_str());
Quoted 8 lines

Hi Slavi,

As far I can understand toStdString() will create a fresh std::string and this string will has its own copy of the characters. However, this copy gets out-of-scope as soon as we hit the semicolon of the line.

My understanding was that toLocal8Bit().data() makes no copy so the array will go out-of-scope only when the QString is destroyed.

Quoted 9 lines

I did some digging into QString's implementation. From my reading of the code, toLocal8Bit() calls into qt_convert_to_latin1()[1] which does allocation, copying/transform-to-latin1 and returns the QByteArray. So it seems that toLocal8Bit() is still making a copy.

[1] https://github.com/qt/qtbase/blob/5.12/src/corelib/tools/qstring.cpp#L5275

Cheers,

Thanks a lot for investigating this!
I think in this case it will be more appropriate if you sign the patch. cheers,
Y.

Quoted 18 lines

-- Slavi

Quoted 13 lines

But anyway, your solution looks cleaner and safer. I will send another version of the patch. Thanks a lot!
Y.

Quoted 6 lines

Thanks!

--
Slavomir Kaslev

#11 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 76 lines · Yordan Karadzhov (VMware)
Quoted 7 lines · Slavomir Kaslev
Quoted 5 lines · Yordan Karadzhov (VMware)
Quoted 1 line · Slavomir Kaslev

On Thu, Mar 7, 2019 at 5:44 PM Yordan Karadzhov

Quoted 6 lines · <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

const char *lib = plugin.toStdString().c_str();

This line is a bad idea because the returned array may (will) be invalidated when the destructor of std::string is called.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
---
   kernel-shark/src/KsUtils.cpp | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/kernel-shark/src/KsUtils.cpp

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

kernel-shark/src/KsUtils.cpp void

Quoted 4 lines

index 34b2e2d..d7b1753 100644

kernel-shark/src/KsUtils.cpp +0 -0
@@ -439,7 +439,7 @@ void

KsPluginManager::registerFromList(kshark_context *kshark_ctx)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

kernel-shark/src/KsUtils.cpp void

Quoted 9 lines
kernel-shark/src/KsUtils.cpp +1 -1
          auto lamRegUser = [&kshark_ctx](const QString &plugin)
          {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                  kshark_register_plugin(kshark_ctx, lib);
          };
 
@@ -474,7 +474,7 @@ void

KsPluginManager::unregisterFromList(kshark_context *kshark_ctx)

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

kernel-shark/src/KsUtils.cpp void KsPluginManager::unregisterFromList(kshark_context *kshark_ctx) · line 479

Quoted 7 lines
kernel-shark/src/KsUtils.cpp +1 -1
          auto lamUregUser = [&kshark_ctx](const QString &plugin)
          {
-               const char *lib = plugin.toStdString().c_str();
+               const char *lib = plugin.toLocal8Bit().data();
                  kshark_unregister_plugin(kshark_ctx, lib);
          };

Doesn't the new version have the same problem with the temporary

QByteArray?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

How about saving the data in a local std::string/QByteArray

variable?

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
                 std::string lib = plugin.toStdString();
                 kshark_register_plugin(kshark_ctx, lib.c_str());

Hi Slavi,

As far I can understand toStdString() will create a fresh

std::string

Quoted 1 line
Quoted 1 line

and this string will has its own copy of the characters. However,

this

Quoted 11 lines
Quoted 4 lines

copy gets out-of-scope as soon as we hit the semicolon of the line.

My understanding was that toLocal8Bit().data() makes no copy so the array will go out-of-scope only when the QString is destroyed.

I did some digging into QString's implementation. From my reading of the code, toLocal8Bit() calls into qt_convert_to_latin1()[1] which does allocation, copying/transform-to-latin1 and returns the QByteArray. So it seems that toLocal8Bit() is still making a copy.

[1]

https://github.com/qt/qtbase/blob/5.12/src/corelib/tools/qstring.cpp#L5275

Quoted 1 line
Quoted 14 lines
Quoted 2 lines

Cheers,

Thanks a lot for investigating this!
I think in this case it will be more appropriate if you sign the patch. cheers,
Y.

Quoted 6 lines

-- Slavi

Quoted 4 lines

But anyway, your solution looks cleaner and safer. I will send another version of the patch. Thanks a lot!

Signing the patch means that the person either wrote the patch or handled it to be committed.

I think you want Suggested-by:

-- Steve

Quoted 12 lines
Quoted 12 lines
Quoted 9 lines

Y.

Quoted 6 lines

Thanks!

--
Slavomir Kaslev

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity and top posting.
#12 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 8 lines · On Mon, 11 Mar 2019 11:15:40 -0700 Steven Rostedt <[email protected]> wrote:
Quoted 8 lines

Thanks a lot for investigating this!
I think in this case it will be more appropriate if you sign the patch. cheers,
Y.

Quoted 3 lines

-- Slavi

Quoted 1 line
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

But anyway, your solution looks cleaner and safer. I will send another version of the patch. Thanks a lot!

Signing the patch means that the person either wrote the patch or handled it to be committed.

I think you want Suggested-by:

BTW, I'm confused. Does this patch need to be applied or was there another version coming?

-- Steve

#13 lore raw

Re: [PATCH v2 4/4] kernel-shark: Fix a bug in KsPluginManager

Quoted 16 lines · Steven Rostedt
Quoted 13 lines · On Mon, 11 Mar 2019 11:15:40 -0700 Steven Rostedt <[email protected]> wrote:
Quoted 11 lines

Thanks a lot for investigating this!
I think in this case it will be more appropriate if you sign the patch. cheers,
Y.

Quoted 6 lines

-- Slavi

Quoted 4 lines

But anyway, your solution looks cleaner and safer. I will send another version of the patch. Thanks a lot!

Quoted 7 lines
Quoted 4 lines

Signing the patch means that the person either wrote the patch or handled it to be committed.

I think you want Suggested-by:

BTW, I'm confused. Does this patch need to be applied or was there another version coming?

It is my fault. Looks like I forgot to send v3.
The patch is coming.
Thanks!
Y.

Quoted 2 lines

-- Steve