Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-24 Thread Arnaldo Carvalho de Melo
Em Mon, Aug 24, 2015 at 10:00:17AM +0300, Adrian Hunter escreveu:
> On 21/08/15 18:28, Arnaldo Carvalho de Melo wrote:
> > Em Fri, Aug 21, 2015 at 12:21:25PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo 
> >> escreveu:
> >>> [acme@zoo ~]$ perf script -s 
> >>> ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
> >>> branches calls
> >>> 2015-08-21 12:10:00.504126 Creating database...
> >>> QSqlDatabase: QPSQL driver not loaded
> >>> QSqlDatabase: available drivers: QSQLITE
> >>> QSqlDatabase: an instance of QCoreApplication is required for loading 
> >>> driver plugins
> >>> QSqlQuery::exec: database not open
> >>> Traceback (most recent call last):
> >>>   File 
> >>> "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
> >>> line 87, in 
> >>> do_query(query, 'CREATE DATABASE ' + dbname)
> >>>   File 
> >>> "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
> >>> line 78, in do_query
> >>> raise Exception("Query failed: " + q.lastError().text())
> >>> Exception: Query failed: Driver not loaded Driver not loaded
> >>> Error running python script 
> >>> /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
> >>> [acme@zoo ~]$ 
> >>
> >> A-ha, this was missing:
> >>
> >> [root@zoo ~]# rpm -ql qt-postgresql 
> >> /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
> >> [root@zoo ~]#
> >>
> >> [acme@zoo ~]$ perf script -s 
> >> ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
> >> branches calls
> >> 2015-08-21 12:20:01.841677 Creating database...
> >> 2015-08-21 12:20:02.556853 Writing to intermediate files...
> >> 2015-08-21 12:20:03.262814 Copying to database...
> >> 2015-08-21 12:20:03.783109 Removing intermediate files...
> >> 2015-08-21 12:20:03.790282 Adding primary keys
> >> 2015-08-21 12:20:04.294342 Adding foreign keys
> >> 2015-08-21 12:20:04.718238 Done
> >> [acme@zoo ~]$ 
> >>
> >> Now to the next steps... Lets see how this looks like with BTS...
> > 
> > So, after running:
> > 
> >   [acme@zoo linux]$ python
> >   tools/perf/scripts/python/call-graph-from-postgresql.py bts_example
> > 
> > I got a GUI and after expanding some callchains I took this screenshot:
> > 
> >   http://vger.kernel.org/~acme/perf/call_graph_example_intel_bts.png
> > 
> > Cool stuff! But it seems the COMM got messed up? I.e. that "1380:1380"
> > first level after "ls".
> 
> That is, in fact, correct.  The top-level is the process (comm).  The next
> level is the threads (pid/tid) for that process.  Currently, each thread is
> reported separately.

Ok, understood.

> For the future, there ought to be an option to combine the data for all
> threads of a process, or all processes with the same comm.  Also presently
> it is not tracking if a thread sets it's own comm (e.g. some multi-threaded
> applications name each thread).

And in that case it would be nice to have both the comms and pid/tid.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-24 Thread Adrian Hunter
On 21/08/15 18:28, Arnaldo Carvalho de Melo wrote:
> Em Fri, Aug 21, 2015 at 12:21:25PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo escreveu:
>>> [acme@zoo ~]$ perf script -s 
>>> ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
>>> branches calls
>>> 2015-08-21 12:10:00.504126 Creating database...
>>> QSqlDatabase: QPSQL driver not loaded
>>> QSqlDatabase: available drivers: QSQLITE
>>> QSqlDatabase: an instance of QCoreApplication is required for loading 
>>> driver plugins
>>> QSqlQuery::exec: database not open
>>> Traceback (most recent call last):
>>>   File 
>>> "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", line 
>>> 87, in 
>>> do_query(query, 'CREATE DATABASE ' + dbname)
>>>   File 
>>> "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", line 
>>> 78, in do_query
>>> raise Exception("Query failed: " + q.lastError().text())
>>> Exception: Query failed: Driver not loaded Driver not loaded
>>> Error running python script 
>>> /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
>>> [acme@zoo ~]$ 
>>
>> A-ha, this was missing:
>>
>> [root@zoo ~]# rpm -ql qt-postgresql 
>> /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
>> [root@zoo ~]#
>>
>> [acme@zoo ~]$ perf script -s 
>> ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
>> branches calls
>> 2015-08-21 12:20:01.841677 Creating database...
>> 2015-08-21 12:20:02.556853 Writing to intermediate files...
>> 2015-08-21 12:20:03.262814 Copying to database...
>> 2015-08-21 12:20:03.783109 Removing intermediate files...
>> 2015-08-21 12:20:03.790282 Adding primary keys
>> 2015-08-21 12:20:04.294342 Adding foreign keys
>> 2015-08-21 12:20:04.718238 Done
>> [acme@zoo ~]$ 
>>
>> Now to the next steps... Lets see how this looks like with BTS...
> 
> So, after running:
> 
>   [acme@zoo linux]$ python
>   tools/perf/scripts/python/call-graph-from-postgresql.py bts_example
> 
> I got a GUI and after expanding some callchains I took this screenshot:
> 
>   http://vger.kernel.org/~acme/perf/call_graph_example_intel_bts.png
> 
> Cool stuff! But it seems the COMM got messed up? I.e. that "1380:1380"
> first level after "ls".

That is, in fact, correct.  The top-level is the process (comm).  The next
level is the threads (pid/tid) for that process.  Currently, each thread is
reported separately.

