diff mbox series

[1/4] kernel-shark: Configuration information in ${HOME}/.cache/kernelshark

Message ID 20190404145603.13592-2-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series Various modifications and fixes toward KS 1.0 | expand

Commit Message

Yordan Karadzhov April 4, 2019, 2:56 p.m. UTC
By default the "Last session" configuration file will be saved in
${HOME}/.cache/kernelshark

After applying this patch you may need to clean the CMAKE cache.
This can be done by:

    cd kernel-shark/build/;./cmake_clean.sh; cd -
    make gui

Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 Makefile                          |  5 ++++-
 kernel-shark/CMakeLists.txt       | 13 ++++++++-----
 kernel-shark/README               |  8 +++++++-
 kernel-shark/build/deff.h.cmake   |  4 ++--
 kernel-shark/src/KsMainWindow.cpp |  4 ++--
 5 files changed, 23 insertions(+), 11 deletions(-)

Comments

Slavomir Kaslev April 8, 2019, 3:01 p.m. UTC | #1
On Thu, Apr 04, 2019 at 05:56:00PM +0300, Yordan Karadzhov wrote:
> By default the "Last session" configuration file will be saved in
> ${HOME}/.cache/kernelshark
> 
> After applying this patch you may need to clean the CMAKE cache.
> This can be done by:
> 
>     cd kernel-shark/build/;./cmake_clean.sh; cd -
>     make gui
> 
> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>  Makefile                          |  5 ++++-
>  kernel-shark/CMakeLists.txt       | 13 ++++++++-----
>  kernel-shark/README               |  8 +++++++-
>  kernel-shark/build/deff.h.cmake   |  4 ++--
>  kernel-shark/src/KsMainWindow.cpp |  4 ++--
>  5 files changed, 23 insertions(+), 11 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index cde45f8..d9b0c0e 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -254,7 +254,10 @@ all_cmd: $(CMD_TARGETS)
>  CMAKE_COMMAND = /usr/bin/cmake
>  
>  $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
> -	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) -D_INSTALL_PREFIX=$(prefix) ..
> +
> +	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) \
> +		-D_KS_CACHE_DIR=$(HOME)/.cache/kernelshark \
                                ^
Which $HOME would that be? The one for the user who built kernelshark and not the user who runs it.


