author | timothy.murphy@nokia.com |
Wed, 02 Dec 2009 00:38:31 +0000 | |
branch | wip |
changeset 30 | 01c962c3f631 |
permissions | -rw-r--r-- |
30
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
1 |
# |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
3 |
# All rights reserved. |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
4 |
# This component and the accompanying materials are made available |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
5 |
# under the terms of the License "Eclipse Public License v1.0" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
6 |
# which accompanies this distribution, and is available |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
8 |
# |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
9 |
# Initial Contributors: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
10 |
# Nokia Corporation - initial contribution. |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
11 |
# |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
12 |
# Contributors: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
13 |
# |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
14 |
# Description: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
15 |
# Base Class for defining filter classes |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
16 |
# All filter classes that get defined should derive from this base class |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
17 |
# |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
18 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
19 |
import errno |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
20 |
import filter_interface |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
21 |
import os |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
22 |
import raptor |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
23 |
import raptor_timing |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
24 |
import sys |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
25 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
26 |
class FilterTiming(filter_interface.Filter): |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
27 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
28 |
Writes a logfile containing the timings for each Raptor process |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
29 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
30 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
31 |
def open(self, raptor_instance): |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
32 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
33 |
Open a log file with the same name as the Raptor log file, with |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
34 |
'.timings' appended. This will contain only 'progress' |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
35 |
timing tags from the Raptor output |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
36 |
Parameters: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
37 |
raptor_instance - Raptor |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
38 |
Instance of Raptor. FilterList usually passes in a cut-down |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
39 |
version of Raptor containing only a few attributes |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
40 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
41 |
self.raptor = raptor_instance |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
42 |
self.logFileName = self.raptor.logFileName |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
43 |
# insert the time into the log file name |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
44 |
if self.logFileName: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
45 |
self.path = (self.logFileName.path.replace("%TIME", |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
46 |
self.raptor.timestring) + ".timings") |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
47 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
48 |
try: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
49 |
dirname = str(self.raptor.logFileName.Dir()) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
50 |
if dirname and not os.path.isdir(dirname): |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
51 |
os.makedirs(dirname) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
52 |
except os.error, e: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
53 |
if e.errno != errno.EEXIST: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
54 |
sys.stderr.write("%s : error: cannot create directory " + |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
55 |
"%s\n" % (raptor.name, dirname)) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
56 |
return False |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
57 |
try: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
58 |
self.out = open(str(self.path), "w") |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
59 |
except: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
60 |
self.out = None |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
61 |
sys.stderr.write("%s : error: cannot write log %s\n" %\ |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
62 |
(raptor.name, self.path)) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
63 |
return False |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
64 |
self.start_times = {} |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
65 |
self.all_durations = [] |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
66 |
self.namespace_written = False |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
67 |
self.open_written = False |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
68 |
return True |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
69 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
70 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
71 |
def write(self, text): |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
72 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
73 |
Write out any tags with a 'progress_' tagName |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
74 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
75 |
if "<progress:discovery " in text: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
76 |
self.out.write(text) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
77 |
elif "<progress:start " in text: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
78 |
attributes = raptor_timing.Timing.extract_values(source = text) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
79 |
self.start_times[(attributes["object_type"] + attributes["task"] + |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
80 |
attributes["key"])] = attributes["time"] |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
81 |
elif "<progress:end " in text: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
82 |
attributes = raptor_timing.Timing.extract_values(source = text) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
83 |
duration = (float(attributes["time"]) - |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
84 |
float(self.start_times[(attributes["object_type"] + |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
85 |
attributes["task"] + attributes["key"])])) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
86 |
self.out.write(raptor_timing.Timing.custom_string(tag = "duration", |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
87 |
object_type = attributes["object_type"], |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
88 |
task = attributes["task"], key = attributes["key"], |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
89 |
time = duration)) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
90 |
self.all_durations.append(duration) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
91 |
elif text.startswith("<?xml ") and not self.namespace_written: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
92 |
self.out.write(text) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
93 |
self.namespace_written = True |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
94 |
elif text.startswith("<buildlog ") and not self.open_written: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
95 |
self.out.write(text) |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
96 |
self.open_written = True |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
97 |
return True |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
98 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
99 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
100 |
def summary(self): |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
101 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
102 |
Print out extra timing info |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
103 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
104 |
total_time = 0.0 |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
105 |
for duration in self.all_durations: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
106 |
total_time += duration |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
107 |
self.out.write(raptor_timing.Timing.custom_string(tag = "duration", |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
108 |
object_type = "all", task = "all", key = "all", |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
109 |
time = total_time) + "</buildlog>\n") |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
110 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
111 |
|
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
112 |
def close(self): |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
113 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
114 |
Close the logfile |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
115 |
""" |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
116 |
try: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
117 |
self.out.close |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
118 |
return True |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
119 |
except: |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
120 |
self.out = None |
01c962c3f631
correction: left out timing files in previous commit
timothy.murphy@nokia.com
parents:
diff
changeset
|
121 |
return False |