summaryrefslogtreecommitdiffstats
path: root/bitbake/bin
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-12-09 11:57:38 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-18 10:24:06 +0000
commit85a17f86ea2edf24b54aa62bd25e10ff522cb6e7 (patch)
tree69baa4d959be832b5c096b7d69b0fc2bcb2247b5 /bitbake/bin
parentd086fa3aed34a05d52e73c255ca22379149a64a1 (diff)
downloadpoky-85a17f86ea2edf24b54aa62bd25e10ff522cb6e7.tar.gz
bitbake: add option to write offline event log file
This patch adds a "-w/--write-log" option to bitbake that writes an event log file for the current build. The name of the file is passed as a parameter to the "-w" argument. If the parameter is the empty string '', the file name is generated in the form bitbake_eventlog_DATE.json, where DATE is the current date and time, with second precision. The "-w" option can also be supplied as the BBEVENTLOG environment variable. We add a script, toater-eventreplay, that reads an event log file and loads the data into a Toaster database, creating a build entry. We modify the toasterui to fix minor issues with reading events from an event log file. Performance impact is undetectable under no-task executed builds. (Bitbake rev: 1befb4a783bb7b7b387d4b5ee08830d9516f1ac2) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/bin')
-rwxr-xr-xbitbake/bin/bitbake12
-rwxr-xr-xbitbake/bin/toaster-eventreplay179
2 files changed, 190 insertions, 1 deletions
diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake
index 7f8449c7b3..d46c3dde3b 100755
--- a/bitbake/bin/bitbake
+++ b/bitbake/bin/bitbake
@@ -196,6 +196,9 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
196 parser.add_option("", "--status-only", help = "Check the status of the remote bitbake server.", 196 parser.add_option("", "--status-only", help = "Check the status of the remote bitbake server.",
197 action = "store_true", dest = "status_only", default = False) 197 action = "store_true", dest = "status_only", default = False)
198 198
199 parser.add_option("-w", "--write-log", help = "Writes the event log of the build to a bitbake event json file. Use '' (empty string) to assign the name automatically.",
200 action = "store", dest = "writeeventlog")
201
199 options, targets = parser.parse_args(sys.argv) 202 options, targets = parser.parse_args(sys.argv)
200 203
201 # some environmental variables set also configuration options 204 # some environmental variables set also configuration options
@@ -206,6 +209,14 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
206 if "BBTOKEN" in os.environ: 209 if "BBTOKEN" in os.environ:
207 options.xmlrpctoken = os.environ["BBTOKEN"] 210 options.xmlrpctoken = os.environ["BBTOKEN"]
208 211
212 if "BBEVENTLOG" is os.environ:
213 options.writeeventlog = os.environ["BBEVENTLOG"]
214
215 # fill in proper log name if not supplied
216 if options.writeeventlog is not None and len(options.writeeventlog) == 0:
217 import datetime
218 options.writeeventlog = "bitbake_eventlog_%s.json" % datetime.datetime.now().strftime("%Y%m%d%H%M%S")
219
209 # if BBSERVER says to autodetect, let's do that 220 # if BBSERVER says to autodetect, let's do that
210 if options.remote_server: 221 if options.remote_server:
211 [host, port] = options.remote_server.split(":", 2) 222 [host, port] = options.remote_server.split(":", 2)
@@ -266,7 +277,6 @@ def start_server(servermodule, configParams, configuration, features):
266 return server 277 return server
267 278
268 279
269
270def main(): 280def main():
271 281
272 configParams = BitBakeConfigParameters() 282 configParams = BitBakeConfigParameters()
diff --git a/bitbake/bin/toaster-eventreplay b/bitbake/bin/toaster-eventreplay
new file mode 100755
index 0000000000..624829aea0
--- /dev/null
+++ b/bitbake/bin/toaster-eventreplay
@@ -0,0 +1,179 @@
1#!/usr/bin/env python
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# Copyright (C) 2014 Alex Damian
6#
7# This file re-uses code spread throughout other Bitbake source files.
8# As such, all other copyrights belong to their own right holders.
9#
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License version 2 as
13# published by the Free Software Foundation.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License along
21# with this program; if not, write to the Free Software Foundation, Inc.,
22# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24
25# This command takes a filename as a single parameter. The filename is read
26# as a build eventlog, and the ToasterUI is used to process events in the file
27# and log data in the database
28
29import os
30import sys, logging
31
32# mangle syspath to allow easy import of modules
33sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
34 'lib'))
35
36
37import bb.cooker
38from bb.ui import toasterui
39import sys
40import logging
41
42logger = logging.getLogger(__name__)
43console = logging.StreamHandler(sys.stdout)
44format_str = "%(levelname)s: %(message)s"
45logging.basicConfig(format=format_str)
46
47
48import json, pickle
49
50
51class FileReadEventsServerConnection():
52 """ Emulates a connection to a bitbake server that feeds
53 events coming actually read from a saved log file.
54 """
55
56 class MockConnection():
57 """ fill-in for the proxy to the server. we just return generic data
58 """
59 def __init__(self, sc):
60 self._sc = sc
61
62 def runCommand(self, commandArray):
63 """ emulates running a command on the server; only read-only commands are accepted """
64 command_name = commandArray[0]
65
66 if command_name == "getVariable":
67 if commandArray[1] in self._sc._variables:
68 return (self._sc._variables[commandArray[1]]['v'], None)
69 return (None, "Missing variable")
70
71 elif command_name == "getAllKeysWithFlags":
72 dump = {}
73 flaglist = commandArray[1]
74 for k in self._sc._variables.keys():
75 try:
76 if not k.startswith("__"):
77 v = self._sc._variables[k]['v']
78 dump[k] = {
79 'v' : v ,
80 'history' : self._sc._variables[k]['history'],
81 }
82 for d in flaglist:
83 dump[k][d] = self._sc._variables[k][d]
84 except Exception as e:
85 print(e)
86 return (dump, None)
87 else:
88 raise Exception("Command %s not implemented" % commandArray[0])
89
90 def terminateServer(self):
91 """ do not do anything """
92 pass
93
94
95
96 class EventReader():
97 def __init__(self, sc):
98 self._sc = sc
99 self.firstraise = 0
100
101 def _create_event(self, line):
102 def _import_class(name):
103 assert len(name) > 0
104 assert "." in name, name
105
106 components = name.strip().split(".")
107 modulename = ".".join(components[:-1])
108 moduleklass = components[-1]
109
110 module = __import__(modulename, fromlist=[str(moduleklass)])
111 return getattr(module, moduleklass)
112
113 # we build a toaster event out of current event log line
114 try:
115 event_data = json.loads(line.strip())
116 event_class = _import_class(event_data['class'])
117 event_object = pickle.loads(json.loads(event_data['vars']))
118 except ValueError as e:
119 print("Failed loading ", line)
120 raise e
121
122 if not isinstance(event_object, event_class):
123 raise Exception("Error loading objects %s class %s ", event_object, event_class)
124
125 return event_object
126
127 def waitEvent(self, timeout):
128
129 nextline = self._sc._eventfile.readline()
130 if len(nextline) == 0:
131 # the build data ended, while toasterui still waits for events.
132 # this happens when the server was abruptly stopped, so we simulate this
133 self.firstraise += 1
134 if self.firstraise == 1:
135 raise KeyboardInterrupt()
136 else:
137 return None
138 else:
139 self._sc.lineno += 1
140 return self._create_event(nextline)
141
142
143 def _readVariables(self, variableline):
144 self._variables = json.loads(variableline.strip())['allvariables']
145
146
147 def __init__(self, file_name):
148 self.connection = FileReadEventsServerConnection.MockConnection(self)
149 self._eventfile = open(file_name, "r")
150
151 # we expect to have the variable dump at the start of the file
152 self.lineno = 1
153 self._readVariables(self._eventfile.readline())
154
155 self.events = FileReadEventsServerConnection.EventReader(self)
156
157
158
159
160
161class MockConfigParameters():
162 """ stand-in for cookerdata.ConfigParameters; as we don't really config a cooker, this
163 serves just to supply needed interfaces for the toaster ui to work """
164 def __init__(self):
165 self.observe_only = True # we can only read files
166
167
168# run toaster ui on our mock bitbake class
169if __name__ == "__main__":
170 if len(sys.argv) < 2:
171 logger.error("Usage: %s event.log " % sys.argv[0])
172 sys.exit(1)
173
174 file_name = sys.argv[-1]
175 mock_connection = FileReadEventsServerConnection(file_name)
176 configParams = MockConfigParameters()
177
178 # run the main program
179 toasterui.main(mock_connection.connection, mock_connection.events, configParams)