1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2015 Canonical Ltd.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License as published by
7
# the Free Software Foundation; version 3.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
def __init__(self, name):
26
def add_child(self, child):
27
self.children.append(child)
30
output = "<%s>" % self.name
31
for child in self.children:
32
output += child.to_string()
33
output += "</%s>" % self.name
38
super().__init__("results")
42
super().__init__("events")
45
def __init__(self, event):
46
self.pid = event["vpid"]
47
self.name = event.name
48
self.timestamp = event.timestamp
52
output += "pid='{}' ".format(self.pid)
53
output += "name='{}' ".format(self.name)
54
output += "timestamp='{}' ".format(self.timestamp)
58
class Processes(Node):
60
super().__init__("processes")
63
def __init__(self, name, pid):
69
output += "name='{}' ".format(self.name)
70
output += "pid='{}' ".format(self.pid)
75
def __init__(self, name, mean=0.0, deviation=0.0, comment=""):
79
self.deviation = deviation
80
self.comment = comment
82
def add_data(self, value):
83
self.data.append(value)
86
output = "<data name='{}' mean='{}' deviation='{}' comment='{}' count='{}'>".format(
93
output += ",".join(map( lambda x: str(x), self.data))
98
def generate_histogram(self, filename):
100
shutil.which("Rscript"),
101
os.path.split(os.path.abspath(__file__))[0] + "/touch_event_latency.R",
104
# Use R to generate a histogram plot
105
f = open("data.csv", "w")
106
f.write(",".join(map( lambda x: str(x), self.data)));
108
process = subprocess.Popen(cmdline)
110
if process.returncode != 0:
111
print("Failed to generate histogram");
112
os.remove("data.csv")
116
def __init__(self, comment):
117
self.comment = comment
120
return "<error comment='{}' />".format(self.comment)
b'\\ No newline at end of file'