Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | BUILDSTATS_BASE = "${TMPDIR}/buildstats/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | ################################################################################ |
| 4 | # Build statistics gathering. |
| 5 | # |
| 6 | # The CPU and Time gathering/tracking functions and bbevent inspiration |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 7 | # were written by Christopher Larson. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | # |
| 9 | ################################################################################ |
| 10 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 11 | def get_buildprocess_cputime(pid): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | with open("/proc/%d/stat" % pid, "r") as f: |
| 13 | fields = f.readline().rstrip().split() |
| 14 | # 13: utime, 14: stime, 15: cutime, 16: cstime |
| 15 | return sum(int(field) for field in fields[13:16]) |
| 16 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 17 | def get_process_cputime(pid): |
| 18 | import resource |
| 19 | with open("/proc/%d/stat" % pid, "r") as f: |
| 20 | fields = f.readline().rstrip().split() |
| 21 | stats = { |
| 22 | 'utime' : fields[13], |
| 23 | 'stime' : fields[14], |
| 24 | 'cutime' : fields[15], |
| 25 | 'cstime' : fields[16], |
| 26 | } |
| 27 | iostats = {} |
| 28 | if os.path.isfile("/proc/%d/io" % pid): |
| 29 | with open("/proc/%d/io" % pid, "r") as f: |
| 30 | while True: |
| 31 | i = f.readline().strip() |
| 32 | if not i: |
| 33 | break |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | if not ":" in i: |
| 35 | # one more extra line is appended (empty or containing "0") |
| 36 | # most probably due to race condition in kernel while |
| 37 | # updating IO stats |
| 38 | break |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 39 | i = i.split(": ") |
| 40 | iostats[i[0]] = i[1] |
| 41 | resources = resource.getrusage(resource.RUSAGE_SELF) |
| 42 | childres = resource.getrusage(resource.RUSAGE_CHILDREN) |
| 43 | return stats, iostats, resources, childres |
| 44 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | def get_cputime(): |
| 46 | with open("/proc/stat", "r") as f: |
| 47 | fields = f.readline().rstrip().split()[1:] |
| 48 | return sum(int(field) for field in fields) |
| 49 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | def set_timedata(var, d, server_time): |
| 51 | d.setVar(var, server_time) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 53 | def get_timedata(var, d, end_time): |
| 54 | oldtime = d.getVar(var, False) |
| 55 | if oldtime is None: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | return |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 57 | return end_time - oldtime |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 59 | def set_buildtimedata(var, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | import time |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 61 | time = time.time() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | cputime = get_cputime() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 63 | proctime = get_buildprocess_cputime(os.getpid()) |
| 64 | d.setVar(var, (time, cputime, proctime)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 66 | def get_buildtimedata(var, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | import time |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 68 | timedata = d.getVar(var, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | if timedata is None: |
| 70 | return |
| 71 | oldtime, oldcpu, oldproc = timedata |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 72 | procdiff = get_buildprocess_cputime(os.getpid()) - oldproc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | cpudiff = get_cputime() - oldcpu |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 74 | end_time = time.time() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | timediff = end_time - oldtime |
| 76 | if cpudiff > 0: |
| 77 | cpuperc = float(procdiff) * 100 / cpudiff |
| 78 | else: |
| 79 | cpuperc = None |
| 80 | return timediff, cpuperc |
| 81 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | def write_task_data(status, logfile, e, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | with open(os.path.join(logfile), "a") as f: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 84 | elapsedtime = get_timedata("__timedata_task", d, e.time) |
| 85 | if elapsedtime: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 86 | f.write(d.expand("${PF}: %s\n" % e.task)) |
| 87 | f.write(d.expand("Elapsed time: %0.2f seconds\n" % elapsedtime)) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 88 | cpu, iostats, resources, childres = get_process_cputime(os.getpid()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | if cpu: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 90 | f.write("utime: %s\n" % cpu['utime']) |
| 91 | f.write("stime: %s\n" % cpu['stime']) |
| 92 | f.write("cutime: %s\n" % cpu['cutime']) |
| 93 | f.write("cstime: %s\n" % cpu['cstime']) |
| 94 | for i in iostats: |
| 95 | f.write("IO %s: %s\n" % (i, iostats[i])) |
| 96 | rusages = ["ru_utime", "ru_stime", "ru_maxrss", "ru_minflt", "ru_majflt", "ru_inblock", "ru_oublock", "ru_nvcsw", "ru_nivcsw"] |
| 97 | for i in rusages: |
| 98 | f.write("rusage %s: %s\n" % (i, getattr(resources, i))) |
| 99 | for i in rusages: |
| 100 | f.write("Child rusage %s: %s\n" % (i, getattr(childres, i))) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 101 | if status == "passed": |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | f.write("Status: PASSED \n") |
| 103 | else: |
| 104 | f.write("Status: FAILED \n") |
| 105 | f.write("Ended: %0.2f \n" % e.time) |
| 106 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 107 | def write_host_data(logfile, e, d, type): |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 108 | import subprocess, os, datetime |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 109 | # minimum time allowed for each command to run, in seconds |
| 110 | time_threshold = 0.5 |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 111 | limit = 10 |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 112 | # the total number of commands |
| 113 | num_cmds = 0 |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 114 | msg = "" |
| 115 | if type == "interval": |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 116 | # interval at which data will be logged |
| 117 | interval = d.getVar("BB_HEARTBEAT_EVENT", False) |
| 118 | if interval is None: |
| 119 | bb.warn("buildstats: Collecting host data at intervals failed. Set BB_HEARTBEAT_EVENT=\"<interval>\" in conf/local.conf for the interval at which host data will be logged.") |
| 120 | d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0") |
| 121 | return |
| 122 | interval = int(interval) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 123 | cmds = d.getVar('BB_LOG_HOST_STAT_CMDS_INTERVAL') |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 124 | msg = "Host Stats: Collecting data at %d second intervals.\n" % interval |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 125 | if cmds is None: |
| 126 | d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0") |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 127 | bb.warn("buildstats: Collecting host data at intervals failed. Set BB_LOG_HOST_STAT_CMDS_INTERVAL=\"command1 ; command2 ; ... \" in conf/local.conf.") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 128 | return |
| 129 | if type == "failure": |
| 130 | cmds = d.getVar('BB_LOG_HOST_STAT_CMDS_FAILURE') |
| 131 | msg = "Host Stats: Collecting data on failure.\n" |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 132 | msg += "Failed at task: " + e.task + "\n" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 133 | if cmds is None: |
| 134 | d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0") |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 135 | bb.warn("buildstats: Collecting host data on failure failed. Set BB_LOG_HOST_STAT_CMDS_FAILURE=\"command1 ; command2 ; ... \" in conf/local.conf.") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 136 | return |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 137 | c_san = [] |
| 138 | for cmd in cmds.split(";"): |
| 139 | if len(cmd) == 0: |
| 140 | continue |
| 141 | num_cmds += 1 |
| 142 | c_san.append(cmd) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 143 | if num_cmds == 0: |
| 144 | if type == "interval": |
| 145 | d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0") |
| 146 | if type == "failure": |
| 147 | d.setVar("BB_LOG_HOST_STAT_ON_FAILURE", "0") |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 148 | return |
| 149 | |
| 150 | # return if the interval is not enough to run all commands within the specified BB_HEARTBEAT_EVENT interval |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 151 | if type == "interval": |
| 152 | limit = interval / num_cmds |
| 153 | if limit <= time_threshold: |
| 154 | d.setVar("BB_LOG_HOST_STAT_ON_INTERVAL", "0") |
| 155 | bb.warn("buildstats: Collecting host data failed. BB_HEARTBEAT_EVENT interval not enough to run the specified commands. Increase value of BB_HEARTBEAT_EVENT in conf/local.conf.") |
| 156 | return |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 157 | |
| 158 | # set the environment variables |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 159 | path = d.getVar("PATH") |
| 160 | opath = d.getVar("BB_ORIGENV", False).getVar("PATH") |
| 161 | ospath = os.environ['PATH'] |
| 162 | os.environ['PATH'] = path + ":" + opath + ":" + ospath |
| 163 | with open(logfile, "a") as f: |
| 164 | f.write("Event Time: %f\nDate: %s\n" % (e.time, datetime.datetime.now())) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 165 | f.write("%s" % msg) |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 166 | for c in c_san: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 167 | try: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 168 | output = subprocess.check_output(c.split(), stderr=subprocess.STDOUT, timeout=limit).decode('utf-8') |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 169 | except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError) as err: |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 170 | output = "Error running command: %s\n%s\n" % (c, err) |
| 171 | f.write("%s\n%s\n" % (c, output)) |
| 172 | # reset the environment |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 173 | os.environ['PATH'] = ospath |
| 174 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | python run_buildstats () { |
| 176 | import bb.build |
| 177 | import bb.event |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 178 | import time, subprocess, platform |
| 179 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 180 | bn = d.getVar('BUILDNAME') |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 181 | ######################################################################## |
| 182 | # bitbake fires HeartbeatEvent even before a build has been |
| 183 | # triggered, causing BUILDNAME to be None |
| 184 | ######################################################################## |
| 185 | if bn is not None: |
| 186 | bsdir = os.path.join(d.getVar('BUILDSTATS_BASE'), bn) |
| 187 | taskdir = os.path.join(bsdir, d.getVar('PF')) |
| 188 | if isinstance(e, bb.event.HeartbeatEvent) and bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_INTERVAL")): |
| 189 | bb.utils.mkdirhier(bsdir) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 190 | write_host_data(os.path.join(bsdir, "host_stats_interval"), e, d, "interval") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 191 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 192 | if isinstance(e, bb.event.BuildStarted): |
| 193 | ######################################################################## |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 194 | # If the kernel was not configured to provide I/O statistics, issue |
| 195 | # a one time warning. |
| 196 | ######################################################################## |
| 197 | if not os.path.isfile("/proc/%d/io" % os.getpid()): |
| 198 | bb.warn("The Linux kernel on your build host was not configured to provide process I/O statistics. (CONFIG_TASK_IO_ACCOUNTING is not set)") |
| 199 | |
| 200 | ######################################################################## |
| 201 | # at first pass make the buildstats hierarchy and then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | # set the buildname |
| 203 | ######################################################################## |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | bb.utils.mkdirhier(bsdir) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 205 | set_buildtimedata("__timedata_build", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 206 | build_time = os.path.join(bsdir, "build_stats") |
| 207 | # write start of build into build_time |
| 208 | with open(build_time, "a") as f: |
| 209 | host_info = platform.uname() |
| 210 | f.write("Host Info: ") |
| 211 | for x in host_info: |
| 212 | if x: |
| 213 | f.write(x + " ") |
| 214 | f.write("\n") |
Andrew Geissler | 4ed12e1 | 2020-06-05 18:00:41 -0500 | [diff] [blame] | 215 | f.write("Build Started: %0.2f \n" % d.getVar('__timedata_build', False)[0]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 216 | |
| 217 | elif isinstance(e, bb.event.BuildCompleted): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 218 | build_time = os.path.join(bsdir, "build_stats") |
| 219 | with open(build_time, "a") as f: |
| 220 | ######################################################################## |
| 221 | # Write build statistics for the build |
| 222 | ######################################################################## |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 223 | timedata = get_buildtimedata("__timedata_build", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | if timedata: |
| 225 | time, cpu = timedata |
| 226 | # write end of build and cpu used into build_time |
| 227 | f.write("Elapsed time: %0.2f seconds \n" % (time)) |
| 228 | if cpu: |
| 229 | f.write("CPU usage: %0.1f%% \n" % cpu) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | |
| 231 | if isinstance(e, bb.build.TaskStarted): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 232 | set_timedata("__timedata_task", d, e.time) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 233 | bb.utils.mkdirhier(taskdir) |
| 234 | # write into the task event file the name and start time |
| 235 | with open(os.path.join(taskdir, e.task), "a") as f: |
| 236 | f.write("Event: %s \n" % bb.event.getName(e)) |
| 237 | f.write("Started: %0.2f \n" % e.time) |
| 238 | |
| 239 | elif isinstance(e, bb.build.TaskSucceeded): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 240 | write_task_data("passed", os.path.join(taskdir, e.task), e, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | if e.task == "do_rootfs": |
| 242 | bs = os.path.join(bsdir, "build_stats") |
| 243 | with open(bs, "a") as f: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 244 | rootfs = d.getVar('IMAGE_ROOTFS') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 245 | if os.path.isdir(rootfs): |
| 246 | try: |
| 247 | rootfs_size = subprocess.check_output(["du", "-sh", rootfs], |
| 248 | stderr=subprocess.STDOUT).decode('utf-8') |
| 249 | f.write("Uncompressed Rootfs size: %s" % rootfs_size) |
| 250 | except subprocess.CalledProcessError as err: |
| 251 | bb.warn("Failed to get rootfs size: %s" % err.output.decode('utf-8')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | |
| 253 | elif isinstance(e, bb.build.TaskFailed): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 254 | # Can have a failure before TaskStarted so need to mkdir here too |
| 255 | bb.utils.mkdirhier(taskdir) |
| 256 | write_task_data("failed", os.path.join(taskdir, e.task), e, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | ######################################################################## |
| 258 | # Lets make things easier and tell people where the build failed in |
| 259 | # build_status. We do this here because BuildCompleted triggers no |
| 260 | # matter what the status of the build actually is |
| 261 | ######################################################################## |
| 262 | build_status = os.path.join(bsdir, "build_stats") |
| 263 | with open(build_status, "a") as f: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 264 | f.write(d.expand("Failed at: ${PF} at task: %s \n" % e.task)) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 265 | if bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_FAILURE")): |
| 266 | write_host_data(os.path.join(bsdir, "host_stats_%s_failure" % e.task), e, d, "failure") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | addhandler run_buildstats |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 270 | run_buildstats[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted bb.event.HeartbeatEvent bb.build.TaskStarted bb.build.TaskSucceeded bb.build.TaskFailed" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 271 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 272 | python runqueue_stats () { |
| 273 | import buildstats |
| 274 | from bb import event, runqueue |
| 275 | # We should not record any samples before the first task has started, |
| 276 | # because that's the first activity shown in the process chart. |
| 277 | # Besides, at that point we are sure that the build variables |
| 278 | # are available that we need to find the output directory. |
| 279 | # The persistent SystemStats is stored in the datastore and |
| 280 | # closed when the build is done. |
| 281 | system_stats = d.getVar('_buildstats_system_stats', False) |
| 282 | if not system_stats and isinstance(e, (bb.runqueue.sceneQueueTaskStarted, bb.runqueue.runQueueTaskStarted)): |
| 283 | system_stats = buildstats.SystemStats(d) |
| 284 | d.setVar('_buildstats_system_stats', system_stats) |
| 285 | if system_stats: |
| 286 | # Ensure that we sample at important events. |
| 287 | done = isinstance(e, bb.event.BuildCompleted) |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame^] | 288 | if system_stats.sample(e, force=done): |
| 289 | d.setVar('_buildstats_system_stats', system_stats) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 290 | if done: |
| 291 | system_stats.close() |
| 292 | d.delVar('_buildstats_system_stats') |
| 293 | } |
| 294 | |
| 295 | addhandler runqueue_stats |
| 296 | runqueue_stats[eventmask] = "bb.runqueue.sceneQueueTaskStarted bb.runqueue.runQueueTaskStarted bb.event.HeartbeatEvent bb.event.BuildCompleted bb.event.MonitorDiskEvent" |