For the future, there ought to be an option to combine the data for all
threads of a process, or all processes with the same comm.  Also presently
it is not tracking if a thread sets it's own comm (e.g. some multi-threaded
applications name each thread).

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-24 Thread Adrian Hunter
On 21/08/15 18:28, Arnaldo Carvalho de Melo wrote:
 Em Fri, Aug 21, 2015 at 12:21:25PM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo escreveu:
 [acme@zoo ~]$ perf script -s 
 ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
 branches calls
 2015-08-21 12:10:00.504126 Creating database...
 QSqlDatabase: QPSQL driver not loaded
 QSqlDatabase: available drivers: QSQLITE
 QSqlDatabase: an instance of QCoreApplication is required for loading 
 driver plugins
 QSqlQuery::exec: database not open
 Traceback (most recent call last):
   File 
 /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, line 
 87, in module
 do_query(query, 'CREATE DATABASE ' + dbname)
   File 
 /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, line 
 78, in do_query
 raise Exception(Query failed:  + q.lastError().text())
 Exception: Query failed: Driver not loaded Driver not loaded
 Error running python script 
 /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
 [acme@zoo ~]$ 

 A-ha, this was missing:

 [root@zoo ~]# rpm -ql qt-postgresql 
 /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
 [root@zoo ~]#

 [acme@zoo ~]$ perf script -s 
 ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
 branches calls
 2015-08-21 12:20:01.841677 Creating database...
 2015-08-21 12:20:02.556853 Writing to intermediate files...
 2015-08-21 12:20:03.262814 Copying to database...
 2015-08-21 12:20:03.783109 Removing intermediate files...
 2015-08-21 12:20:03.790282 Adding primary keys
 2015-08-21 12:20:04.294342 Adding foreign keys
 2015-08-21 12:20:04.718238 Done
 [acme@zoo ~]$ 

 Now to the next steps... Lets see how this looks like with BTS...
 
 So, after running:
 
   [acme@zoo linux]$ python
   tools/perf/scripts/python/call-graph-from-postgresql.py bts_example
 
 I got a GUI and after expanding some callchains I took this screenshot:
 
   http://vger.kernel.org/~acme/perf/call_graph_example_intel_bts.png
 
 Cool stuff! But it seems the COMM got messed up? I.e. that 1380:1380
 first level after ls.

That is, in fact, correct.  The top-level is the process (comm).  The next
level is the threads (pid/tid) for that process.  Currently, each thread is
reported separately.

For the future, there ought to be an option to combine the data for all
threads of a process, or all processes with the same comm.  Also presently
it is not tracking if a thread sets it's own comm (e.g. some multi-threaded
applications name each thread).

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-24 Thread Arnaldo Carvalho de Melo
Em Mon, Aug 24, 2015 at 10:00:17AM +0300, Adrian Hunter escreveu:
 On 21/08/15 18:28, Arnaldo Carvalho de Melo wrote:
  Em Fri, Aug 21, 2015 at 12:21:25PM -0300, Arnaldo Carvalho de Melo escreveu:
  Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo 
  escreveu:
  [acme@zoo ~]$ perf script -s 
  ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
  branches calls
  2015-08-21 12:10:00.504126 Creating database...
  QSqlDatabase: QPSQL driver not loaded
  QSqlDatabase: available drivers: QSQLITE
  QSqlDatabase: an instance of QCoreApplication is required for loading 
  driver plugins
  QSqlQuery::exec: database not open
  Traceback (most recent call last):
File 
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
  line 87, in module
  do_query(query, 'CREATE DATABASE ' + dbname)
File 
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
  line 78, in do_query
  raise Exception(Query failed:  + q.lastError().text())
  Exception: Query failed: Driver not loaded Driver not loaded
  Error running python script 
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
  [acme@zoo ~]$ 
 
  A-ha, this was missing:
 
  [root@zoo ~]# rpm -ql qt-postgresql 
  /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
  [root@zoo ~]#
 
  [acme@zoo ~]$ perf script -s 
  ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
  branches calls
  2015-08-21 12:20:01.841677 Creating database...
  2015-08-21 12:20:02.556853 Writing to intermediate files...
  2015-08-21 12:20:03.262814 Copying to database...
  2015-08-21 12:20:03.783109 Removing intermediate files...
  2015-08-21 12:20:03.790282 Adding primary keys
  2015-08-21 12:20:04.294342 Adding foreign keys
  2015-08-21 12:20:04.718238 Done
  [acme@zoo ~]$ 
 
  Now to the next steps... Lets see how this looks like with BTS...
  
  So, after running:
  
[acme@zoo linux]$ python
tools/perf/scripts/python/call-graph-from-postgresql.py bts_example
  
  I got a GUI and after expanding some callchains I took this screenshot:
  
http://vger.kernel.org/~acme/perf/call_graph_example_intel_bts.png
  
  Cool stuff! But it seems the COMM got messed up? I.e. that 1380:1380
  first level after ls.
 
 That is, in fact, correct.  The top-level is the process (comm).  The next
 level is the threads (pid/tid) for that process.  Currently, each thread is
 reported separately.

Ok, understood.

 For the future, there ought to be an option to combine the data for all
 threads of a process, or all processes with the same comm.  Also presently
 it is not tracking if a thread sets it's own comm (e.g. some multi-threaded
 applications name each thread).

And in that case it would be nice to have both the comms and pid/tid.

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:28:13PM -0300, Arnaldo Carvalho de Melo escreveu:
> > A-ha, this was missing:
> > 
> > [root@zoo ~]# rpm -ql qt-postgresql 
> > /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so

