diff options
| author | Adrian Hunter <adrian.hunter@intel.com> | 2018-10-01 02:28:44 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-10-23 13:25:42 -0400 |
| commit | 4be9ace7e1cdcb44c1fba1fb41ec2b92dda06732 (patch) | |
| tree | 9f709667cbc167da898ca862e75f4e1684b29b33 /tools/perf/scripts/python | |
| parent | 70d831e85c1bdd87d193e85666bf3aa39aab7f21 (diff) | |
perf scripts python: call-graph-from-sql.py: Add data helper functions
Add helper functions for a few common cases.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20181001062853.28285-11-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts/python')
| -rw-r--r-- | tools/perf/scripts/python/call-graph-from-sql.py | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/tools/perf/scripts/python/call-graph-from-sql.py b/tools/perf/scripts/python/call-graph-from-sql.py index ada486048ad8..7f2eabe7dacd 100644 --- a/tools/perf/scripts/python/call-graph-from-sql.py +++ b/tools/perf/scripts/python/call-graph-from-sql.py | |||
| @@ -52,6 +52,28 @@ from PySide.QtGui import * | |||
| 52 | from PySide.QtSql import * | 52 | from PySide.QtSql import * |
| 53 | from decimal import * | 53 | from decimal import * |
| 54 | 54 | ||
| 55 | # Data formatting helpers | ||
| 56 | |||
| 57 | def dsoname(name): | ||
| 58 | if name == "[kernel.kallsyms]": | ||
| 59 | return "[kernel]" | ||
| 60 | return name | ||
| 61 | |||
| 62 | # Percent to one decimal place | ||
| 63 | |||
| 64 | def PercentToOneDP(n, d): | ||
| 65 | if not d: | ||
| 66 | return "0.0" | ||
| 67 | x = (n * Decimal(100)) / d | ||
| 68 | return str(x.quantize(Decimal(".1"), rounding=ROUND_HALF_UP)) | ||
| 69 | |||
| 70 | # Helper for queries that must not fail | ||
| 71 | |||
| 72 | def QueryExec(query, stmt): | ||
| 73 | ret = query.exec_(stmt) | ||
| 74 | if not ret: | ||
| 75 | raise Exception("Query failed: " + query.lastError().text()) | ||
| 76 | |||
| 55 | class TreeItem(): | 77 | class TreeItem(): |
| 56 | 78 | ||
| 57 | def __init__(self, db, row, parent_item): | 79 | def __init__(self, db, row, parent_item): |
| @@ -73,9 +95,7 @@ class TreeItem(): | |||
| 73 | def setUpRoot(self): | 95 | def setUpRoot(self): |
| 74 | self.query_done = True | 96 | self.query_done = True |
| 75 | query = QSqlQuery(self.db) | 97 | query = QSqlQuery(self.db) |
| 76 | ret = query.exec_('SELECT id, comm FROM comms') | 98 | QueryExec(query, 'SELECT id, comm FROM comms') |
| 77 | if not ret: | ||
| 78 | raise Exception("Query failed: " + query.lastError().text()) | ||
| 79 | while query.next(): | 99 | while query.next(): |
| 80 | if not query.value(0): | 100 | if not query.value(0): |
| 81 | continue | 101 | continue |
| @@ -91,9 +111,7 @@ class TreeItem(): | |||
| 91 | self.child_items = [] | 111 | self.child_items = [] |
| 92 | self.child_count = 0 | 112 | self.child_count = 0 |
| 93 | query = QSqlQuery(self.db) | 113 | query = QSqlQuery(self.db) |
| 94 | ret = query.exec_('SELECT thread_id, ( SELECT pid FROM threads WHERE id = thread_id ), ( SELECT tid FROM threads WHERE id = thread_id ) FROM comm_threads WHERE comm_id = ' + str(comm_id)) | 114 | QueryExec(query, 'SELECT thread_id, ( SELECT pid FROM threads WHERE id = thread_id ), ( SELECT tid FROM threads WHERE id = thread_id ) FROM comm_threads WHERE comm_id = ' + str(comm_id)) |
| 95 | if not ret: | ||
| 96 | raise Exception("Query failed: " + query.lastError().text()) | ||
| 97 | while query.next(): | 115 | while query.next(): |
| 98 | child_item = TreeItem(self.db, self.child_count, self) | 116 | child_item = TreeItem(self.db, self.child_count, self) |
| 99 | self.child_items.append(child_item) | 117 | self.child_items.append(child_item) |
| @@ -114,18 +132,6 @@ class TreeItem(): | |||
| 114 | def getRow(self): | 132 | def getRow(self): |
| 115 | return self.row | 133 | return self.row |
| 116 | 134 | ||
| 117 | def timePercent(self, b): | ||
| 118 | if not self.time: | ||
| 119 | return "0.0" | ||
| 120 | x = (b * Decimal(100)) / self.time | ||
| 121 | return str(x.quantize(Decimal('.1'), rounding=ROUND_HALF_UP)) | ||
| 122 | |||
| 123 | def branchPercent(self, b): | ||
| 124 | if not self.branch_count: | ||
| 125 | return "0.0" | ||
| 126 | x = (b * Decimal(100)) / self.branch_count | ||
| 127 | return str(x.quantize(Decimal('.1'), rounding=ROUND_HALF_UP)) | ||
| 128 | |||
| 129 | def addChild(self, call_path_id, name, dso, count, time, branch_count): | 135 | def addChild(self, call_path_id, name, dso, count, time, branch_count): |
| 130 | child_item = TreeItem(self.db, self.child_count, self) | 136 | child_item = TreeItem(self.db, self.child_count, self) |
| 131 | child_item.comm_id = self.comm_id | 137 | child_item.comm_id = self.comm_id |
| @@ -134,14 +140,12 @@ class TreeItem(): | |||
| 134 | child_item.branch_count = branch_count | 140 | child_item.branch_count = branch_count |
| 135 | child_item.time = time | 141 | child_item.time = time |
| 136 | child_item.data[0] = name | 142 | child_item.data[0] = name |
| 137 | if dso == "[kernel.kallsyms]": | 143 | child_item.data[1] = dsoname(dso) |
| 138 | dso = "[kernel]" | ||
| 139 | child_item.data[1] = dso | ||
| 140 | child_item.data[2] = str(count) | 144 | child_item.data[2] = str(count) |
| 141 | child_item.data[3] = str(time) | 145 | child_item.data[3] = str(time) |
| 142 | child_item.data[4] = self.timePercent(time) | 146 | child_item.data[4] = PercentToOneDP(time, self.time) |
| 143 | child_item.data[5] = str(branch_count) | 147 | child_item.data[5] = str(branch_count) |
| 144 | child_item.data[6] = self.branchPercent(branch_count) | 148 | child_item.data[6] = PercentToOneDP(branch_count, self.branch_count) |
| 145 | self.child_items.append(child_item) | 149 | self.child_items.append(child_item) |
| 146 | self.child_count += 1 | 150 | self.child_count += 1 |
| 147 | 151 | ||
| @@ -189,12 +193,12 @@ class TreeItem(): | |||
| 189 | self.branch_count = total_branch_count | 193 | self.branch_count = total_branch_count |
| 190 | if self.branch_count: | 194 | if self.branch_count: |
| 191 | for child_item in self.child_items: | 195 | for child_item in self.child_items: |
| 192 | child_item.data[6] = self.branchPercent(child_item.branch_count) | 196 | child_item.data[6] = PercentToOneDP(child_item.branch_count, self.branch_count) |
| 193 | if total_time > self.time: | 197 | if total_time > self.time: |
| 194 | self.time = total_time | 198 | self.time = total_time |
| 195 | if self.time: | 199 | if self.time: |
| 196 | for child_item in self.child_items: | 200 | for child_item in self.child_items: |
| 197 | child_item.data[4] = self.timePercent(child_item.time) | 201 | child_item.data[4] = PercentToOneDP(child_item.time, self.time) |
| 198 | 202 | ||
| 199 | def childCount(self): | 203 | def childCount(self): |
| 200 | if not self.query_done: | 204 | if not self.query_done: |
