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
122
123
124
125
126
127
|
/* benchmark.vala
*
* Copyright © 2011 Collabora Ltd.
* By Seif Lotfy <seif@lotfy.com>
*
* 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, either version 2.1 of the License, or
* (at your option) any later version.
*
* 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 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/>.
*
*/
namespace Zeitgeist
{
[DBus (name = "org.gnome.zeitgeist.Benchmark")]
public interface RemoteBenchmarker: Object
{
public abstract async HashTable<string, Variant> find_events (
[DBus (signature = "(xx)")] Variant time_range,
[DBus (signature = "a(asaasay)")] Variant event_templates,
uint storage_state, uint num_events, uint result_type)
throws Error;
}
class Benchmarker: Extension, RemoteBenchmarker
{
private uint registration_id;
Benchmarker ()
{
Object ();
}
construct
{
try
{
var connection = Bus.get_sync (BusType.SESSION, null);
registration_id = connection.register_object<RemoteBenchmarker> (
"/org/gnome/zeitgeist/benchmark", this);
}
catch (Error err)
{
warning ("%s", err.message);
}
}
public async HashTable<string, Variant> find_events (Variant time_range,
Variant filter_templates, uint storage_state, uint num_events,
uint result_type)
throws Error
{
var data = new HashTable<string, Variant> (str_hash, str_equal);
var find_event_ids_timer = new Timer ();
var ids = engine.find_event_ids (
new TimeRange.from_variant (time_range),
Events.from_variant (filter_templates),
storage_state, num_events, result_type);
var find_event_ids_elapsed = find_event_ids_timer.elapsed();
var get_events_timer = new Timer ();
var events = engine.get_events (ids);
var get_events_elapsed = get_events_timer.elapsed();
var marsh_events_timer = new Timer ();
var marsh_events = Events.to_variant(events);
var marsh_events_elapsed = marsh_events_timer.elapsed();
var find_events_elapsed = get_events_elapsed + find_event_ids_elapsed + marsh_events_elapsed;
data.insert("find_event_ids",
new Variant.double(find_event_ids_elapsed));
data.insert("get_events",
new Variant.double(get_events_elapsed));
data.insert("find_events",
new Variant.double(find_events_elapsed));
data.insert("marsh_events",
new Variant.double(marsh_events_elapsed));
data.insert("events", marsh_events);
return data;
}
public override void unload ()
{
try
{
var connection = Bus.get_sync (BusType.SESSION, null);
if (registration_id != 0)
{
connection.unregister_object (registration_id);
registration_id = 0;
}
}
catch (Error err)
{
warning ("%s", err.message);
}
debug ("%s, this.ref_count = %u", Log.METHOD, this.ref_count);
}
}
[ModuleInit]
#if BUILTIN_EXTENSIONS
public static Type benchmark_init (TypeModule module)
{
#else
public static Type extension_register (TypeModule module)
{
#endif
return typeof (Benchmarker);
}
}
// vim:expandtab:ts=4:sw=4
|