Adding this to your patch:

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 5e939eadacd2..84a32037a80f 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -25,7 +25,7 @@ import datetime
 #
 # fedora:
 #
-#  $ sudo yum install postgresql postgresql-server
+#  $ sudo yum install postgresql postgresql-server python-pyside 
qt-postgresql
 #  $ sudo su - postgres -c initdb
 #  $ sudo service postgresql start
 #  $ sudo su - postgres
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:21:25PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo escreveu:
> > [acme@zoo ~]$ perf script -s 
> > ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
> > branches calls
> > 2015-08-21 12:10:00.504126 Creating database...
> > QSqlDatabase: QPSQL driver not loaded
> > QSqlDatabase: available drivers: QSQLITE
> > QSqlDatabase: an instance of QCoreApplication is required for loading 
> > driver plugins
> > QSqlQuery::exec: database not open
> > Traceback (most recent call last):
> >   File 
> > "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", line 
> > 87, in 
> > do_query(query, 'CREATE DATABASE ' + dbname)
> >   File 
> > "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", line 
> > 78, in do_query
> > raise Exception("Query failed: " + q.lastError().text())
> > Exception: Query failed: Driver not loaded Driver not loaded
> > Error running python script 
> > /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
> > [acme@zoo ~]$ 
> 
> A-ha, this was missing:
> 
> [root@zoo ~]# rpm -ql qt-postgresql 
> /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
> [root@zoo ~]#
> 
> [acme@zoo ~]$ perf script -s 
> ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
> branches calls
> 2015-08-21 12:20:01.841677 Creating database...
> 2015-08-21 12:20:02.556853 Writing to intermediate files...
> 2015-08-21 12:20:03.262814 Copying to database...
> 2015-08-21 12:20:03.783109 Removing intermediate files...
> 2015-08-21 12:20:03.790282 Adding primary keys
> 2015-08-21 12:20:04.294342 Adding foreign keys
> 2015-08-21 12:20:04.718238 Done
> [acme@zoo ~]$ 
> 
> Now to the next steps... Lets see how this looks like with BTS...

So, after running:

  [acme@zoo linux]$ python
  tools/perf/scripts/python/call-graph-from-postgresql.py bts_example

I got a GUI and after expanding some callchains I took this screenshot:

  http://vger.kernel.org/~acme/perf/call_graph_example_intel_bts.png

Cool stuff! But it seems the COMM got messed up? I.e. that "1380:1380"
first level after "ls".

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo escreveu:
> [acme@zoo ~]$ perf script -s 
> ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
> branches calls
> 2015-08-21 12:10:00.504126 Creating database...
> QSqlDatabase: QPSQL driver not loaded
> QSqlDatabase: available drivers: QSQLITE
> QSqlDatabase: an instance of QCoreApplication is required for loading driver 
> plugins
> QSqlQuery::exec: database not open
> Traceback (most recent call last):
>   File "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
> line 87, in 
> do_query(query, 'CREATE DATABASE ' + dbname)
>   File "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
> line 78, in do_query
> raise Exception("Query failed: " + q.lastError().text())
> Exception: Query failed: Driver not loaded Driver not loaded
> Error running python script 
> /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
> [acme@zoo ~]$ 

A-ha, this was missing:

[root@zoo ~]# rpm -ql qt-postgresql 
/usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
[root@zoo ~]#

[acme@zoo ~]$ perf script -s 
~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example branches 
calls
2015-08-21 12:20:01.841677 Creating database...
2015-08-21 12:20:02.556853 Writing to intermediate files...
2015-08-21 12:20:03.262814 Copying to database...
2015-08-21 12:20:03.783109 Removing intermediate files...
2015-08-21 12:20:03.790282 Adding primary keys
2015-08-21 12:20:04.294342 Adding foreign keys
2015-08-21 12:20:04.718238 Done
[acme@zoo ~]$ 

Now to the next steps... Lets see how this looks like with BTS...

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:00:13PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Jul 17, 2015 at 07:33:45PM +0300, Adrian Hunter escreveu:
> > Add a script to produce a call-graph from data exported
> > to a postgresql database and derived from a processor trace
> > event like intel_pt or intel_bts. Refer to comments in the
> > scripts call-graph-from-postgresql.py and export-to-postgresql.py
> > for more details.
> 
> Testing this, you forgot to add instructions to install the qt stuff:
> 
>   [acme@felicio ~]$ perf script -s
>   ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example
>   branches calls
> 
>   Traceback (most recent call last):
> File
>   "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py",
>   line 65, in 
>   from PySide.QtSql import *
>   ImportError: No module named PySide.QtSql
>   Error running python script
>   /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
>   [acme@felicio ~]$
> 
> I'll add it.

[acme@zoo ~]$ perf script -s 
~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example branches 
calls
Traceback (most recent call last):
  File "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
line 18, in 
from PySide.QtSql import *
ImportError: No module named PySide.QtSql
Error running python script 
/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py


Installed python-pyside, fedora21, but still something is missing:

[acme@zoo ~]$ perf script -s 
~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example branches 
calls
2015-08-21 12:10:00.504126 Creating database...
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
QSqlDatabase: an instance of QCoreApplication is required for loading driver 
plugins
QSqlQuery::exec: database not open
Traceback (most recent call last):
  File "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
line 87, in 
do_query(query, 'CREATE DATABASE ' + dbname)
  File "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py", 
line 78, in do_query
raise Exception("Query failed: " + q.lastError().text())
Exception: Query failed: Driver not loaded Driver not loaded
Error running python script 
/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
[acme@zoo ~]$ 