> +		-D_INSTALL_PREFIX=$(prefix) ..
>  
>  gui: force $(CMD_TARGETS) $(kshark-dir)/build/Makefile
>  	$(Q)$(MAKE) $(S) -C $(kshark-dir)/build
> diff --git a/kernel-shark/CMakeLists.txt b/kernel-shark/CMakeLists.txt
> index 8858eb7..14d73f5 100644
> --- a/kernel-shark/CMakeLists.txt
> +++ b/kernel-shark/CMakeLists.txt
> @@ -12,10 +12,12 @@ message("\n project: Kernel Shark: (version: ${KS_VERSION_STRING})\n")
>  
>  set(KS_DIR ${CMAKE_SOURCE_DIR})
>  
> -# Make a directory to hold configuration files. To change this do:
> -# cmake .. -DKS_CONF_DIR=/your/preferred/path
> -set(KS_CONF_DIR "${KS_DIR}/.ksconf" CACHE STRING "Directory for configuration files.")
> -file(MAKE_DIRECTORY ${KS_CONF_DIR})
> +# Make a directory to hold cached configuration files. To change this do:
> +# cmake .. -D_KS_CACHE_DIR=/your/preferred/path
> +set(_KS_CACHE_DIR "$ENV{HOME}/.cache/kernelshark"
> +    CACHE STRING "Directory for cached configuration files.")
> +
> +file(MAKE_DIRECTORY ${_KS_CACHE_DIR})
>  
>  include(${KS_DIR}/build/FindTraceCmd.cmake)
>  include(${KS_DIR}/build/FindJSONC.cmake)
> @@ -66,7 +68,8 @@ include_directories(${KS_DIR}/src/
>  message("")
>  message(STATUS "C flags      : " ${CMAKE_C_FLAGS})
>  message(STATUS "CXX flags    : " ${CMAKE_CXX_FLAGS})
> -message(STATUS "Linker flags : " ${CMAKE_EXE_LINKER_FLAGS})
> +message(STATUS "Linker flags : " ${CMAKE_EXE_LINKER_FLAGS}\n)
> +message(STATUS "config. files saved in ${_KS_CACHE_DIR}")
>  
>  add_subdirectory(${KS_DIR}/src)
>  add_subdirectory(${KS_DIR}/examples)
> diff --git a/kernel-shark/README b/kernel-shark/README
> index 9f7db26..a75b08b 100644
> --- a/kernel-shark/README
> +++ b/kernel-shark/README
> @@ -52,8 +52,14 @@ as a CMake Command-Line option.
>  2.1.3 By default, installation prefix is "/usr/local". It can be changed using
>  -D_INSTALL_PREFIX= as a CMake Command-Line option.
>  
> -Example:
> +2.1.4 By default, the directory that holds cached configuration files is
> +${HOME}/.cache/kernelshark/ .It can be changed using -D_KS_CACHE_DIR=
> +as a CMake Command-Line option. Use only absolute paths for this option.
> +
> +
> +Examples:
>      cmake -D_DOXYGEN_DOC=1 -D_DEBUG=1 -D_INSTALL_PREFIX=/usr ../
> +    cmake -D_KS_CACHE_DIR=${PWD}../.kscache ../
>  
>  2.2.1 Use "make clean" if you want to delete all already compiled objects.
>  
> diff --git a/kernel-shark/build/deff.h.cmake b/kernel-shark/build/deff.h.cmake
> index 80d624c..f1f6a35 100644
> --- a/kernel-shark/build/deff.h.cmake
> +++ b/kernel-shark/build/deff.h.cmake
> @@ -14,8 +14,8 @@
>  /** KernelShark source code path. */
>  #cmakedefine KS_DIR "@KS_DIR@"
>  
> -/** KernelShark configuration directory path. */
> -#cmakedefine KS_CONF_DIR "@KS_CONF_DIR@"
> +/** KernelShark cache directory path. */
> +#cmakedefine _KS_CACHE_DIR "@_KS_CACHE_DIR@"
>  
>  /** Location of the trace-cmd executable. */
>  #cmakedefine TRACECMD_BIN_DIR "@TRACECMD_BIN_DIR@"
> diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
> index 7afb721..d07a89d 100644
> --- a/kernel-shark/src/KsMainWindow.cpp
> +++ b/kernel-shark/src/KsMainWindow.cpp
> @@ -133,7 +133,7 @@ KsMainWindow::KsMainWindow(QWidget *parent)
>  KsMainWindow::~KsMainWindow()
>  {
>  	kshark_context *kshark_ctx(nullptr);
> -	QString file = KS_CONF_DIR;
> +	QString file = _KS_CACHE_DIR;
>  
>  	file += "/lastsession.json";
>  
> @@ -370,7 +370,7 @@ void KsMainWindow::_open()
>  
>  void KsMainWindow::_restoreSession()
>  {
> -	QString file = KS_CONF_DIR;
> +	QString file = _KS_CACHE_DIR;
>  	file += "/lastsession.json";
>  
>  	loadSession(file);
> -- 
> 2.19.1
>
Steven Rostedt April 8, 2019, 3:13 p.m. UTC | #2
On Mon, 8 Apr 2019 18:01:03 +0300
Slavomir Kaslev <kaslevs@vmware.com> wrote:

> > +++ b/Makefile
> > @@ -254,7 +254,10 @@ all_cmd: $(CMD_TARGETS)
> >  CMAKE_COMMAND = /usr/bin/cmake
> >  
> >  $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
> > -	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) -D_INSTALL_PREFIX=$(prefix) ..
> > +
> > +	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) \
> > +		-D_KS_CACHE_DIR=$(HOME)/.cache/kernelshark \  
>                                 ^
> Which $HOME would that be? The one for the user who built kernelshark and not the user who runs it.
> 
> 
> > +		-D_INSTALL_PREFIX=$(prefix) ..

Correct, this needs to be the HOME from the run time environment. Which
is taken as the third parameter from main!

#include <stdio.h>
#include <string.h>
int main(int argc, char **argv, **envp)
{
	int i;
	for (i = 0; env[i]; i++) {
		if (strncmp(env[i], "HOME=", 5) == 0)
			printf("home is %s\n", env[i] + 5);
	}
	return 0;
}


-- Steve
Yordan Karadzhov April 9, 2019, 12:23 p.m. UTC | #3
On 8.04.19 г. 18:13 ч., Steven Rostedt wrote:
> On Mon, 8 Apr 2019 18:01:03 +0300
> Slavomir Kaslev <kaslevs@vmware.com> wrote:
> 
>>> +++ b/Makefile
>>> @@ -254,7 +254,10 @@ all_cmd: $(CMD_TARGETS)
>>>   CMAKE_COMMAND = /usr/bin/cmake
>>>   
>>>   $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
>>> -	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) -D_INSTALL_PREFIX=$(prefix) ..
>>> +
>>> +	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) \
>>> +		-D_KS_CACHE_DIR=$(HOME)/.cache/kernelshark \
>>                                  ^
>> Which $HOME would that be? The one for the user who built kernelshark and not the user who runs it.
>>
>>

