Skip to contentSkip to conversation

oe-build-perf-test: re-organize buildstats archiving

PATCH New Markus Lehtonen 1 participant 7 messages Mar 24, 2017

lore
Share & tools
lore
#2 lore raw

PATCH 2/6 oe-build-perf-test: sum rusage in buildstats

In reply to Markus Lehtonen

Instead of separate rusage and child rusage values, only store their sum value in buildstats. This is a big reduction in data footprint without really losing any interesting data.

Also, utilize OrderedDict to order data more logically.

[YOCTO #10582]

---
 meta/lib/oeqa/buildperf/base.py | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
meta/lib/oeqa/buildperf/base.py +12 -12
index ffe42dc..aa5c5ad 100644
@@ -411,9 +411,9 @@ class BuildPerfTestCase(unittest.TestCase):
 
         def bs_to_json(filename):
             """Convert (task) buildstats file into json format"""
-            bs_json = {'iostat': {},
-                       'rusage': {},
-                       'child_rusage': {}}
+            bs_json = OrderedDict()
+            iostat = OrderedDict()
+            rusage = OrderedDict()
             with open(filename) as fobj:
                 for line in fobj.readlines():
                     key, val = line.split(':', 1)
@@ -425,7 +425,7 @@ class BuildPerfTestCase(unittest.TestCase):
                         end_time = datetime.utcfromtimestamp(float(val))
                     elif key.startswith('IO '):
                         split = key.split()
-                        bs_json['iostat'][split[1]] = int(val)
+                        iostat[split[1]] = int(val)
                     elif key.find('rusage') >= 0:
                         split = key.split()
                         ru_key = split[-1]
@@ -433,12 +433,12 @@ class BuildPerfTestCase(unittest.TestCase):
                             val = float(val)
                         else:
                             val = int(val)
-                        ru_type = 'rusage' if split[0] == 'rusage' else \
-                                                          'child_rusage'
-                        bs_json[ru_type][ru_key] = val
+                        rusage[ru_key] = rusage.get(ru_key, 0) + val
                     elif key == 'Status':
                         bs_json['status'] = val
             bs_json['elapsed_time'] = end_time - start_time
+            bs_json['rusage'] = rusage
+            bs_json['iostat'] = iostat
             return bs_json
 
         log.info('Saving buildstats in JSON format')
@@ -454,11 +454,11 @@ class BuildPerfTestCase(unittest.TestCase):
             if not os.path.isdir(recipe_dir):
                 continue
             name, epoch, version, revision = split_nevr(fname)
-            recipe_bs = {'name': name,
-                         'epoch': epoch,
-                         'version': version,
-                         'revision': revision,
-                         'tasks': {}}
+            recipe_bs = OrderedDict((('name', name),
+                                     ('epoch', epoch),
+                                     ('version', version),
+                                     ('revision', revision),
+                                     ('tasks', OrderedDict())))
             for task in os.listdir(recipe_dir):
                 recipe_bs['tasks'][task] = bs_to_json(os.path.join(recipe_dir,
                                                                    task))
Signature · 1 line
2.6.6
#3 lore raw

PATCH 3/6 scripts/oe-git-archive: fix pushing

In reply to Markus Lehtonen

Git arguments were badly laid out.

---
 scripts/oe-git-archive | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
scripts/oe-git-archive +3 -2
index 117118b..aef4ba1 100755
@@ -231,9 +231,10 @@ def main(argv=None):
         # Push data to remote
         if args.push:
             cmd = ['push', '--tags']
+            # If no remote is given we push with the default settings from
+            # gitconfig
             if args.push is not True:
-                cmd.extend(['--repo', args.push])
-                cmd.append(branch_name)
+                cmd.extend([args.push, branch_name])
             log.info("Pushing data to remote")
             data_repo.run_cmd(cmd)
 
Signature · 1 line
2.6.6
#4 lore raw

PATCH 4/6 scripts/oe-git-archive: implement --exclude

In reply to Markus Lehtonen

May be used for excluding certain files from the commit.

[YOCTO #10582]

---
 scripts/oe-git-archive | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
scripts/oe-git-archive +10 -2
index aef4ba1..1805ab3 100755
@@ -83,7 +83,7 @@ def init_git_repo(path, no_create, bare):
     return repo
 
 
-def git_commit_data(repo, data_dir, branch, message):
+def git_commit_data(repo, data_dir, branch, message, exclude):
     """Commit data into a Git repository"""
     log.info("Committing data into to branch %s", branch)
     tmp_index = os.path.join(repo.git_dir, 'index.oe-git-archive')
@@ -92,6 +92,11 @@ def git_commit_data(repo, data_dir, branch, message):
         env_update = {'GIT_INDEX_FILE': tmp_index,
                       'GIT_WORK_TREE': os.path.abspath(data_dir)}
         repo.run_cmd('add .', env_update)
+
+        # Remove files that are excluded
+        if exclude:
+            repo.run_cmd(['rm', '--cached'] + [f for f in exclude], env_update)
+
         tree = repo.run_cmd('write-tree', env_update)
 
         # Create new commit object from the tree
@@ -183,6 +188,9 @@ def parse_args(argv):
     parser.add_argument('--tag-msg-body',
                         default='',
                         help="Tag message body (pattern)")
+    parser.add_argument('--exclude', action='append', default=[],
+                        help="Glob to exclude files from the commit. Relative "
+                             "to DATA_DIR. May be specified multiple times")
     parser.add_argument('data_dir', metavar='DATA_DIR',
                         help="Data to commit")
     return parser.parse_args(argv)
@@ -221,7 +229,7 @@ def main(argv=None):
 
         # Commit data
         commit = git_commit_data(data_repo, args.data_dir, branch_name,
-                                 commit_msg)
+                                 commit_msg, args.exclude)
 
         # Create tag
         if tag_name:
Signature · 1 line
2.6.6
#5 lore raw

PATCH 5/6 scripts/oe-git-archive: implement --notes

In reply to Markus Lehtonen

Option for adding git-notes to the commit.

[YOCTO #10582]

---
 scripts/oe-git-archive | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
scripts/oe-git-archive +18 -3
index 1805ab3..ab19cb9 100755
@@ -83,7 +83,7 @@ def init_git_repo(path, no_create, bare):
     return repo
 
 
-def git_commit_data(repo, data_dir, branch, message, exclude):
+def git_commit_data(repo, data_dir, branch, message, exclude, notes):
     """Commit data into a Git repository"""
     log.info("Committing data into to branch %s", branch)
     tmp_index = os.path.join(repo.git_dir, 'index.oe-git-archive')
@@ -106,6 +106,12 @@ def git_commit_data(repo, data_dir, branch, message, exclude):
             git_cmd += ['-p', parent]
         commit = repo.run_cmd(git_cmd, env_update)
 
+        # Create git notes
+        for ref, filename in notes:
+            ref = ref.format(branch_name=branch)
+            repo.run_cmd(['notes', '--ref', ref, 'add',
+                          '-F', os.path.abspath(filename), commit])
+
         # Update branch head
         git_cmd = ['update-ref', 'refs/heads/' + branch, commit]
         if parent:
@@ -191,6 +197,13 @@ def parse_args(argv):
     parser.add_argument('--exclude', action='append', default=[],
                         help="Glob to exclude files from the commit. Relative "
                              "to DATA_DIR. May be specified multiple times")
+    parser.add_argument('--notes', nargs=2, action='append', default=[],
+                        metavar=('GIT_REF', 'FILE'),
+                        help="Add a file as a note under refs/notes/GIT_REF. "
+                             "{branch_name} in GIT_REF will be expanded to the "
+                             "actual target branch name (specified by "
+                             "--branch-name). This option may be specified "
+                             "multiple times.")
     parser.add_argument('data_dir', metavar='DATA_DIR',
                         help="Data to commit")
     return parser.parse_args(argv)
@@ -229,7 +242,7 @@ def main(argv=None):
 
         # Commit data
         commit = git_commit_data(data_repo, args.data_dir, branch_name,
-                                 commit_msg, args.exclude)
+                                 commit_msg, args.exclude, args.notes)
 
         # Create tag
         if tag_name:
@@ -242,7 +255,9 @@ def main(argv=None):
             # If no remote is given we push with the default settings from
             # gitconfig
             if args.push is not True:
-                cmd.extend([args.push, branch_name])
+                notes_refs = ['refs/notes/' + ref.format(branch_name=branch_name)
+                                for ref, _ in args.notes]
+                cmd.extend([args.push, branch_name] + notes_refs)
             log.info("Pushing data to remote")
             data_repo.run_cmd(cmd)
 
Signature · 1 line
2.6.6
#6 lore raw

PATCH 6/6 build-perf-test-wrapper.sh: store buildstats under git-notes

In reply to Markus Lehtonen

In order to dramatically reduce the data footprint of the result branches. This makes cloning/pulling result repositories a lot faster. Buildstats can still be accessed, when needed by doing
git fetch refs/notes/buildstats/*:refs/notes/buildstats/*

[YOCTO #10582]

---
 scripts/contrib/build-perf-test-wrapper.sh | 2 ++
 1 file changed, 2 insertions(+)
scripts/contrib/build-perf-test-wrapper.sh +2 -0
index 240d669..234652d 100755
@@ -143,6 +143,8 @@ if [ -n "$results_repo" ]; then
         --git-dir "$results_repo" \
         --branch-name "{hostname}/{branch}/{machine}" \
         --tag-name "{hostname}/{branch}/{machine}/{commit_count}-g{commit}/{tag_number}" \
+        --exclude "buildstats.json" \
+        --notes "buildstats/{branch_name}" "$results_dir/buildstats.json" \
         "$results_dir"
 fi
 
Signature · 1 line
2.6.6
#0 lore raw

cover oe-build-perf-test: re-organize buildstats archiving

This patchset optimizes the way buildstats are stored in oe-build-perf-test result data. After this change buildstats are stored under refs/notes/buildstats/* in Git, and thus, they're not cloned/fetched by default. The motivation is to reduce the data footprint as buildstats are rarely used but they take a lot of space. With thousands of test runs, the amount of data transfer required by git clone drops from the order of gigabytes to megabytes. If needed for deeper analysis, buildstats can always be fetched separately.

The first patch in this changeset packs all buildstats into one JSON-formatted file so that they're easier to work with under git-notes.

The second patch optimizes buildstats data footprint by combining rusage values.

Patches #3, #4 and #5 add oe-git-archive script the ability to store data under git-notes, also fixing one bug in the git push functionality.

The last patch changes the build perf test worker script to store buildstats under git-notes.

The following changes since commit 3b5ac72bdf76ac8ff98dc3c882a4edc77c6e2c33:

rpm: add a "rpm-build" PROVIDES (2017-03-22 15:09:26 +0000)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib marquiz/buildperf/buildstats
http://git.openembedded.org/openembedded-core-contrib/log/?h=marquiz/buildperf/buildstats

Markus Lehtonen (6):
oe-build-perf-test: pack all buildstat in one file
oe-build-perf-test: sum rusage in buildstats scripts/oe-git-archive: fix pushing scripts/oe-git-archive: implement --exclude scripts/oe-git-archive: implement --notes build-perf-test-wrapper.sh: store buildstats under git-notes

 meta/lib/oeqa/buildperf/base.py            | 66 ++++++++++++++++--------------
 meta/lib/oeqa/buildperf/test_basic.py      | 24 +++++------
 scripts/contrib/build-perf-test-wrapper.sh |  2 +
 scripts/oe-build-perf-test                 |  1 +
 scripts/oe-git-archive                     | 32 +++++++++++++--
 5 files changed, 78 insertions(+), 47 deletions(-)
Signature · 1 line
2.6.6
#1 lore raw

PATCH 1/6 oe-build-perf-test: pack all buildstat in one file

Write out all buildstats into one big json file, instead of using multiple per-measurement files. Individual buildstats will be indexed using "<test_name>.<measurement_name>" as the key. Also, changes the per-testcase working directories into temporary directories that will be removed after test execution as there are no more per-testcase data files to store permanently.

[YOCTO #10582]

---
 meta/lib/oeqa/buildperf/base.py       | 42 ++++++++++++++++++++---------------
 meta/lib/oeqa/buildperf/test_basic.py | 24 +++++++++-----------
 scripts/oe-build-perf-test            |  1 +
 3 files changed, 36 insertions(+), 31 deletions(-)
meta/lib/oeqa/buildperf/base.py +24 -18
index dd473a0..ffe42dc 100644
@@ -16,6 +16,7 @@ import os
 import re
 import resource
 import socket
+import shutil
 import time
 import unittest
 import xml.etree.ElementTree as ET
@@ -127,7 +128,6 @@ class BuildPerfTestResult(unittest.TextTestResult):
     def startTest(self, test):
         """Pre-test hook"""
         test.base_dir = self.out_dir
-        os.mkdir(test.out_dir)
         log.info("Executing test %s: %s", test.name, test.shortDescription())
         self.stream.write(datetime.now().strftime("[%Y-%m-%d %H:%M:%S] "))
         super(BuildPerfTestResult, self).startTest(test)
@@ -150,6 +150,16 @@ class BuildPerfTestResult(unittest.TextTestResult):
         return sorted(compound, key=lambda info: info[1].start_time)
 
 
+    def write_buildstats_json(self):
+        """Write buildstats file"""
+        buildstats = OrderedDict()
+        for _, test, _ in self.all_results():
+            for key, val in test.buildstats.items():
+                buildstats[test.name + '.' + key] = val
+        with open(os.path.join(self.out_dir, 'buildstats.json'), 'w') as fobj:
+            json.dump(buildstats, fobj, cls=ResultsJsonEncoder)
+
+
     def write_results_json(self):
         """Write test results into a json-formatted file"""
         results = OrderedDict([('tester_host', self.hostname),
@@ -221,8 +231,6 @@ class BuildPerfTestResult(unittest.TextTestResult):
                     ET.SubElement(measurement, 'time',
                                   timestamp=vals['start_time'].isoformat()).text = \
                         str(vals['elapsed_time'].total_seconds())
-                    if 'buildstats_file' in vals:
-                        ET.SubElement(measurement, 'buildstats_file').text = vals['buildstats_file']
                     attrib = dict((k, str(v)) for k, v in vals['iostat'].items())
                     ET.SubElement(measurement, 'iostat', attrib=attrib)
                     attrib = dict((k, str(v)) for k, v in vals['rusage'].items())
@@ -238,7 +246,6 @@ class BuildPerfTestResult(unittest.TextTestResult):
         dom_doc = minidom.parseString(ET.tostring(top, 'utf-8'))
         with open(os.path.join(self.out_dir, 'results.xml'), 'w') as fobj:
             dom_doc.writexml(fobj, addindent='  ', newl='\n', encoding='utf-8')
-        return
 
 
 class BuildPerfTestCase(unittest.TestCase):
@@ -254,6 +261,7 @@ class BuildPerfTestCase(unittest.TestCase):
         self.start_time = None
         self.elapsed_time = None
         self.measurements = OrderedDict()
+        self.buildstats = OrderedDict()
         # self.err is supposed to be a tuple from sys.exc_info()
         self.err = None
         self.bb_vars = get_bb_vars()
@@ -263,17 +271,24 @@ class BuildPerfTestCase(unittest.TestCase):
         self.sizes = []
 
     @property
-    def out_dir(self):
-        return os.path.join(self.base_dir, self.name)
+    def tmp_dir(self):
+        return os.path.join(self.base_dir, self.name + '.tmp')
 
     def shortDescription(self):
         return super(BuildPerfTestCase, self).shortDescription() or ""
 
     def setUp(self):
         """Set-up fixture for each test"""
+        if not os.path.isdir(self.tmp_dir):
+            os.mkdir(self.tmp_dir)
         if self.build_target:
             self.run_cmd(['bitbake', self.build_target, '-c', 'fetchall'])
 
+    def tearDown(self):
+        """Tear-down fixture for each test"""
+        if os.path.isdir(self.tmp_dir):
+            shutil.rmtree(self.tmp_dir)
+
     def run(self, *args, **kwargs):
         """Run test"""
         self.start_time = datetime.now()
@@ -349,9 +364,7 @@ class BuildPerfTestCase(unittest.TestCase):
                                              ('rusage', data['rusage']),
                                              ('iostat', data['iostat'])])
         if save_bs:
-            bs_file = self.save_buildstats(legend)
-            measurement['values']['buildstats_file'] = \
-                    os.path.relpath(bs_file, self.base_dir)
+            self.save_buildstats(name)
 
         self._append_measurement(measurement)
 
@@ -379,7 +392,7 @@ class BuildPerfTestCase(unittest.TestCase):
         # Append to 'sizes' array for globalres log
         self.sizes.append(str(size))
 
-    def save_buildstats(self, label=None):
+    def save_buildstats(self, measurement_name):
         """Save buildstats"""
         def split_nevr(nevr):
             """Split name and version information from recipe "nevr" string"""
@@ -451,14 +464,7 @@ class BuildPerfTestCase(unittest.TestCase):
                                                                    task))
             buildstats.append(recipe_bs)
 
-        # Write buildstats into json file
-        postfix = '.' + str_to_fn(label) if label else ''
-        postfix += '.json'
-        outfile = os.path.join(self.out_dir, 'buildstats' + postfix)
-        with open(outfile, 'w') as fobj:
-            json.dump(buildstats, fobj, indent=4, sort_keys=True,
-                      cls=ResultsJsonEncoder)
-        return outfile
+        self.buildstats[measurement_name] = buildstats
 
     def rm_tmp(self):
         """Cleanup temporary/intermediate files and directories"""
meta/lib/oeqa/buildperf/test_basic.py +11 -13
index 1333407..a9e4a5b 100644
@@ -51,21 +51,19 @@ class Test1P3(BuildPerfTestCase):
 
     def test13(self):
         """Build core-image-sato with rm_work enabled"""
-        postfile = os.path.join(self.out_dir, 'postfile.conf')
+        postfile = os.path.join(self.tmp_dir, 'postfile.conf')
         with open(postfile, 'w') as fobj:
             fobj.write('INHERIT += "rm_work"\n')
-        try:
-            self.rm_tmp()
-            self.rm_sstate()
-            self.rm_cache()
-            self.sync()
-            cmd = ['bitbake', '-R', postfile, self.build_target]
-            self.measure_cmd_resources(cmd, 'build',
-                                       'bitbake' + self.build_target,
-                                       save_bs=True)
-            self.measure_disk_usage(self.bb_vars['TMPDIR'], 'tmpdir', 'tmpdir')
-        finally:
-            os.unlink(postfile)
+
+        self.rm_tmp()
+        self.rm_sstate()
+        self.rm_cache()
+        self.sync()
+        cmd = ['bitbake', '-R', postfile, self.build_target]
+        self.measure_cmd_resources(cmd, 'build',
+                                   'bitbake' + self.build_target,
+                                   save_bs=True)
+        self.measure_disk_usage(self.bb_vars['TMPDIR'], 'tmpdir', 'tmpdir')
 
 
 class Test2(BuildPerfTestCase):
scripts/oe-build-perf-test +1 -0
index 8950c32..669470f 100755
@@ -209,6 +209,7 @@ def main(argv=None):
         result.write_results_xml()
     else:
         result.write_results_json()
+    result.write_buildstats_json()
     if args.globalres_file:
         update_globalres_file(result, args.globalres_file, metadata)
     if result.wasSuccessful():
Signature · 1 line
2.6.6