> - Arnaldo
>  
> > Signed-off-by: Adrian Hunter 
> > ---
> >  .../scripts/python/call-graph-from-postgresql.py   | 327 
> > +
> >  tools/perf/scripts/python/export-to-postgresql.py  |  47 +++
> >  2 files changed, 374 insertions(+)
> >  create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py
> > 
> > diff --git a/tools/perf/scripts/python/call-graph-from-postgresql.py 
> > b/tools/perf/scripts/python/call-graph-from-postgresql.py
> > new file mode 100644
> > index ..e78fdc2a5a9d
> > --- /dev/null
> > +++ b/tools/perf/scripts/python/call-graph-from-postgresql.py
> > @@ -0,0 +1,327 @@
> > +#!/usr/bin/python2
> > +# call-graph-from-postgresql.py: create call-graph from postgresql database
> > +# Copyright (c) 2014, Intel Corporation.
> > +#
> > +# This program is free software; you can redistribute it and/or modify it
> > +# under the terms and conditions of the GNU General Public License,
> > +# version 2, as published by the Free Software Foundation.
> > +#
> > +# This program is distributed in the hope it will be useful, but WITHOUT
> > +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > +# more details.
> > +
> > +# To use this script you will need to have exported data using the
> > +# export-to-postgresql.py script.  Refer to that script for details.
> > +#
> > +# Following on from the example in the export-to-postgresql.py script, a
> > +# call-graph can be displayed for the pt_example database like this:
> > +#
> > +#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
> > pt_example
> > +#
> > +# Note this script supports connecting to remote databases by setting 
> > hostname,
> > +# port, username, password, and dbname e.g.
> > +#
> > +#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
> > "hostname=myhost username=myuser password=mypassword dbname=pt_example"
> > +#
> > +# The result is a GUI window with a tree representing a context-sensitive
> > +# call-graph.  Expanding a couple of levels of the tree and adjusting 
> > column
> > +# widths to suit will display something like:
> > +#
> > +# Call Graph: pt_example
> > +# Call Path  Object  Count   Time(ns)  Time(%) 
> >  Branch Count   Branch Count(%)
> > +# v- ls
> > +# v- 2638:2638
> > +# v- _start  ld-2.19.so1 10074071   100.0  
> >211135100.0
> > +#   |- unknown   unknown   113198 

Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Jul 17, 2015 at 07:33:45PM +0300, Adrian Hunter escreveu:
> Add a script to produce a call-graph from data exported
> to a postgresql database and derived from a processor trace
> event like intel_pt or intel_bts. Refer to comments in the
> scripts call-graph-from-postgresql.py and export-to-postgresql.py
> for more details.

Testing this, you forgot to add instructions to install the qt stuff:

  [acme@felicio ~]$ perf script -s
  ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example
  branches calls

  Traceback (most recent call last):
File
  "/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py",
  line 65, in 
  from PySide.QtSql import *
  ImportError: No module named PySide.QtSql
  Error running python script
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
  [acme@felicio ~]$

I'll add it.

- Arnaldo
 
> Signed-off-by: Adrian Hunter 
> ---
>  .../scripts/python/call-graph-from-postgresql.py   | 327 
> +
>  tools/perf/scripts/python/export-to-postgresql.py  |  47 +++
>  2 files changed, 374 insertions(+)
>  create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py
> 
> diff --git a/tools/perf/scripts/python/call-graph-from-postgresql.py 
> b/tools/perf/scripts/python/call-graph-from-postgresql.py
> new file mode 100644
> index ..e78fdc2a5a9d
> --- /dev/null
> +++ b/tools/perf/scripts/python/call-graph-from-postgresql.py
> @@ -0,0 +1,327 @@
> +#!/usr/bin/python2
> +# call-graph-from-postgresql.py: create call-graph from postgresql database
> +# Copyright (c) 2014, Intel Corporation.
> +#
> +# This program is free software; you can redistribute it and/or modify it
> +# under the terms and conditions of the GNU General Public License,
> +# version 2, as published by the Free Software Foundation.
> +#
> +# This program is distributed in the hope it will be useful, but WITHOUT
> +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> +# more details.
> +
> +# To use this script you will need to have exported data using the
> +# export-to-postgresql.py script.  Refer to that script for details.
> +#
> +# Following on from the example in the export-to-postgresql.py script, a
> +# call-graph can be displayed for the pt_example database like this:
> +#
> +#python tools/perf/scripts/python/call-graph-from-postgresql.py 
> pt_example
> +#
> +# Note this script supports connecting to remote databases by setting 
> hostname,
> +# port, username, password, and dbname e.g.
> +#
> +#python tools/perf/scripts/python/call-graph-from-postgresql.py 
> "hostname=myhost username=myuser password=mypassword dbname=pt_example"
> +#
> +# The result is a GUI window with a tree representing a context-sensitive
> +# call-graph.  Expanding a couple of levels of the tree and adjusting column
> +# widths to suit will display something like:
> +#
> +# Call Graph: pt_example
> +# Call Path  Object  Count   Time(ns)  Time(%)  
> Branch Count   Branch Count(%)
> +# v- ls
> +# v- 2638:2638
> +# v- _start  ld-2.19.so1 10074071   100.0
>  211135100.0
> +#   |- unknown   unknown   113198 0.1
>   1  0.0
> +#   >- _dl_start ld-2.19.so1  140098013.9
>   19637  9.3
> +#   >- _d_linit_internal ld-2.19.so1   448152 4.4
>   11094  5.3
> +#   v-__libc_start_main@plt  ls1  821174181.5
>  180397 85.4
> +#  >- _dl_fixup  ld-2.19.so1 7607 0.1
> 108  0.1
> +#  >- __cxa_atexit   libc-2.19.so  111737 0.1
>  10  0.0
> +#  >- __libc_csu_initls110354 0.1
>  10  0.0
> +#  |- _setjmplibc-2.19.so  10 0.0
>   4  0.0
> +#  v- main   ls1  818204399.6
>  180254 99.9
> +#
> +# Points to note:
> +#The top level is a command name (comm)
> +#The next level is a thread (pid:tid)
> +#Subsequent levels are functions
> +#'Count' is the number of calls
> +#'Time' is the elapsed time until the function returns
> +#Percentages are relative to the level above
> +#'Branch Count' is the total number of branches for that function and all
> +#   functions that it calls
> +
> +import sys
> +from PySide.QtCore import *
> +from PySide.QtGui import *
> +from PySide.QtSql import *
> +from decimal import *
> +
> +class TreeItem():
> +
> + def __init__(self, db, row, parent_item):
> + self.db = db

Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:28:13PM -0300, Arnaldo Carvalho de Melo escreveu:
  A-ha, this was missing:
  
  [root@zoo ~]# rpm -ql qt-postgresql 
  /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so

