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 static TimelineLogger? timeline_singleton;
37
public static bool is_logging;
39
public class TimelineLogger : Object
41
private Timer global_timer;
42
private Gee.HashMap<string, ProcessInfo> process_map;
44
public static unowned Unity.TimelineLogger get_default ()
46
if (Unity.timeline_singleton == null)
48
Unity.timeline_singleton = new Unity.TimelineLogger ();
51
return Unity.timeline_singleton;
56
this.process_map = new Gee.HashMap<string, ProcessInfo> ();
57
this.global_timer = new Timer ();
58
this.global_timer.start ();
61
public void start_process (string name)
63
if (name in this.process_map.keys)
65
warning ("already started process: %s", name);
69
var info = new ProcessInfo (name);
70
this.process_map[name] = info;
71
info.start = this.global_timer.elapsed ();
74
public void end_process (string name)
76
double end_time = this.global_timer.elapsed ();
78
if (name in this.process_map.keys)
80
this.process_map[name].end = end_time;
84
warning ("process %s not started", name);
88
public void write_log (string filename)
90
debug ("Writing performance log file: %s...", filename);
91
var log_file = File.new_for_path (filename);
92
FileOutputStream file_stream;
95
if (!log_file.query_exists (null)) {
96
file_stream = log_file.create (FileCreateFlags.NONE, null);
100
file_stream = log_file.replace (null, false, FileCreateFlags.NONE, null);
103
var output_stream = new DataOutputStream (file_stream);
105
foreach (ProcessInfo info in this.process_map.values)
107
string outline = "%s, %f, %f\n".printf(info.name, info.start, info.end);
108
output_stream.put_string (outline, null);