As it is right now Cmake will get the value of the -D_KS_CACHE_DIR 
argument and will tell the GUI to save cache files there. And yes, in 
this case it will be in the $HOME of the user who built kernelshark.

I can make the GUI to check if _KS_CACHE_DIR is defined and if its value 
(path) belongs to the user who runs the GUI. If this is not the case, 
The GUI will use the default location (~/cache/kernelshark).

Is this OK?

Thanks!
Yordan



>>> +		-D_INSTALL_PREFIX=$(prefix) ..
> 
> Correct, this needs to be the HOME from the run time environment. Which
> is taken as the third parameter from main!
> 
> #include <stdio.h>
> #include <string.h>
> int main(int argc, char **argv, **envp)
> {
> 	int i;
> 	for (i = 0; env[i]; i++) {
> 		if (strncmp(env[i], "HOME=", 5) == 0)
> 			printf("home is %s\n", env[i] + 5);
> 	}
> 	return 0;
> }
> 
> 
> -- Steve
>
Slavomir Kaslev April 9, 2019, 1:11 p.m. UTC | #4
On Tue, 2019-04-09 at 15:23 +0300, Yordan Karadzhov (VMware) wrote:
> 
> On 8.04.19 г. 18:13 ч., Steven Rostedt wrote:
> > On Mon, 8 Apr 2019 18:01:03 +0300
> > Slavomir Kaslev <kaslevs@vmware.com> wrote:
> > 
> > > > +++ b/Makefile
> > > > @@ -254,7 +254,10 @@ all_cmd: $(CMD_TARGETS)
> > > >   CMAKE_COMMAND = /usr/bin/cmake
> > > >   
> > > >   $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
> > > > -	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND)
> > > > -D_INSTALL_PREFIX=$(prefix) ..
> > > > +
> > > > +	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) \
> > > > +		-D_KS_CACHE_DIR=$(HOME)/.cache/kernelshark \
> > >                                  ^
> > > Which $HOME would that be? The one for the user who built
> > > kernelshark and not the user who runs it.
> > > 
> > > 
> 
> As it is right now Cmake will get the value of the -D_KS_CACHE_DIR 
> argument and will tell the GUI to save cache files there. And yes,
> in 
> this case it will be in the $HOME of the user who built kernelshark.
> 
> I can make the GUI to check if _KS_CACHE_DIR is defined and if its
> value 
> (path) belongs to the user who runs the GUI. If this is not the
> case, 
> The GUI will use the default location (~/cache/kernelshark).