Adding this to your patch:

diff --git a/tools/perf/scripts/python/export-to-postgresql.py 
b/tools/perf/scripts/python/export-to-postgresql.py
index 5e939eadacd2..84a32037a80f 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -25,7 +25,7 @@ import datetime
 #
 # fedora:
 #
-#  $ sudo yum install postgresql postgresql-server
+#  $ sudo yum install postgresql postgresql-server python-pyside 
qt-postgresql
 #  $ sudo su - postgres -c initdb
 #  $ sudo service postgresql start
 #  $ sudo su - postgres
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Jul 17, 2015 at 07:33:45PM +0300, Adrian Hunter escreveu:
 Add a script to produce a call-graph from data exported
 to a postgresql database and derived from a processor trace
 event like intel_pt or intel_bts. Refer to comments in the
 scripts call-graph-from-postgresql.py and export-to-postgresql.py
 for more details.

Testing this, you forgot to add instructions to install the qt stuff:

  [acme@felicio ~]$ perf script -s
  ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example
  branches calls

  Traceback (most recent call last):
File
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py,
  line 65, in module
  from PySide.QtSql import *
  ImportError: No module named PySide.QtSql
  Error running python script
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
  [acme@felicio ~]$

I'll add it.

- Arnaldo
 
 Signed-off-by: Adrian Hunter adrian.hun...@intel.com
 ---
  .../scripts/python/call-graph-from-postgresql.py   | 327 
 +
  tools/perf/scripts/python/export-to-postgresql.py  |  47 +++
  2 files changed, 374 insertions(+)
  create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py
 
 diff --git a/tools/perf/scripts/python/call-graph-from-postgresql.py 
 b/tools/perf/scripts/python/call-graph-from-postgresql.py
 new file mode 100644
 index ..e78fdc2a5a9d
 --- /dev/null
 +++ b/tools/perf/scripts/python/call-graph-from-postgresql.py
 @@ -0,0 +1,327 @@
 +#!/usr/bin/python2
 +# call-graph-from-postgresql.py: create call-graph from postgresql database
 +# Copyright (c) 2014, Intel Corporation.
 +#
 +# This program is free software; you can redistribute it and/or modify it
 +# under the terms and conditions of the GNU General Public License,
 +# version 2, as published by the Free Software Foundation.
 +#
 +# This program is distributed in the hope it will be useful, but WITHOUT
 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 +# more details.
 +
 +# To use this script you will need to have exported data using the
 +# export-to-postgresql.py script.  Refer to that script for details.
 +#
 +# Following on from the example in the export-to-postgresql.py script, a
 +# call-graph can be displayed for the pt_example database like this:
 +#
 +#python tools/perf/scripts/python/call-graph-from-postgresql.py 
 pt_example
 +#
 +# Note this script supports connecting to remote databases by setting 
 hostname,
 +# port, username, password, and dbname e.g.
 +#
 +#python tools/perf/scripts/python/call-graph-from-postgresql.py 
 hostname=myhost username=myuser password=mypassword dbname=pt_example
 +#
 +# The result is a GUI window with a tree representing a context-sensitive
 +# call-graph.  Expanding a couple of levels of the tree and adjusting column
 +# widths to suit will display something like:
 +#
 +# Call Graph: pt_example
 +# Call Path  Object  Count   Time(ns)  Time(%)  
 Branch Count   Branch Count(%)
 +# v- ls
 +# v- 2638:2638
 +# v- _start  ld-2.19.so1 10074071   100.0
  211135100.0
 +#   |- unknown   unknown   113198 0.1
   1  0.0
 +#   - _dl_start ld-2.19.so1  140098013.9
   19637  9.3
 +#   - _d_linit_internal ld-2.19.so1   448152 4.4
   11094  5.3
 +#   v-__libc_start_main@plt  ls1  821174181.5
  180397 85.4
 +#  - _dl_fixup  ld-2.19.so1 7607 0.1
 108  0.1
 +#  - __cxa_atexit   libc-2.19.so  111737 0.1
  10  0.0
 +#  - __libc_csu_initls110354 0.1
  10  0.0
 +#  |- _setjmplibc-2.19.so  10 0.0
   4  0.0
 +#  v- main   ls1  818204399.6
  180254 99.9
 +#
 +# Points to note:
 +#The top level is a command name (comm)
 +#The next level is a thread (pid:tid)
 +#Subsequent levels are functions
 +#'Count' is the number of calls
 +#'Time' is the elapsed time until the function returns
 +#Percentages are relative to the level above
 +#'Branch Count' is the total number of branches for that function and all
 +#   functions that it calls
 +
 +import sys
 +from PySide.QtCore import *
 +from PySide.QtGui import *
 +from PySide.QtSql import *
 +from decimal import *
 +
 +class TreeItem():
 +
 + def __init__(self, db, row, parent_item):
 + self.db = db
 + self.row = row
 + self.parent_item = parent_item
 +  

Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:00:13PM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Jul 17, 2015 at 07:33:45PM +0300, Adrian Hunter escreveu:
  Add a script to produce a call-graph from data exported
  to a postgresql database and derived from a processor trace
  event like intel_pt or intel_bts. Refer to comments in the
  scripts call-graph-from-postgresql.py and export-to-postgresql.py
  for more details.
 
 Testing this, you forgot to add instructions to install the qt stuff:
 
   [acme@felicio ~]$ perf script -s
   ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example
   branches calls
 
   Traceback (most recent call last):
 File
   /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py,
   line 65, in module
   from PySide.QtSql import *
   ImportError: No module named PySide.QtSql
   Error running python script
   /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
   [acme@felicio ~]$
 
 I'll add it.

