aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/scripts/python')
-rw-r--r--tools/perf/scripts/python/bin/export-to-postgresql-record8
-rw-r--r--tools/perf/scripts/python/bin/export-to-postgresql-report24
-rw-r--r--tools/perf/scripts/python/export-to-postgresql.py360
3 files changed, 392 insertions, 0 deletions
diff --git a/tools/perf/scripts/python/bin/export-to-postgresql-record b/tools/perf/scripts/python/bin/export-to-postgresql-record
new file mode 100644
index 000000000000..221d66e05713
--- /dev/null
+++ b/tools/perf/scripts/python/bin/export-to-postgresql-record
@@ -0,0 +1,8 @@
1#!/bin/bash
2
3#
4# export perf data to a postgresql database. Can cover
5# perf ip samples (excluding the tracepoints). No special
6# record requirements, just record what you want to export.
7#
8perf record $@
diff --git a/tools/perf/scripts/python/bin/export-to-postgresql-report b/tools/perf/scripts/python/bin/export-to-postgresql-report
new file mode 100644
index 000000000000..a8fdd15f85bf
--- /dev/null
+++ b/tools/perf/scripts/python/bin/export-to-postgresql-report
@@ -0,0 +1,24 @@
1#!/bin/bash
2# description: export perf data to a postgresql database
3# args: [database name] [columns]
4n_args=0
5for i in "$@"
6do
7 if expr match "$i" "-" > /dev/null ; then
8 break
9 fi
10 n_args=$(( $n_args + 1 ))
11done
12if [ "$n_args" -gt 2 ] ; then
13 echo "usage: export-to-postgresql-report [database name] [columns]"
14 exit
15fi
16if [ "$n_args" -gt 1 ] ; then
17 dbname=$1
18 columns=$2
19 shift 2
20elif [ "$n_args" -gt 0 ] ; then
21 dbname=$1
22 shift
23fi
24perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/export-to-postgresql.py $dbname $columns
diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
new file mode 100644
index 000000000000..d8f6df0093d6
--- /dev/null
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -0,0 +1,360 @@
1# export-to-postgresql.py: export perf data to a postgresql database
2# Copyright (c) 2014, Intel Corporation.
3#
4# This program is free software; you can redistribute it and/or modify it
5# under the terms and conditions of the GNU General Public License,
6# version 2, as published by the Free Software Foundation.
7#
8# This program is distributed in the hope it will be useful, but WITHOUT
9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11# more details.
12
13import os
14import sys
15import struct
16import datetime
17
18from PySide.QtSql import *
19
20# Need to access PostgreSQL C library directly to use COPY FROM STDIN
21from ctypes import *
22libpq = CDLL("libpq.so.5")
23PQconnectdb = libpq.PQconnectdb
24PQconnectdb.restype = c_void_p
25PQfinish = libpq.PQfinish
26PQstatus = libpq.PQstatus
27PQexec = libpq.PQexec
28PQexec.restype = c_void_p
29PQresultStatus = libpq.PQresultStatus
30PQputCopyData = libpq.PQputCopyData
31PQputCopyData.argtypes = [ c_void_p, c_void_p, c_int ]
32PQputCopyEnd = libpq.PQputCopyEnd
33PQputCopyEnd.argtypes = [ c_void_p, c_void_p ]
34
35sys.path.append(os.environ['PERF_EXEC_PATH'] + \
36 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
37
38# These perf imports are not used at present
39#from perf_trace_context import *
40#from Core import *
41
42perf_db_export_mode = True
43
44def usage():
45 print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>]"
46 print >> sys.stderr, "where: columns 'all' or 'branches'"
47 raise Exception("Too few arguments")
48
49if (len(sys.argv) < 2):
50 usage()
51
52dbname = sys.argv[1]
53
54if (len(sys.argv) >= 3):
55 columns = sys.argv[2]
56else:
57 columns = "all"
58
59if columns not in ("all", "branches"):
60 usage()
61
62branches = (columns == "branches")
63
64output_dir_name = os.getcwd() + "/" + dbname + "-perf-data"
65os.mkdir(output_dir_name)
66
67def do_query(q, s):
68 if (q.exec_(s)):
69 return
70 raise Exception("Query failed: " + q.lastError().text())
71
72print datetime.datetime.today(), "Creating database..."
73
74db = QSqlDatabase.addDatabase('QPSQL')
75query = QSqlQuery(db)
76db.setDatabaseName('postgres')
77db.open()
78try:
79 do_query(query, 'CREATE DATABASE ' + dbname)
80except:
81 os.rmdir(output_dir_name)
82 raise
83query.finish()
84query.clear()
85db.close()
86
87db.setDatabaseName(dbname)
88db.open()
89
90query = QSqlQuery(db)
91do_query(query, 'SET client_min_messages TO WARNING')
92
93do_query(query, 'CREATE TABLE selected_events ('
94 'id bigint NOT NULL,'
95 'name varchar(80))')
96do_query(query, 'CREATE TABLE machines ('
97 'id bigint NOT NULL,'
98 'pid integer,'
99 'root_dir varchar(4096))')
100do_query(query, 'CREATE TABLE threads ('
101 'id bigint NOT NULL,'
102 'machine_id bigint,'
103 'process_id bigint,'
104 'pid integer,'
105 'tid integer)')
106do_query(query, 'CREATE TABLE comms ('
107 'id bigint NOT NULL,'
108 'comm varchar(16))')
109do_query(query, 'CREATE TABLE comm_threads ('
110 'id bigint NOT NULL,'
111 'comm_id bigint,'
112 'thread_id bigint)')
113do_query(query, 'CREATE TABLE dsos ('
114 'id bigint NOT NULL,'
115 'machine_id bigint,'
116 'short_name varchar(256),'
117 'long_name varchar(4096),'
118 'build_id varchar(64))')
119do_query(query, 'CREATE TABLE symbols ('
120 'id bigint NOT NULL,'
121 'dso_id bigint,'
122 'sym_start bigint,'
123 'sym_end bigint,'
124 'binding integer,'
125 'name varchar(2048))')
126if branches:
127 do_query(query, 'CREATE TABLE samples ('
128 'id bigint NOT NULL,'
129 'evsel_id bigint,'
130 'machine_id bigint,'
131 'thread_id bigint,'
132 'comm_id bigint,'
133 'dso_id bigint,'
134 'symbol_id bigint,'
135 'sym_offset bigint,'
136 'ip bigint,'
137 'time bigint,'
138 'cpu integer,'
139 'to_dso_id bigint,'
140 'to_symbol_id bigint,'
141 'to_sym_offset bigint,'
142 'to_ip bigint)')
143else:
144 do_query(query, 'CREATE TABLE samples ('
145 'id bigint NOT NULL,'
146 'evsel_id bigint,'
147 'machine_id bigint,'
148 'thread_id bigint,'
149 'comm_id bigint,'
150 'dso_id bigint,'
151 'symbol_id bigint,'
152 'sym_offset bigint,'
153 'ip bigint,'
154 'time bigint,'
155 'cpu integer,'
156 'to_dso_id bigint,'
157 'to_symbol_id bigint,'
158 'to_sym_offset bigint,'