This will work but it doesn't solve the actual problem. The actual
problem is that KS_CACHE_DIR must be expanded run time, not compile
time. Otherwise, there is no sensible value one can set to KS_CACHE_DIR
build time that works for all users (unless it's shared, say
/var/tmp/kernelshark).

One alternative is to do this in the above Makefile:

	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) \
		-D_KS_CACHE_DIR='$HOME/.cache/kernelshark'

to force shell not to expand variables and then use wordexp(3) or
similar to do the expansion run time.

Another alternative is to change the semantics of KS_CACHE_DIR so that
if it's relative path (.cache/kernelshark) it's always rooted at the
user's $HOME. OTOH that behavior might not be what some users expect.

Cheers,

-- Slavi
Steven Rostedt April 9, 2019, 1:23 p.m. UTC | #5
On Tue, 9 Apr 2019 15:23:56 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> I can make the GUI to check if _KS_CACHE_DIR is defined and if its value 
> (path) belongs to the user who runs the GUI. If this is not the case, 
> The GUI will use the default location (~/cache/kernelshark).

Can't we just make it so that it always does this path?

-- Steve
Yordan Karadzhov April 9, 2019, 1:33 p.m. UTC | #6
On 9.04.19 г. 16:23 ч., Steven Rostedt wrote:
> On Tue, 9 Apr 2019 15:23:56 +0300
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
> 
>> I can make the GUI to check if _KS_CACHE_DIR is defined and if its value
>> (path) belongs to the user who runs the GUI. If this is not the case,
>> The GUI will use the default location (~/cache/kernelshark).
> 
> Can't we just make it so that it always does this path?

This will be a great simplification :-)
Yes, we can.

Thanks!
Yordan


> 
> -- Steve
>
Slavomir Kaslev April 9, 2019, 2:59 p.m. UTC | #7
On Tue, Apr 9, 2019 at 4:24 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Tue, 9 Apr 2019 15:23:56 +0300
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
>
> > I can make the GUI to check if _KS_CACHE_DIR is defined and if its value
> > (path) belongs to the user who runs the GUI. If this is not the case,
> > The GUI will use the default location (~/cache/kernelshark).
>
> Can't we just make it so that it always does this path?

Dropping KS_CACHE_DIR as build time constant in CMake sounds great. I
think that having an environment variable override for it is still
useful.

We also have the same problem with KS_DIR and TRACECMD_BIN_DIR though.
They both point inside the trace-cmd source directory for the user who
built kernelshark atm.

Cheers,

-- Slavi
Steven Rostedt April 9, 2019, 3:11 p.m. UTC | #8
On Tue, 9 Apr 2019 14:59:54 +0000
Slavomir Kaslev <kaslevs@vmware.com> wrote:

> We also have the same problem with KS_DIR and TRACECMD_BIN_DIR though.
> They both point inside the trace-cmd source directory for the user who
> built kernelshark atm.

Hmm, these are a bit different. I'm not sure I want them to be user
run-time configurable, because they are executing system tools. That
could be a security concern.

But they should be compile time configurable, such that a distro can
define them.

-- Steve
Slavomir Kaslev April 9, 2019, 3:44 p.m. UTC | #9
On Tue, Apr 9, 2019 at 6:11 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Tue, 9 Apr 2019 14:59:54 +0000
> Slavomir Kaslev <kaslevs@vmware.com> wrote:
>
> > We also have the same problem with KS_DIR and TRACECMD_BIN_DIR though.
> > They both point inside the trace-cmd source directory for the user who
> > built kernelshark atm.
>
> Hmm, these are a bit different. I'm not sure I want them to be user
> run-time configurable, because they are executing system tools. That
> could be a security concern.
>
> But they should be compile time configurable, such that a distro can
> define them.

I agree, there's no need for those to have environment variable override.

The problem is the way they are defined atm:

# First search in the user provided paths.
find_path(TRACECMD_BIN_DIR      NAMES  trace-cmd
                                PATHS  $ENV{TRACE_CMD}/tracecmd/
                                       ${CMAKE_SOURCE_DIR}/../tracecmd/
                                NO_DEFAULT_PATH)