[acme@zoo ~]$ perf script -s 
~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example branches 
calls
Traceback (most recent call last):
  File /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
line 18, in module
from PySide.QtSql import *
ImportError: No module named PySide.QtSql
Error running python script 
/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py


Installed python-pyside, fedora21, but still something is missing:

[acme@zoo ~]$ perf script -s 
~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example branches 
calls
2015-08-21 12:10:00.504126 Creating database...
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE
QSqlDatabase: an instance of QCoreApplication is required for loading driver 
plugins
QSqlQuery::exec: database not open
Traceback (most recent call last):
  File /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
line 87, in module
do_query(query, 'CREATE DATABASE ' + dbname)
  File /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
line 78, in do_query
raise Exception(Query failed:  + q.lastError().text())
Exception: Query failed: Driver not loaded Driver not loaded
Error running python script 
/home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
[acme@zoo ~]$ 

 - Arnaldo
  
  Signed-off-by: Adrian Hunter adrian.hun...@intel.com
  ---
   .../scripts/python/call-graph-from-postgresql.py   | 327 
  +
   tools/perf/scripts/python/export-to-postgresql.py  |  47 +++
   2 files changed, 374 insertions(+)
   create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py
  
  diff --git a/tools/perf/scripts/python/call-graph-from-postgresql.py 
  b/tools/perf/scripts/python/call-graph-from-postgresql.py
  new file mode 100644
  index ..e78fdc2a5a9d
  --- /dev/null
  +++ b/tools/perf/scripts/python/call-graph-from-postgresql.py
  @@ -0,0 +1,327 @@
  +#!/usr/bin/python2
  +# call-graph-from-postgresql.py: create call-graph from postgresql database
  +# Copyright (c) 2014, Intel Corporation.
  +#
  +# This program is free software; you can redistribute it and/or modify it
  +# under the terms and conditions of the GNU General Public License,
  +# version 2, as published by the Free Software Foundation.
  +#
  +# This program is distributed in the hope it will be useful, but WITHOUT
  +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  +# more details.
  +
  +# To use this script you will need to have exported data using the
  +# export-to-postgresql.py script.  Refer to that script for details.
  +#
  +# Following on from the example in the export-to-postgresql.py script, a
  +# call-graph can be displayed for the pt_example database like this:
  +#
  +#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
  pt_example
  +#
  +# Note this script supports connecting to remote databases by setting 
  hostname,
  +# port, username, password, and dbname e.g.
  +#
  +#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
  hostname=myhost username=myuser password=mypassword dbname=pt_example
  +#
  +# The result is a GUI window with a tree representing a context-sensitive
  +# call-graph.  Expanding a couple of levels of the tree and adjusting 
  column
  +# widths to suit will display something like:
  +#
  +# Call Graph: pt_example
  +# Call Path  Object  Count   Time(ns)  Time(%) 
   Branch Count   Branch Count(%)
  +# v- ls
  +# v- 2638:2638
  +# v- _start  ld-2.19.so1 10074071   100.0  
 211135100.0
  +#   |- unknown   unknown   113198 0.1  
  1  0.0
  +#   - _dl_start ld-2.19.so1  140098013.9  
  

Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo escreveu:
 [acme@zoo ~]$ perf script -s 
 ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
 branches calls
 2015-08-21 12:10:00.504126 Creating database...
 QSqlDatabase: QPSQL driver not loaded
 QSqlDatabase: available drivers: QSQLITE
 QSqlDatabase: an instance of QCoreApplication is required for loading driver 
 plugins
 QSqlQuery::exec: database not open
 Traceback (most recent call last):
   File /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
 line 87, in module
 do_query(query, 'CREATE DATABASE ' + dbname)
   File /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, 
 line 78, in do_query
 raise Exception(Query failed:  + q.lastError().text())
 Exception: Query failed: Driver not loaded Driver not loaded
 Error running python script 
 /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
 [acme@zoo ~]$ 

A-ha, this was missing:

[root@zoo ~]# rpm -ql qt-postgresql 
/usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
[root@zoo ~]#

