From 3187647d892fb5cf50158b0ceacfd9b759f695cb Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Thu, 17 Dec 2015 14:54:14 +0000 Subject: buildstats: Separate out the build and task data to allow improvements The combined build and task data code makes changing things hard, separate out the functions so that changes can be made to the task data whilst the build data remains unchanged. (From OE-Core rev: c79cfce4f820f20346d0565df8df626832976e28) Signed-off-by: Richard Purdie --- meta/classes/buildstats.bbclass | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'meta/classes/buildstats.bbclass') diff --git a/meta/classes/buildstats.bbclass b/meta/classes/buildstats.bbclass index 4fa6981dd6..71469e401d 100644 --- a/meta/classes/buildstats.bbclass +++ b/meta/classes/buildstats.bbclass @@ -20,17 +20,33 @@ def get_cputime(): fields = f.readline().rstrip().split()[1:] return sum(int(field) for field in fields) -def set_timedata(var, d, server_time=None): - import time - if server_time: - time = server_time +def set_timedata(var, d, server_time): + cputime = get_cputime() + proctime = get_process_cputime(os.getpid()) + d.setVar(var, (server_time, cputime, proctime)) + +def get_timedata(var, d, end_time): + timedata = d.getVar(var, False) + if timedata is None: + return + oldtime, oldcpu, oldproc = timedata + procdiff = get_process_cputime(os.getpid()) - oldproc + cpudiff = get_cputime() - oldcpu + timediff = end_time - oldtime + if cpudiff > 0: + cpuperc = float(procdiff) * 100 / cpudiff else: - time = time.time() + cpuperc = None + return timediff, cpuperc + +def set_buildtimedata(var, d): + import time + time = time.time() cputime = get_cputime() proctime = get_process_cputime(os.getpid()) d.setVar(var, (time, cputime, proctime)) -def get_timedata(var, d, server_time=None): +def get_buildtimedata(var, d): import time timedata = d.getVar(var, False) if timedata is None: @@ -38,10 +54,7 @@ def get_timedata(var, d, server_time=None): oldtime, oldcpu, oldproc = timedata procdiff = get_process_cputime(os.getpid()) - oldproc cpudiff = get_cputime() - oldcpu - if server_time: - end_time = server_time - else: - end_time = time.time() + end_time = time.time() timediff = end_time - oldtime if cpudiff > 0: cpuperc = float(procdiff) * 100 / cpudiff @@ -81,7 +94,7 @@ python run_buildstats () { # set the buildname ######################################################################## bb.utils.mkdirhier(bsdir) - set_timedata("__timedata_build", d) + set_buildtimedata("__timedata_build", d) build_time = os.path.join(bsdir, "build_stats") # write start of build into build_time with open(build_time, "a") as f: @@ -99,7 +112,7 @@ python run_buildstats () { ######################################################################## # Write build statistics for the build ######################################################################## - timedata = get_timedata("__timedata_build", d) + timedata = get_buildtimedata("__timedata_build", d) if timedata: time, cpu = timedata # write end of build and cpu used into build_time -- cgit v1.2.3-54-g00ecf