summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/buildstats.bbclass42
1 files changed, 35 insertions, 7 deletions
diff --git a/meta/classes/buildstats.bbclass b/meta/classes/buildstats.bbclass
index a8ee6e69a6..8e03039aeb 100644
--- a/meta/classes/buildstats.bbclass
+++ b/meta/classes/buildstats.bbclass
@@ -106,26 +106,54 @@ def write_task_data(status, logfile, e, d):
106 106
107def write_host_data(logfile, e, d): 107def write_host_data(logfile, e, d):
108 import subprocess, os, datetime 108 import subprocess, os, datetime
109 # minimum time allowed for each command to run, in seconds
110 time_threshold = 0.5
111 # the total number of commands
112 num_cmds = 0
113 # interval at which data will be logged
114 interval = int(d.getVar("BB_HEARTBEAT_EVENT", False))
115 # the commands to be run at each interval
109 cmds = d.getVar('BB_LOG_HOST_STAT_CMDS') 116 cmds = d.getVar('BB_LOG_HOST_STAT_CMDS')
117 # if no commands are passed, issue a warning and return
110 if cmds is None: 118 if cmds is None:
111 d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0") 119 d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0")
112 d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0") 120 d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0")
113 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 failed. Set BB_LOG_HOST_STAT_CMDS=\"command1 ; command2 ; ... \" in conf/local.conf\n")
114 return 122 return
123 # find the total commands
124 c_san = []
125 for cmd in cmds.split(";"):
126 if len(cmd) == 0:
127 continue
128 num_cmds += 1
129 c_san.append(cmd)
130 if num_cmds <= 0:
131 d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0")
132 d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0")
133 return
134
135 # return if the interval is not enough to run all commands within the specified BB_HEARTBEAT_EVENT interval
136 limit = interval / num_cmds
137 if limit <= time_threshold:
138 d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0")
139 d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0")
140 bb.warn("buildstats: Collecting host data failed. BB_HEARTBEAT_EVENT interval not enough to run the specified commands. HINT: Increase value of BB_HEARTBEAT_EVENT in conf/local.conf\n")
141 return
142
143 # set the environment variables
115 path = d.getVar("PATH") 144 path = d.getVar("PATH")
116 opath = d.getVar("BB_ORIGENV", False).getVar("PATH") 145 opath = d.getVar("BB_ORIGENV", False).getVar("PATH")
117 ospath = os.environ['PATH'] 146 ospath = os.environ['PATH']
118 os.environ['PATH'] = path + ":" + opath + ":" + ospath 147 os.environ['PATH'] = path + ":" + opath + ":" + ospath
119 with open(logfile, "a") as f: 148 with open(logfile, "a") as f:
120 f.write("Event Time: %f\nDate: %s\n" % (e.time, datetime.datetime.now())) 149 f.write("Event Time: %f\nDate: %s\n" % (e.time, datetime.datetime.now()))
121 for cmd in cmds.split(";"): 150 for c in c_san:
122 if len(cmd) == 0:
123 continue
124 try: 151 try:
125 output = subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT, timeout=1).decode('utf-8') 152 output = subprocess.check_output(c.split(), stderr=subprocess.STDOUT, timeout=limit).decode('utf-8')
126 except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError) as err: 153 except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError) as err:
127 output = "Error running command: %s\n%s\n" % (cmd, err) 154 output = "Error running command: %s\n%s\n" % (c, err)
128 f.write("%s\n%s\n" % (cmd, output)) 155 f.write("%s\n%s\n" % (c, output))
156 # reset the environment
129 os.environ['PATH'] = ospath 157 os.environ['PATH'] = ospath
130 158
131python run_buildstats () { 159python run_buildstats () {