[acme@zoo ~]$ perf script -s 
~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example branches 
calls
2015-08-21 12:20:01.841677 Creating database...
2015-08-21 12:20:02.556853 Writing to intermediate files...
2015-08-21 12:20:03.262814 Copying to database...
2015-08-21 12:20:03.783109 Removing intermediate files...
2015-08-21 12:20:03.790282 Adding primary keys
2015-08-21 12:20:04.294342 Adding foreign keys
2015-08-21 12:20:04.718238 Done
[acme@zoo ~]$ 

Now to the next steps... Lets see how this looks like with BTS...

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V8 10/25] perf tools: Add example call-graph script

2015-08-21 Thread Arnaldo Carvalho de Melo
Em Fri, Aug 21, 2015 at 12:21:25PM -0300, Arnaldo Carvalho de Melo escreveu:
 Em Fri, Aug 21, 2015 at 12:11:33PM -0300, Arnaldo Carvalho de Melo escreveu:
  [acme@zoo ~]$ perf script -s 
  ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
  branches calls
  2015-08-21 12:10:00.504126 Creating database...
  QSqlDatabase: QPSQL driver not loaded
  QSqlDatabase: available drivers: QSQLITE
  QSqlDatabase: an instance of QCoreApplication is required for loading 
  driver plugins
  QSqlQuery::exec: database not open
  Traceback (most recent call last):
File 
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, line 
  87, in module
  do_query(query, 'CREATE DATABASE ' + dbname)
File 
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py, line 
  78, in do_query
  raise Exception(Query failed:  + q.lastError().text())
  Exception: Query failed: Driver not loaded Driver not loaded
  Error running python script 
  /home/acme/libexec/perf-core/scripts/python/export-to-postgresql.py
  [acme@zoo ~]$ 
 
 A-ha, this was missing:
 
 [root@zoo ~]# rpm -ql qt-postgresql 
 /usr/lib64/qt4/plugins/sqldrivers/libqsqlpsql.so
 [root@zoo ~]#
 
 [acme@zoo ~]$ perf script -s 
 ~/libexec/perf-core/scripts/python/export-to-postgresql.py bts_example 
 branches calls
 2015-08-21 12:20:01.841677 Creating database...
 2015-08-21 12:20:02.556853 Writing to intermediate files...
 2015-08-21 12:20:03.262814 Copying to database...
 2015-08-21 12:20:03.783109 Removing intermediate files...
 2015-08-21 12:20:03.790282 Adding primary keys
 2015-08-21 12:20:04.294342 Adding foreign keys
 2015-08-21 12:20:04.718238 Done
 [acme@zoo ~]$ 
 
 Now to the next steps... Lets see how this looks like with BTS...

So, after running:

  [acme@zoo linux]$ python
  tools/perf/scripts/python/call-graph-from-postgresql.py bts_example

I got a GUI and after expanding some callchains I took this screenshot:

  http://vger.kernel.org/~acme/perf/call_graph_example_intel_bts.png

Cool stuff! But it seems the COMM got messed up? I.e. that 1380:1380
first level after ls.

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V8 10/25] perf tools: Add example call-graph script

2015-07-17 Thread Adrian Hunter
Add a script to produce a call-graph from data exported
to a postgresql database and derived from a processor trace
event like intel_pt or intel_bts. Refer to comments in the
scripts call-graph-from-postgresql.py and export-to-postgresql.py
for more details.

Signed-off-by: Adrian Hunter 
---
 .../scripts/python/call-graph-from-postgresql.py   | 327 +
 tools/perf/scripts/python/export-to-postgresql.py  |  47 +++
 2 files changed, 374 insertions(+)
 create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py

diff --git a/tools/perf/scripts/python/call-graph-from-postgresql.py 
b/tools/perf/scripts/python/call-graph-from-postgresql.py
new file mode 100644
index ..e78fdc2a5a9d
--- /dev/null
+++ b/tools/perf/scripts/python/call-graph-from-postgresql.py
@@ -0,0 +1,327 @@
+#!/usr/bin/python2
+# call-graph-from-postgresql.py: create call-graph from postgresql database
+# Copyright (c) 2014, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+
+# To use this script you will need to have exported data using the
+# export-to-postgresql.py script.  Refer to that script for details.
+#
+# Following on from the example in the export-to-postgresql.py script, a
+# call-graph can be displayed for the pt_example database like this:
+#
+#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
pt_example
+#
+# Note this script supports connecting to remote databases by setting hostname,
+# port, username, password, and dbname e.g.
+#
+#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
"hostname=myhost username=myuser password=mypassword dbname=pt_example"
+#
+# The result is a GUI window with a tree representing a context-sensitive
+# call-graph.  Expanding a couple of levels of the tree and adjusting column
+# widths to suit will display something like:
+#
+# Call Graph: pt_example
+# Call Path  Object  Count   Time(ns)  Time(%)  
Branch Count   Branch Count(%)
+# v- ls
+# v- 2638:2638
+# v- _start  ld-2.19.so1 10074071   100.0  
   211135100.0
+#   |- unknown   unknown   113198 0.1  
1  0.0
+#   >- _dl_start ld-2.19.so1  140098013.9  
19637  9.3
+#   >- _d_linit_internal ld-2.19.so1   448152 4.4  
11094  5.3
+#   v-__libc_start_main@plt  ls1  821174181.5  
   180397 85.4
+#  >- _dl_fixup  ld-2.19.so1 7607 0.1  
  108  0.1
+#  >- __cxa_atexit   libc-2.19.so  111737 0.1  
   10  0.0
+#  >- __libc_csu_initls110354 0.1  
   10  0.0
