summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSakib Sajal <sakib.sajal@windriver.com>2021-04-27 17:19:08 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-04-27 23:43:57 +0100
commitc21419b1fee3098298a77efdcca322fa665dea54 (patch)
tree39dcb471def8904df2c2dd8b4113649ac70c74b6
parentebb7adac03a863304dad00d0df8e9096bb1a49c3 (diff)
downloadpoky-c21419b1fee3098298a77efdcca322fa665dea54.tar.gz
buildstats.bbclass: collect data in the same file.
Previously "at interval" and "on failure" logs were collected in separate files. Collect both types of logging in the same file for better analysis. Introduced new variable which allows different set of commands to be run by the different logging, interval or failure. The variables are BB_LOG_HOST_STAT_CMDS_INTERVAL and BB_LOG_HOST_STAT_CMDS_FAILURE respecteviely. (From OE-Core rev: 4fbf422351668f755a14811ac39161c889087e81) Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/buildstats.bbclass32
1 files changed, 20 insertions, 12 deletions
diff --git a/meta/classes/buildstats.bbclass b/meta/classes/buildstats.bbclass
index 8e03039aeb..8a1466d3fe 100644
--- a/meta/classes/buildstats.bbclass
+++ b/meta/classes/buildstats.bbclass
@@ -104,7 +104,7 @@ def write_task_data(status, logfile, e, d):
104 f.write("Status: FAILED \n") 104 f.write("Status: FAILED \n")
105 f.write("Ended: %0.2f \n" % e.time) 105 f.write("Ended: %0.2f \n" % e.time)
106 106
107def write_host_data(logfile, e, d): 107def write_host_data(logfile, e, d, type):
108 import subprocess, os, datetime 108 import subprocess, os, datetime
109 # minimum time allowed for each command to run, in seconds 109 # minimum time allowed for each command to run, in seconds
110 time_threshold = 0.5 110 time_threshold = 0.5
@@ -112,15 +112,22 @@ def write_host_data(logfile, e, d):
112 num_cmds = 0 112 num_cmds = 0
113 # interval at which data will be logged 113 # interval at which data will be logged
114 interval = int(d.getVar("BB_HEARTBEAT_EVENT", False)) 114 interval = int(d.getVar("BB_HEARTBEAT_EVENT", False))
115 # the commands to be run at each interval 115 msg = ""
116 cmds = d.getVar('BB_LOG_HOST_STAT_CMDS') 116 if type == "interval":
117 # if no commands are passed, issue a warning and return 117 cmds = d.getVar('BB_LOG_HOST_STAT_CMDS_INTERVAL')
118 if cmds is None: 118 msg = "Host Stats: Collecting data at interval.\n"
119 d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0") 119 if cmds is None:
120 d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0") 120 d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0")
121 bb.warn("buildstats: Collecting host data failed. Set BB_LOG_HOST_STAT_CMDS=\"command1 ; command2 ; ... \" in conf/local.conf\n") 121 bb.warn("buildstats: Collecting host data at intervals failed. Set BB_LOG_HOST_STAT_CMDS_INTERVAL=\"command1 ; command2 ; ... \" in conf/local.conf\n")
122 return 122 return
123 # find the total commands 123 if type == "failure":
124 cmds = d.getVar('BB_LOG_HOST_STAT_CMDS_FAILURE')
125 msg = "Host Stats: Collecting data on failure.\n"
126 msg += "Failed at task " + e.task + "\n"
127 if cmds is None:
128 d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0")
129 bb.warn("buildstats: Collecting host data on failure failed. Set BB_LOG_HOST_STAT_CMDS_FAILURE=\"command1 ; command2 ; ... \" in conf/local.conf\n")
130 return
124 c_san = [] 131 c_san = []
125 for cmd in cmds.split(";"): 132 for cmd in cmds.split(";"):
126 if len(cmd) == 0: 133 if len(cmd) == 0:
@@ -147,6 +154,7 @@ def write_host_data(logfile, e, d):
147 os.environ['PATH'] = path + ":" + opath + ":" + ospath 154 os.environ['PATH'] = path + ":" + opath + ":" + ospath
148 with open(logfile, "a") as f: 155 with open(logfile, "a") as f:
149 f.write("Event Time: %f\nDate: %s\n" % (e.time, datetime.datetime.now())) 156 f.write("Event Time: %f\nDate: %s\n" % (e.time, datetime.datetime.now()))
157 f.write("%s" % msg)
150 for c in c_san: 158 for c in c_san:
151 try: 159 try:
152 output = subprocess.check_output(c.split(), stderr=subprocess.STDOUT, timeout=limit).decode('utf-8') 160 output = subprocess.check_output(c.split(), stderr=subprocess.STDOUT, timeout=limit).decode('utf-8')
@@ -171,7 +179,7 @@ python run_buildstats () {
171 taskdir = os.path.join(bsdir, d.getVar('PF')) 179 taskdir = os.path.join(bsdir, d.getVar('PF'))
172 if isinstance(e, bb.event.HeartbeatEvent) and bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_INTERVAL")): 180 if isinstance(e, bb.event.HeartbeatEvent) and bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_INTERVAL")):
173 bb.utils.mkdirhier(bsdir) 181 bb.utils.mkdirhier(bsdir)
174 write_host_data(os.path.join(bsdir, "host_stats"), e, d) 182 write_host_data(os.path.join(bsdir, "host_stats"), e, d, "interval")
175 183
176 if isinstance(e, bb.event.BuildStarted): 184 if isinstance(e, bb.event.BuildStarted):
177 ######################################################################## 185 ########################################################################
@@ -247,7 +255,7 @@ python run_buildstats () {
247 with open(build_status, "a") as f: 255 with open(build_status, "a") as f:
248 f.write(d.expand("Failed at: ${PF} at task: %s \n" % e.task)) 256 f.write(d.expand("Failed at: ${PF} at task: %s \n" % e.task))
249 if bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_FAILURE")): 257 if bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_FAILURE")):
250 write_host_data(build_status, e, d) 258 write_host_data(os.path.join(bsdir, "host_stats"), e, d, "failure")
251} 259}
252 260
253addhandler run_buildstats 261addhandler run_buildstats