~mterry/qtmir/warn-on-xapp

« back to all changes in this revision

Viewing changes to benchmarks/report_types.py

  • Committer: Nick Dedekind
  • Date: 2015-09-01 16:16:47 UTC
  • mto: (381.1.6 wheelEvent)
  • mto: This revision was merged to the branch mainline in revision 395.
  • Revision ID: nick.dedekind@canonical.com-20150901161647-829z580lczgu0i1l
touch events tracepoints

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Copyright (C) 2015 Canonical Ltd.
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
 
 
17
import subprocess
 
18
import os
 
19
import shutil
 
20
 
 
21
class Node:
 
22
    def __init__(self, name):
 
23
        self.name = name
 
24
        self.children = []
 
25
    
 
26
    def add_child(self, child):
 
27
        self.children.append(child)
 
28
 
 
29
    def to_string(self):
 
30
        output = "<%s>" % self.name
 
31
        for child in self.children:
 
32
            output += child.to_string()
 
33
        output += "</%s>" % self.name
 
34
        return output
 
35
 
 
36
class Results(Node):
 
37
    def __init__(self):
 
38
        super().__init__("results")
 
39
 
 
40
class Events(Node):
 
41
    def __init__(self):
 
42
        super().__init__("events")
 
43
 
 
44
class Event:
 
45
    def __init__(self, event):
 
46
        self.pid = event["vpid"]
 
47
        self.name = event.name
 
48
        self.timestamp = event.timestamp
 
49
 
 
50
    def to_string(self):
 
51
        output = "<event "
 
52
        output += "pid='{}' ".format(self.pid)
 
53
        output += "name='{}' ".format(self.name)
 
54
        output += "timestamp='{}' ".format(self.timestamp)
 
55
        output += "/>"
 
56
        return output
 
57
 
 
58
class Processes(Node):
 
59
    def __init__(self):
 
60
        super().__init__("processes")
 
61
 
 
62
class Process:
 
63
    def __init__(self, name, pid):
 
64
        self.name = name
 
65
        self.pid = pid
 
66
 
 
67
    def to_string(self):
 
68
        output = "<process "
 
69
        output += "name='{}' ".format(self.name)
 
70
        output += "pid='{}' ".format(self.pid)
 
71
        output += "/>"
 
72
        return output
 
73
 
 
74
class ResultsData:
 
75
    def __init__(self, name, mean=0.0, deviation=0.0, comment=""):
 
76
        self.data = []
 
77
        self.name = name
 
78
        self.mean = mean
 
79
        self.deviation = deviation
 
80
        self.comment = comment
 
81
 
 
82
    def add_data(self, value):
 
83
        self.data.append(value)
 
84
 
 
85
    def to_string(self):
 
86
        output = "<data name='{}' mean='{}' deviation='{}' comment='{}' count='{}'>".format(
 
87
            self.name,
 
88
            self.mean,
 
89
            self.deviation, 
 
90
            self.comment, 
 
91
            len(self.data))
 
92
        output += "<values>"
 
93
        output += ",".join(map( lambda x: str(x), self.data))
 
94
        output += "</values>"
 
95
        output += "</data>"
 
96
        return output;
 
97
 
 
98
    def generate_histogram(self, filename):
 
99
        cmdline = [
 
100
            shutil.which("Rscript"),
 
101
            os.path.split(os.path.abspath(__file__))[0] + "/touch_event_latency.R",
 
102
            "data.csv",
 
103
            "%s.png" % filename]
 
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)));
 
107
        f.close()
 
108
        process = subprocess.Popen(cmdline)
 
109
        process.wait()
 
110
        if process.returncode != 0:
 
111
            print("Failed to generate histogram");
 
112
        os.remove("data.csv")
 
113
 
 
114
 
 
115
class Error:    
 
116
    def __init__(self, comment):
 
117
        self.comment = comment
 
118
 
 
119
    def to_string(self):
 
120
        return "<error comment='{}' />".format(self.comment)
 
121
        return output
 
 
b'\\ No newline at end of file'