32
31
public double start;
36
35
public static TimelineLogger? timeline_singleton;
37
public static bool is_logging;
36
public static bool is_logging;
39
38
public class TimelineLogger : Object
41
40
private Timer global_timer;
42
41
private Gee.HashMap<string, ProcessInfo> process_map;
44
public static unowned Unity.TimelineLogger get_default ()
43
public static unowned Perf.TimelineLogger get_default ()
46
if (Unity.timeline_singleton == null)
45
if (Perf.timeline_singleton == null)
48
Unity.timeline_singleton = new Unity.TimelineLogger ();
47
Perf.timeline_singleton = new Perf.TimelineLogger ();
51
return Unity.timeline_singleton;
50
return Perf.timeline_singleton;
56
55
this.process_map = new Gee.HashMap<string, ProcessInfo> ();
57
this.global_timer = new Timer ();
56
this.global_timer = new Timer ();
58
57
this.global_timer.start ();
61
60
public void start_process (string name)
62
debug ("shoop de whoop");
63
63
if (name in this.process_map.keys)
65
65
warning ("already started process: %s", name);
69
69
var info = new ProcessInfo (name);
70
70
this.process_map[name] = info;
71
71
info.start = this.global_timer.elapsed ();
74
74
public void end_process (string name)
76
debug ("shonk le donk");
76
77
double end_time = this.global_timer.elapsed ();
78
print ("the end time is %f", end_time);
78
80
if (name in this.process_map.keys)
80
82
this.process_map[name].end = end_time;
84
86
warning ("process %s not started", name);
88
90
public void write_log (string filename)
90
92
debug ("Writing performance log file: %s...", filename);
91
93
var log_file = File.new_for_path (filename);
92
94
FileOutputStream file_stream;
95
97
if (!log_file.query_exists (null)) {
96
98
file_stream = log_file.create (FileCreateFlags.NONE, null);
100
102
file_stream = log_file.replace (null, false, FileCreateFlags.NONE, null);
103
105
var output_stream = new DataOutputStream (file_stream);
105
107
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);
109
string name = info.name.replace (",", ";");
110
string outline = "%s, %f, %f\n".printf(name, info.start, info.end);
111
output_stream.put_string (outline, null);
111
114
file_stream.close (null);
112
115
} catch (Error e)