2
* Copyright (C) 2009 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Gord Allott <gord.allott@canonical.com>
23
public class ProcessInfo
25
public ProcessInfo (string name)
36
public TimelineLogger? timeline_singleton;
38
public class TimelineLogger : Object
40
private Timer global_timer;
41
private Gee.HashMap<string, ProcessInfo> process_map;
43
public static unowned Unity.TimelineLogger get_default ()
45
if (Unity.timeline_singleton == null)
47
Unity.timeline_singleton = new Unity.TimelineLogger ();
50
return Unity.timeline_singleton;
55
this.process_map = new Gee.HashMap<string, ProcessInfo> ();
56
this.global_timer = new Timer ();
57
this.global_timer.start ();
60
public void start_process (string name)
62
if (name in this.process_map.keys)
64
warning ("already started process: %s", name);
68
var info = new ProcessInfo (name);
69
this.process_map[name] = info;
70
info.start = this.global_timer.elapsed ();
73
public void end_process (string name)
75
double end_time = this.global_timer.elapsed ();
77
if (name in this.process_map.keys)
79
this.process_map[name].end = end_time;
83
warning ("process %s not started", name);
87
public void write_log (string filename)
89
debug ("Writing performance log file: %s...", filename);
90
var log_file = File.new_for_path (filename);
91
FileOutputStream file_stream;
94
if (!log_file.query_exists (null)) {
95
file_stream = log_file.create (FileCreateFlags.NONE, null);
99
file_stream = log_file.replace (null, false, FileCreateFlags.NONE, null);
102
var output_stream = new DataOutputStream (file_stream);
104
foreach (ProcessInfo info in this.process_map.values)
106
string outline = "%s, %f, %f\n".printf(info.name, info.start, info.end);
107
output_stream.put_string (outline, null);