diff options
Diffstat (limited to 'tools/perf/scripts/python')
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 | # | ||
| 8 | perf 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] | ||
| 4 | n_args=0 | ||
| 5 | for i in "$@" | ||
| 6 | do | ||
| 7 | if expr match "$i" "-" > /dev/null ; then | ||
| 8 | break | ||
| 9 | fi | ||
| 10 | n_args=$(( $n_args + 1 )) | ||
| 11 | done | ||
| 12 | if [ "$n_args" -gt 2 ] ; then | ||
| 13 | echo "usage: export-to-postgresql-report [database name] [columns]" | ||
| 14 | exit | ||
| 15 | fi | ||
| 16 | if [ "$n_args" -gt 1 ] ; then | ||
| 17 | dbname=$1 | ||
| 18 | columns=$2 | ||
| 19 | shift 2 | ||
| 20 | elif [ "$n_args" -gt 0 ] ; then | ||
| 21 | dbname=$1 | ||
| 22 | shift | ||
| 23 | fi | ||
| 24 | perf 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 | |||
| 13 | import os | ||
| 14 | import sys | ||
| 15 | import struct | ||
| 16 | import datetime | ||
| 17 | |||
| 18 | from PySide.QtSql import * | ||
| 19 | |||
| 20 | # Need to access PostgreSQL C library directly to use COPY FROM STDIN | ||
| 21 | from ctypes import * | ||
| 22 | libpq = CDLL("libpq.so.5") | ||
| 23 | PQconnectdb = libpq.PQconnectdb | ||
| 24 | PQconnectdb.restype = c_void_p | ||
| 25 | PQfinish = libpq.PQfinish | ||
| 26 | PQstatus = libpq.PQstatus | ||
| 27 | PQexec = libpq.PQexec | ||
| 28 | PQexec.restype = c_void_p | ||
| 29 | PQresultStatus = libpq.PQresultStatus | ||
| 30 | PQputCopyData = libpq.PQputCopyData | ||
| 31 | PQputCopyData.argtypes = [ c_void_p, c_void_p, c_int ] | ||
| 32 | PQputCopyEnd = libpq.PQputCopyEnd | ||
| 33 | PQputCopyEnd.argtypes = [ c_void_p, c_void_p ] | ||
| 34 | |||
| 35 | sys.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 | |||
| 42 | perf_db_export_mode = True | ||
| 43 | |||
| 44 | def 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 | |||
| 49 | if (len(sys.argv) < 2): | ||
| 50 | usage() | ||
| 51 | |||
| 52 | dbname = sys.argv[1] | ||
| 53 | |||
| 54 | if (len(sys.argv) >= 3): | ||
| 55 | columns = sys.argv[2] | ||
| 56 | else: | ||
| 57 | columns = "all" | ||
| 58 | |||
| 59 | if columns not in ("all", "branches"): | ||
| 60 | usage() | ||
| 61 | |||
| 62 | branches = (columns == "branches") | ||
| 63 | |||
| 64 | output_dir_name = os.getcwd() + "/" + dbname + "-perf-data" | ||
| 65 | os.mkdir(output_dir_name) | ||
| 66 | |||
| 67 | def do_query(q, s): | ||
| 68 | if (q.exec_(s)): | ||
| 69 | return | ||
| 70 | raise Exception("Query failed: " + q.lastError().text()) | ||
| 71 | |||
| 72 | print datetime.datetime.today(), "Creating database..." | ||
| 73 | |||
| 74 | db = QSqlDatabase.addDatabase('QPSQL') | ||
| 75 | query = QSqlQuery(db) | ||
| 76 | db.setDatabaseName('postgres') | ||
| 77 | db.open() | ||
| 78 | try: | ||
| 79 | do_query(query, 'CREATE DATABASE ' + dbname) | ||
| 80 | except: | ||
| 81 | os.rmdir(output_dir_name) | ||
| 82 | raise | ||
| 83 | query.finish() | ||
| 84 | query.clear() | ||
| 85 | db.close() | ||
| 86 | |||
| 87 | db.setDatabaseName(dbname) | ||
| 88 | db.open() | ||
| 89 | |||
| 90 | query = QSqlQuery(db) | ||
| 91 | do_query(query, 'SET client_min_messages TO WARNING') | ||
| 92 | |||
| 93 | do_query(query, 'CREATE TABLE selected_events (' | ||
| 94 | 'id bigint NOT NULL,' | ||
| 95 | 'name varchar(80))') | ||
| 96 | do_query(query, 'CREATE TABLE machines (' | ||
| 97 | 'id bigint NOT NULL,' | ||
| 98 | 'pid integer,' | ||
| 99 | 'root_dir varchar(4096))') | ||
| 100 | do_query(query, 'CREATE TABLE threads (' | ||
| 101 | 'id bigint NOT NULL,' | ||
| 102 | 'machine_id bigint,' | ||
| 103 | 'process_id bigint,' | ||
| 104 | 'pid integer,' | ||
| 105 | 'tid integer)') | ||
| 106 | do_query(query, 'CREATE TABLE comms (' | ||
| 107 | 'id bigint NOT NULL,' | ||
| 108 | 'comm varchar(16))') | ||
| 109 | do_query(query, 'CREATE TABLE comm_threads (' | ||
| 110 | 'id bigint NOT NULL,' | ||
| 111 | 'comm_id bigint,' | ||
| 112 | 'thread_id bigint)') | ||
| 113 | do_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))') | ||
| 119 | do_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))') | ||
| 126 | if 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)') | ||
| 143 | else: | ||
| 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,' | ||