+#  |- _setjmplibc-2.19.so  10 0.0  
4  0.0
+#  v- main   ls1  818204399.6  
   180254 99.9
+#
+# Points to note:
+#  The top level is a command name (comm)
+#  The next level is a thread (pid:tid)
+#  Subsequent levels are functions
+#  'Count' is the number of calls
+#  'Time' is the elapsed time until the function returns
+#  Percentages are relative to the level above
+#  'Branch Count' is the total number of branches for that function and all
+#   functions that it calls
+
+import sys
+from PySide.QtCore import *
+from PySide.QtGui import *
+from PySide.QtSql import *
+from decimal import *
+
+class TreeItem():
+
+   def __init__(self, db, row, parent_item):
+   self.db = db
+   self.row = row
+   self.parent_item = parent_item
+   self.query_done = False;
+   self.child_count = 0
+   self.child_items = []
+   self.data = ["", "", "", "", "", "", ""]
+   self.comm_id = 0
+   self.thread_id = 0
+   self.call_path_id = 1
+   self.branch_count = 0
+   self.time = 0
+   if not parent_item:
+   self.setUpRoot()
+
+   def setUpRoot(self):
+   self.query_done = True
+   query = QSqlQuery(self.db)
+   ret = query.exec_('SELECT id, comm FROM comms')
+   if not ret:
+   raise Exception("Query failed: " + 
query.lastError().text())
+  

[PATCH V8 10/25] perf tools: Add example call-graph script

2015-07-17 Thread Adrian Hunter
Add a script to produce a call-graph from data exported
to a postgresql database and derived from a processor trace
event like intel_pt or intel_bts. Refer to comments in the
scripts call-graph-from-postgresql.py and export-to-postgresql.py
for more details.

Signed-off-by: Adrian Hunter adrian.hun...@intel.com
---
 .../scripts/python/call-graph-from-postgresql.py   | 327 +
 tools/perf/scripts/python/export-to-postgresql.py  |  47 +++
 2 files changed, 374 insertions(+)
 create mode 100644 tools/perf/scripts/python/call-graph-from-postgresql.py

diff --git a/tools/perf/scripts/python/call-graph-from-postgresql.py 
b/tools/perf/scripts/python/call-graph-from-postgresql.py
new file mode 100644
index ..e78fdc2a5a9d
--- /dev/null
+++ b/tools/perf/scripts/python/call-graph-from-postgresql.py
@@ -0,0 +1,327 @@
+#!/usr/bin/python2
+# call-graph-from-postgresql.py: create call-graph from postgresql database
+# Copyright (c) 2014, Intel Corporation.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+
+# To use this script you will need to have exported data using the
+# export-to-postgresql.py script.  Refer to that script for details.
+#
+# Following on from the example in the export-to-postgresql.py script, a
+# call-graph can be displayed for the pt_example database like this:
+#
+#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
pt_example
+#
+# Note this script supports connecting to remote databases by setting hostname,
+# port, username, password, and dbname e.g.
+#
+#  python tools/perf/scripts/python/call-graph-from-postgresql.py 
hostname=myhost username=myuser password=mypassword dbname=pt_example
+#
+# The result is a GUI window with a tree representing a context-sensitive
+# call-graph.  Expanding a couple of levels of the tree and adjusting column
+# widths to suit will display something like:
+#
+# Call Graph: pt_example
+# Call Path  Object  Count   Time(ns)  Time(%)  
Branch Count   Branch Count(%)
+# v- ls
+# v- 2638:2638
+# v- _start  ld-2.19.so1 10074071   100.0  
   211135100.0
+#   |- unknown   unknown   113198 0.1  
1  0.0
+#   - _dl_start ld-2.19.so1  140098013.9  
19637  9.3
+#   - _d_linit_internal ld-2.19.so1   448152 4.4  
11094  5.3
+#   v-__libc_start_main@plt  ls1  821174181.5  
   180397 85.4
+#  - _dl_fixup  ld-2.19.so1 7607 0.1  
  108  0.1
+#  - __cxa_atexit   libc-2.19.so  111737 0.1  
   10  0.0
+#  - __libc_csu_initls110354 0.1  
   10  0.0
+#  |- _setjmplibc-2.19.so  10 0.0  
4  0.0
+#  v- main   ls1  818204399.6  
   180254 99.9
+#
+# Points to note:
+#  The top level is a command name (comm)
+#  The next level is a thread (pid:tid)
+#  Subsequent levels are functions
+#  'Count' is the number of calls
+#  'Time' is the elapsed time until the function returns
+#  Percentages are relative to the level above
+#  'Branch Count' is the total number of branches for that function and all
+#   functions that it calls
+
+import sys
+from PySide.QtCore import *
+from PySide.QtGui import *
+from PySide.QtSql import *
+from decimal import *
+
+class TreeItem():
+
+   def __init__(self, db, row, parent_item):
+   self.db = db
+   self.row = row
+   self.parent_item = parent_item
+   self.query_done = False;
+   self.child_count = 0
+   self.child_items = []
+   self.data = [, , , , , , ]
+   self.comm_id = 0
+   self.thread_id = 0
+   self.call_path_id = 1
+   self.branch_count = 0
+   self.time = 0
+   if not parent_item:
+   self.setUpRoot()
+
+   def setUpRoot(self):
+   self.query_done = True
+   query = QSqlQuery(self.db)
+   ret = query.exec_('SELECT id, comm FROM comms')
+   if not ret:
+   raise Exception(Query failed:  + 
query.lastError().text())
+