This will never evaluate to /usr/bin which is what it should be for
distro builds.

KS_DIR is used runtime to load plugins, as default path for file open
dialogs (which doesn't make much sense imo) and at compile time to
construct relative paths in the source directory. It is currently
defined simply as

set(KS_DIR ${CMAKE_SOURCE_DIR})

I think there needs to be a separate constant for plugins path that
can be set at build time and in distro build can point to
/usr/share/kernelshark/plugins or somewhere where we want shared
plugins to live. The compile time uses of KS_DIR are fine though
${CMAKE_SOURCE_DIR} is clearer for the reader. The default directory
for file open dialogs can be the current directory or the last opened
path rather than the kernelshark source directory.

What do you think?

Cheers,

-- Slavi
Steven Rostedt April 9, 2019, 5:02 p.m. UTC | #10
On Tue, 9 Apr 2019 15:44:55 +0000
Slavomir Kaslev <kaslevs@vmware.com> wrote:

> I think there needs to be a separate constant for plugins path that
> can be set at build time and in distro build can point to
> /usr/share/kernelshark/plugins or somewhere where we want shared
> plugins to live. The compile time uses of KS_DIR are fine though
> ${CMAKE_SOURCE_DIR} is clearer for the reader. The default directory
> for file open dialogs can be the current directory or the last opened
> path rather than the kernelshark source directory.
> 
> What do you think?

I agree.

-- Steve
Yordan Karadzhov April 15, 2019, 11:05 a.m. UTC | #11
On 9.04.19 г. 18:44 ч., Slavomir Kaslev wrote:
> The problem is the way they are defined atm:
> 
> # First search in the user provided paths.
> find_path(TRACECMD_BIN_DIR      NAMES  trace-cmd
>                                  PATHS  $ENV{TRACE_CMD}/tracecmd/
>                                         ${CMAKE_SOURCE_DIR}/../tracecmd/
>                                  NO_DEFAULT_PATH)
> 
> This will never evaluate to /usr/bin which is what it should be for
> distro builds.

I think there is a bit of confusion here. The code above will never 
search in /usr/bin. This statement is correct.

However if this search fails we will perform another search that will 
this time search in /usr/bin. Look few lines below in  FindTraceCmd.cmake.

The reason for this is to avoid confusion in the case when the user has 
the distro package installed, but in the same time is trying to build 
KernelShark from source. We want in this case the GUI to link with the 
version of the trace-cmd library that is being build (not the one from 
the package).

Thanks!
Yordan
Yordan Karadzhov April 15, 2019, 11:16 a.m. UTC | #12
On 9.04.19 г. 18:44 ч., Slavomir Kaslev wrote:
> KS_DIR is used runtime to load plugins, as default path for file open
> dialogs (which doesn't make much sense imo) and at compile time to
> construct relative paths in the source directory. It is currently
> defined simply as
> 
> set(KS_DIR ${CMAKE_SOURCE_DIR})
> 
> I think there needs to be a separate constant for plugins path that
> can be set at build time and in distro build can point to
> /usr/share/kernelshark/plugins or somewhere where we want shared
> plugins to live. 

Yes. No doubt that this must be separated.

> The compile time uses of KS_DIR are fine though
> ${CMAKE_SOURCE_DIR} is clearer for the reader. The default directory
> for file open dialogs can be the current directory or the last opened
> path rather than the kernelshark source directory.
> 
> What do you think?

I still think that if you build KernelShark from source, the most 
natural  default path for the open-file dialogs is the 
trace-cmd/kernel-shark directory. However if this directory doesn't 
exist the dialogs can start at ${HOME} (the one of the user running the 
app).


I still think that if you build KernelShark from source, the most 
natural  default path for the open-file dialogs is the 
trace-cmd/kernel-shark directory. However if this directory doesn't 
exist {distro installation} the dialogs can start at ${HOME} (the one of 
the user running the app).

What do you think?
Thanks!
Yordan
Slavomir Kaslev April 15, 2019, 1:11 p.m. UTC | #13
On Mon, 2019-04-15 at 14:05 +0300, Yordan Karadzhov (VMware) wrote:
> 
> On 9.04.19 г. 18:44 ч., Slavomir Kaslev wrote:
> > The problem is the way they are defined atm:
> > 
> > # First search in the user provided paths.
> > find_path(TRACECMD_BIN_DIR      NAMES  trace-cmd
> >                                  PATHS  $ENV{TRACE_CMD}/tracecmd/
> >                                         ${CMAKE_SOURCE_DIR}/../trac
> > ecmd/
> >                                  NO_DEFAULT_PATH)
> > 
> > This will never evaluate to /usr/bin which is what it should be for
> > distro builds.
> 
> I think there is a bit of confusion here. The code above will never 
> search in /usr/bin. This statement is correct.
> 
> However if this search fails we will perform another search that
> will 
> this time search in /usr/bin. Look few lines below
> in  FindTraceCmd.cmake.

Ah, I missed that.

> 
> The reason for this is to avoid confusion in the case when the user
> has 
> the distro package installed, but in the same time is trying to
> build 
> KernelShark from source. We want in this case the GUI to link with
> the 
> version of the trace-cmd library that is being build (not the one
> from 
> the package).

So how should I build kernelshark after a clean git clone for a distro
build? In particular, what sequence of commands do I need to run so
that I get fully build kernelshark with all constants pointing to the
correct places (say TRACECMD_BIN_DIR = /usr/bin). If this is not
supporeted yet (and I think it's not atm), we should at least have a
plan how we want to go about doing it. A script doing something is
always better that documenting how to achieve the same.

-- Slavi

> 
> Thanks!
> Yordan
> 
>
Yordan Karadzhov April 15, 2019, 1:58 p.m. UTC | #14
On 15.04.19 г. 16:11 ч., Slavomir Kaslev wrote:
> On Mon, 2019-04-15 at 14:05 +0300, Yordan Karadzhov (VMware) wrote:
>>
>> On 9.04.19 г. 18:44 ч., Slavomir Kaslev wrote:
>>> The problem is the way they are defined atm:
>>>
>>> # First search in the user provided paths.
>>> find_path(TRACECMD_BIN_DIR      NAMES  trace-cmd
>>>                                   PATHS  $ENV{TRACE_CMD}/tracecmd/
>>>                                          ${CMAKE_SOURCE_DIR}/../trac
>>> ecmd/
>>>                                   NO_DEFAULT_PATH)
>>>
>>> This will never evaluate to /usr/bin which is what it should be for
>>> distro builds.
>>
>> I think there is a bit of confusion here. The code above will never
>> search in /usr/bin. This statement is correct.
>>
>> However if this search fails we will perform another search that
>> will
>> this time search in /usr/bin. Look few lines below
>> in  FindTraceCmd.cmake.
> 
> Ah, I missed that.
> 
>>
>> The reason for this is to avoid confusion in the case when the user
>> has
>> the distro package installed, but in the same time is trying to
>> build
>> KernelShark from source. We want in this case the GUI to link with
>> the
>> version of the trace-cmd library that is being build (not the one
>> from
>> the package).
> 
> So how should I build kernelshark after a clean git clone for a distro
> build? In particular, what sequence of commands do I need to run so
> that I get fully build kernelshark with all constants pointing to the
> correct places (say TRACECMD_BIN_DIR = /usr/bin). If this is not
> supporeted yet (and I think it's not atm), we should at least have a
> plan how we want to go about doing it. A script doing something is
> always better that documenting how to achieve the same.

My understanding is that the user can do two things:
   1. sudo apt-get install kernelshark (on Ubuntu)

     In this case all libraries will be in /usr/local/lib/kshark/
                  all plugins will be in   /usr/local/lib/kshark/plugins/
            and all executables will be in /usr/local/bin/
            Or whatever is the install prefix chosen by the distro.

   2. git clone git://git.kernel.org/pub/scm/utils/trac...
      cd trace-cmd
      make gui

      in this case all libraries will be in trace-cmd/kernel-shark/lib/
                     all plugins will be in trace-cmd/kernel-shark/lib/
             and all executables will be in trace-cmd/kernel-shark/bin/

     at this point if you do:
     sudo make install gui

     option 2 became equivalent to option 1

and of course someone may decide to do both 1 and 2

Thanks!
Yordan

> 
> -- Slavi
> 
>>
>> Thanks!
>> Yordan
>>
>>
Steven Rostedt April 15, 2019, 8:04 p.m. UTC | #15
On Mon, 15 Apr 2019 14:16:53 +0300
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> I still think that if you build KernelShark from source, the most 
> natural  default path for the open-file dialogs is the 
> trace-cmd/kernel-shark directory. However if this directory doesn't 
> exist the dialogs can start at ${HOME} (the one of the user running the 
> app).

What you can do, and this is what some other applications do, is to
check the relative path of the binary. There's a few ways to accomplish
this. But once you know the exact path that the application ran from,
you can then check if the plugins exist relatively to the executable.

> 
> 
> I still think that if you build KernelShark from source, the most 
> natural  default path for the open-file dialogs is the 
> trace-cmd/kernel-shark directory. However if this directory doesn't 
> exist {distro installation} the dialogs can start at ${HOME} (the one of 
> the user running the app).


If I run kernelshark via:

 kernelshark/bin/kernelshark

that full path name will be in argv[0].

If I run it as: ./kernelshark we can look at that too. Perhaps we
should only check this if it's executed by a local path name (that is,
if it is found via the $PATH variable, we don't do this), which would
be the case if argv[0] == "kernelshark" and not "./kernelshark" or
something like that.

That is, we have something like this:

	if (strstr(argv[0], "/")) {
		char *fullpath = strdup(argv[0]);
		char *path, *local_plugin_path;
		struct stat sb;

		if (!fullpath) die(...);
		path = dirname(fullpath);
		ret = asprintf(&local_plugin_path, "%s/../../plugins");
		if (!ret) die (...);
		ret = stat(local_plugin_path, &sb);
		if (!ret) {
			if ((sb.st_mode & S_IFMT) == S_IFDIR)
				use_local_plugin_path = true;
		}
		free(fullpath);
		free(local_plugin_path);
	}

That way if you run this from the source directory, we use the source
plugin files, otherwise, we use the default ones.

-- Steve
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index cde45f8..d9b0c0e 100644
--- a/Makefile
+++ b/Makefile
@@ -254,7 +254,10 @@  all_cmd: $(CMD_TARGETS)
 CMAKE_COMMAND = /usr/bin/cmake
 
 $(kshark-dir)/build/Makefile: $(kshark-dir)/CMakeLists.txt
-	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) -D_INSTALL_PREFIX=$(prefix) ..
+
+	$(Q) cd $(kshark-dir)/build && $(CMAKE_COMMAND) \
+		-D_KS_CACHE_DIR=$(HOME)/.cache/kernelshark \
+		-D_INSTALL_PREFIX=$(prefix) ..
 
 gui: force $(CMD_TARGETS) $(kshark-dir)/build/Makefile
 	$(Q)$(MAKE) $(S) -C $(kshark-dir)/build
diff --git a/kernel-shark/CMakeLists.txt b/kernel-shark/CMakeLists.txt
index 8858eb7..14d73f5 100644
--- a/kernel-shark/CMakeLists.txt
+++ b/kernel-shark/CMakeLists.txt
@@ -12,10 +12,12 @@  message("\n project: Kernel Shark: (version: ${KS_VERSION_STRING})\n")
 
 set(KS_DIR ${CMAKE_SOURCE_DIR})
 
-# Make a directory to hold configuration files. To change this do:
-# cmake .. -DKS_CONF_DIR=/your/preferred/path
-set(KS_CONF_DIR "${KS_DIR}/.ksconf" CACHE STRING "Directory for configuration files.")
-file(MAKE_DIRECTORY ${KS_CONF_DIR})
+# Make a directory to hold cached configuration files. To change this do:
+# cmake .. -D_KS_CACHE_DIR=/your/preferred/path
+set(_KS_CACHE_DIR "$ENV{HOME}/.cache/kernelshark"
+    CACHE STRING "Directory for cached configuration files.")
+
+file(MAKE_DIRECTORY ${_KS_CACHE_DIR})
 
 include(${KS_DIR}/build/FindTraceCmd.cmake)
 include(${KS_DIR}/build/FindJSONC.cmake)
@@ -66,7 +68,8 @@  include_directories(${KS_DIR}/src/
 message("")
 message(STATUS "C flags      : " ${CMAKE_C_FLAGS})
 message(STATUS "CXX flags    : " ${CMAKE_CXX_FLAGS})
-message(STATUS "Linker flags : " ${CMAKE_EXE_LINKER_FLAGS})
+message(STATUS "Linker flags : " ${CMAKE_EXE_LINKER_FLAGS}\n)
+message(STATUS "config. files saved in ${_KS_CACHE_DIR}")
 
 add_subdirectory(${KS_DIR}/src)
 add_subdirectory(${KS_DIR}/examples)
diff --git a/kernel-shark/README b/kernel-shark/README
index 9f7db26..a75b08b 100644
--- a/kernel-shark/README
+++ b/kernel-shark/README
@@ -52,8 +52,14 @@  as a CMake Command-Line option.
 2.1.3 By default, installation prefix is "/usr/local". It can be changed using
 -D_INSTALL_PREFIX= as a CMake Command-Line option.
 
-Example:
+2.1.4 By default, the directory that holds cached configuration files is
+${HOME}/.cache/kernelshark/ .It can be changed using -D_KS_CACHE_DIR=
+as a CMake Command-Line option. Use only absolute paths for this option.
+
+
+Examples:
     cmake -D_DOXYGEN_DOC=1 -D_DEBUG=1 -D_INSTALL_PREFIX=/usr ../
+    cmake -D_KS_CACHE_DIR=${PWD}../.kscache ../
 
 2.2.1 Use "make clean" if you want to delete all already compiled objects.
 
diff --git a/kernel-shark/build/deff.h.cmake b/kernel-shark/build/deff.h.cmake
index 80d624c..f1f6a35 100644
--- a/kernel-shark/build/deff.h.cmake
+++ b/kernel-shark/build/deff.h.cmake
@@ -14,8 +14,8 @@ 
 /** KernelShark source code path. */
 #cmakedefine KS_DIR "@KS_DIR@"
 
-/** KernelShark configuration directory path. */
-#cmakedefine KS_CONF_DIR "@KS_CONF_DIR@"
+/** KernelShark cache directory path. */
+#cmakedefine _KS_CACHE_DIR "@_KS_CACHE_DIR@"
 
 /** Location of the trace-cmd executable. */
 #cmakedefine TRACECMD_BIN_DIR "@TRACECMD_BIN_DIR@"
diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp
index 7afb721..d07a89d 100644
--- a/kernel-shark/src/KsMainWindow.cpp
+++ b/kernel-shark/src/KsMainWindow.cpp
@@ -133,7 +133,7 @@  KsMainWindow::KsMainWindow(QWidget *parent)
 KsMainWindow::~KsMainWindow()
 {
 	kshark_context *kshark_ctx(nullptr);
-	QString file = KS_CONF_DIR;
+	QString file = _KS_CACHE_DIR;
 
 	file += "/lastsession.json";
 
@@ -370,7 +370,7 @@  void KsMainWindow::_open()
 
 void KsMainWindow::_restoreSession()
 {
-	QString file = KS_CONF_DIR;
+	QString file = _KS_CACHE_DIR;
 	file += "/lastsession.json";
 
 	loadSession(file);