1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2015 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import subprocess
import os
import shutil
class Node:
def __init__(self, name):
self.name = name
self.children = []
def add_child(self, child):
self.children.append(child)
def to_string(self):
output = "<%s>" % self.name
for child in self.children:
output += child.to_string()
output += "</%s>" % self.name
return output
class Results(Node):
def __init__(self):
super().__init__("results")
class Events(Node):
def __init__(self):
super().__init__("events")
class Event:
def __init__(self, event):
self.pid = event["vpid"]
self.name = event.name
self.timestamp = event.timestamp
def to_string(self):
output = "<event "
output += "pid='{}' ".format(self.pid)
output += "name='{}' ".format(self.name)
output += "timestamp='{}' ".format(self.timestamp)
output += "/>"
return output
class Processes(Node):
def __init__(self):
super().__init__("processes")
class Process:
def __init__(self, name, pid):
self.name = name
self.pid = pid
def to_string(self):
output = "<process "
output += "name='{}' ".format(self.name)
output += "pid='{}' ".format(self.pid)
output += "/>"
return output
class ResultsData:
def __init__(self, name, mean=0.0, deviation=0.0, comment=""):
self.data = []
self.name = name
self.mean = mean
self.deviation = deviation
self.comment = comment
def add_data(self, value):
self.data.append(value)
def to_string(self):
output = "<data name='{}' mean='{}' deviation='{}' comment='{}' count='{}'>".format(
self.name,
self.mean,
self.deviation,
self.comment,
len(self.data))
output += "<values>"
output += ",".join(map( lambda x: str(x), self.data))
output += "</values>"
output += "</data>"
return output;
def generate_histogram(self, filename):
cmdline = [
shutil.which("Rscript"),
os.path.split(os.path.abspath(__file__))[0] + "/touch_event_latency.R",
"data.csv",
"%s.png" % filename]
# Use R to generate a histogram plot
f = open("data.csv", "w")
f.write(",".join(map( lambda x: str(x), self.data)));
f.close()
process = subprocess.Popen(cmdline)
process.wait()
if process.returncode != 0:
print("Failed to generate histogram");
os.remove("data.csv")
class Error:
def __init__(self, comment):
self.comment = comment
def to_string(self):
return "<error comment='{}' />".format(self.comment)
return output
|