4
A library to communicate a menu object set accross DBus and
5
track updates and maintain consistency.
7
Copyright 2010 Canonical Ltd.
10
Aurélien Gâteau <aurelien.gateau@canonical.com>
12
This program is free software: you can redistribute it and/or modify it
13
under the terms of either or both of the following licenses:
15
1) the GNU Lesser General Public License version 3, as published by the
16
Free Software Foundation; and/or
17
2) the GNU Lesser General Public License version 2.1, as published by
18
the Free Software Foundation.
20
This program is distributed in the hope that it will be useful, but
21
WITHOUT ANY WARRANTY; without even the implied warranties of
22
MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
23
PURPOSE. See the applicable version of the GNU Lesser General Public
24
License for more details.
26
You should have received a copy of both the GNU Lesser General Public
27
License version 3 and version 2.1 along with this program. If not, see
28
<http://www.gnu.org/licenses/>
33
from optparse import OptionParser
34
from xml.etree import ElementTree as ET
38
DBUS_INTERFACE = "org.ayatana.dbusmenu"
39
DBUS_SERVICE = "org.dbusmenu.test"
40
DBUS_PATH = "/MenuBar"
42
PROBE_GET_LAYOUT = "GetLayout"
43
PROBE_GET_PROPERTIES = "GetProperties"
44
PROBE_GET_CHILDREN = "GetChildren"
45
PROBES = PROBE_GET_LAYOUT, PROBE_GET_PROPERTIES, PROBE_GET_CHILDREN
53
new_time = time.time()
54
delta = new_time - self._time
59
return time.time() - self._time
62
def dump_properties(properties, prepend=""):
63
for key, value in properties.items():
64
print "%s- %s: %s" % (prepend, key, value)
67
def run_test_sequence(menu, dump=False):
69
Runs the test sequence and returns a dict of method_name: seconds
71
property_names = ["type", "label", "enabled", "icon-name"]
74
revision, layout = menu.GetLayout(dbus.Int32(0))
75
times["GetLayout"] = chrono.elapsed()
77
print "revision:", revision
82
tree = ET.fromstring(layout)
83
root_id = int(tree.attrib["id"])
84
child_element = tree.find("menu")
85
assert child_element is not None
86
child_id = int(child_element.attrib["id"])
89
children = menu.GetChildren(dbus.Int32(root_id), property_names)
90
times["GetChildren"] = chrono.elapsed()
93
for child in children:
94
id, properties = child
96
dump_properties(properties, prepend=" ")
99
properties = menu.GetProperties(dbus.Int32(child_id), property_names)
100
times["GetProperties"] = chrono.elapsed()
103
dump_properties(properties)
107
def create_timing_dict():
108
return dict(zip(PROBES, itertools.repeat(0)))
110
def print_probe(prefix, name, value, timestamp):
111
value = int(value * 1000000)
112
print "%(prefix)s.%(name)s:%(value)d@%(timestamp)d" % locals()
115
parser = OptionParser(usage = "%prog [options]")
117
parser.add_option("-c", "--count", dest="count", type=int, default=1,
118
help="repeat calls COUNT times", metavar="COUNT")
119
parser.add_option("-d", "--dump", dest="dump", action="store_true", default=False,
120
help="dump call output to stdout")
122
(options, args) = parser.parse_args()
124
bus = dbus.SessionBus()
125
proxy = bus.get_object(DBUS_SERVICE, DBUS_PATH)
126
menu = dbus.Interface(proxy, dbus_interface=DBUS_INTERFACE)
129
run_test_sequence(menu, dump=True)
132
cumulated_timings = create_timing_dict()
133
min_timings = create_timing_dict()
134
max_timings = create_timing_dict()
135
for x in range(options.count):
136
timings = run_test_sequence(menu)
137
for name, timing in timings.items():
138
cumulated_timings[name] += timing
139
if min_timings[name] == 0 or min_timings[name] > timing:
140
min_timings[name] = timing
141
if max_timings[name] < timing:
142
max_timings[name] = timing
144
timestamp = int(time.time())
145
for name, timing in cumulated_timings.items():
146
print_probe("average", name, timing / options.count, timestamp)
147
for name, timing in min_timings.items():
148
print_probe("min", name, timing, timestamp)
149
for name, timing in max_timings.items():
150
print_probe("max", name, timing, timestamp)
155
if __name__=="__main__":
157
# vi: ts=4 sw=4 et tw=0