44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
1 |
/*
|
636.8.1
by Gord Allott
perf logger update |
2 |
* Copyright (C) 2009-2010 Canonical Ltd
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
3 |
*
|
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.
|
|
7 |
*
|
|
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.
|
|
12 |
*
|
|
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/>.
|
|
15 |
*
|
|
16 |
* Authored by Gord Allott <gord.allott@canonical.com>
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
||
636.8.1
by Gord Allott
perf logger update |
20 |
namespace Perf |
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
21 |
{
|
22 |
public class ProcessInfo |
|
23 |
{
|
|
24 |
public ProcessInfo (string name) |
|
25 |
{
|
|
26 |
this.name = name; |
|
27 |
start = 0; |
|
28 |
end = 0; |
|
29 |
}
|
|
30 |
public string name; |
|
31 |
public double start; |
|
32 |
public double end; |
|
33 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
34 |
|
44.1.2
by Gordon Allott
few fixes and added places monitoring |
35 |
public static TimelineLogger? timeline_singleton; |
636.8.1
by Gord Allott
perf logger update |
36 |
public static bool is_logging; |
37 |
||
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
38 |
public class TimelineLogger : Object |
39 |
{
|
|
40 |
private Timer global_timer; |
|
41 |
private Gee.HashMap<string, ProcessInfo> process_map; |
|
636.8.1
by Gord Allott
perf logger update |
42 |
|
43 |
public static unowned Perf.TimelineLogger get_default () |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
44 |
{
|
636.8.1
by Gord Allott
perf logger update |
45 |
if (Perf.timeline_singleton == null) |
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
46 |
{
|
636.8.1
by Gord Allott
perf logger update |
47 |
Perf.timeline_singleton = new Perf.TimelineLogger (); |
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
48 |
}
|
636.8.1
by Gord Allott
perf logger update |
49 |
|
50 |
return Perf.timeline_singleton; |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
51 |
}
|
636.8.1
by Gord Allott
perf logger update |
52 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
53 |
construct
|
54 |
{
|
|
55 |
this.process_map = new Gee.HashMap<string, ProcessInfo> (); |
|
636.8.1
by Gord Allott
perf logger update |
56 |
this.global_timer = new Timer (); |
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
57 |
this.global_timer.start (); |
58 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
59 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
60 |
public void start_process (string name) |
61 |
{
|
|
62 |
if (name in this.process_map.keys) |
|
63 |
{
|
|
64 |
warning ("already started process: %s", name); |
|
65 |
return; |
|
66 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
67 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
68 |
var info = new ProcessInfo (name); |
69 |
this.process_map[name] = info; |
|
70 |
info.start = this.global_timer.elapsed (); |
|
71 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
72 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
73 |
public void end_process (string name) |
74 |
{
|
|
75 |
double end_time = this.global_timer.elapsed (); |
|
636.8.1
by Gord Allott
perf logger update |
76 |
print ("the end time is %f", end_time); |
77 |
||
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
78 |
if (name in this.process_map.keys) |
79 |
{
|
|
80 |
this.process_map[name].end = end_time; |
|
81 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
82 |
else
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
83 |
{
|
84 |
warning ("process %s not started", name); |
|
85 |
}
|
|
86 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
87 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
88 |
public void write_log (string filename) |
89 |
{
|
|
90 |
debug ("Writing performance log file: %s...", filename); |
|
91 |
var log_file = File.new_for_path (filename); |
|
92 |
FileOutputStream file_stream; |
|
636.8.1
by Gord Allott
perf logger update |
93 |
try
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
94 |
{
|
95 |
if (!log_file.query_exists (null)) { |
|
96 |
file_stream = log_file.create (FileCreateFlags.NONE, null); |
|
97 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
98 |
else
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
99 |
{
|
100 |
file_stream = log_file.replace (null, false, FileCreateFlags.NONE, null); |
|
101 |
}
|
|
636.8.1
by Gord Allott
perf logger update |
102 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
103 |
var output_stream = new DataOutputStream (file_stream); |
636.8.1
by Gord Allott
perf logger update |
104 |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
105 |
foreach (ProcessInfo info in this.process_map.values) |
106 |
{
|
|
636.8.1
by Gord Allott
perf logger update |
107 |
string name = info.name.replace (",", ";"); |
108 |
string outline = "%s, %f, %f\n".printf(name, info.start, info.end); |
|
109 |
output_stream.put_string (outline, null); |
|
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
110 |
}
|
636.8.1
by Gord Allott
perf logger update |
111 |
|
57.1.1
by Gord Allott
updated unity bootlogging to support the mutter-plugin, added new logs for missing areas, updated bootchart script to print time for each process and updated HACKING file |
112 |
file_stream.close (null); |
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
113 |
} catch (Error e) |
114 |
{
|
|
115 |
warning (e.message); |
|
116 |
}
|
|
57.1.1
by Gord Allott
updated unity bootlogging to support the mutter-plugin, added new logs for missing areas, updated bootchart script to print time for each process and updated HACKING file |
117 |
debug ("Done writing performance log file: %s", filename); |
44.1.1
by Gordon Allott
performance logger support and boot chart generation script |
118 |
}
|
119 |
}
|
|
120 |
}
|