All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Lehtonen <markus.lehtonen@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 02/12] oeqa.buildperf: enable json-formatted results
Date: Mon, 29 Aug 2016 22:48:21 +0300	[thread overview]
Message-ID: <1472500111-12358-3-git-send-email-markus.lehtonen@linux.intel.com> (raw)
In-Reply-To: <1472500111-12358-1-git-send-email-markus.lehtonen@linux.intel.com>

Automatically create a json.formatted file (results.json) in the results
directory that contains results from all tests.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
---
 meta/lib/oeqa/buildperf/base.py | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py
index ed8ff4a..eed0266 100644
--- a/meta/lib/oeqa/buildperf/base.py
+++ b/meta/lib/oeqa/buildperf/base.py
@@ -11,6 +11,7 @@
 #
 """Build performance test base classes and functionality"""
 import glob
+import json
 import logging
 import os
 import re
@@ -80,6 +81,20 @@ def time_cmd(cmd, **kwargs):
     return ret, timedata
 
 
+class ResultsJsonEncoder(json.JSONEncoder):
+    """Extended encoder for build perf test results"""
+    unix_epoch = datetime.utcfromtimestamp(0)
+
+    def default(self, obj):
+        """Encoder for our types"""
+        if isinstance(obj, datetime):
+            # NOTE: we assume that all timestamps are in UTC time
+            return (obj - self.unix_epoch).total_seconds()
+        if isinstance(obj, timedelta):
+            return obj.total_seconds()
+        return json.JSONEncoder.default(self, obj)
+
+
 class BuildPerfTestResult(unittest.TextTestResult):
     """Runner class for executing the individual tests"""
     # List of test cases to run
@@ -143,6 +158,7 @@ class BuildPerfTestResult(unittest.TextTestResult):
     def stopTestRun(self):
         """Pre-run hook"""
         self.elapsed_time = datetime.utcnow() - self.start_time
+        self.write_results_json()
 
     def all_results(self):
         result_map = {'SUCCESS': self.successes,
@@ -190,6 +206,30 @@ class BuildPerfTestResult(unittest.TextTestResult):
                                              git_tag_rev))
             fobj.write(','.join(values) + '\n')
 
+    def write_results_json(self):
+        """Write test results into a json-formatted file"""
+        results = {'tester_host': self.hostname,
+                   'git_branch': self.git_branch,
+                   'git_commit': self.git_commit,
+                   'git_commit_count': self.git_commit_count,
+                   'product': self.product,
+                   'start_time': self.start_time,
+                   'elapsed_time': self.elapsed_time}
+
+        tests = {}
+        for status, (test, reason) in self.all_results():
+            tests[test.name] = {'name': test.name,
+                                'description': test.shortDescription(),
+                                'status': status,
+                                'start_time': test.start_time,
+                                'elapsed_time': test.elapsed_time,
+                                'measurements': test.measurements}
+        results['tests'] = tests
+
+        with open(os.path.join(self.out_dir, 'results.json'), 'w') as fobj:
+            json.dump(results, fobj, indent=4, sort_keys=True,
+                      cls=ResultsJsonEncoder)
+
 
     def git_commit_results(self, repo_path, branch=None, tag=None):
         """Commit results into a Git repository"""
-- 
2.6.6



  parent reply	other threads:[~2016-08-29 19:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29 19:48 [PATCH 00/12] oe-build-perf-test: new format for test output data Markus Lehtonen
2016-08-29 19:48 ` [PATCH 01/12] oeqa.buildperf: add 'product' to test result data Markus Lehtonen
2016-08-29 19:48 ` Markus Lehtonen [this message]
2016-08-29 19:48 ` [PATCH 03/12] oe-build-perf-test: rename log file and implement --log-file Markus Lehtonen
2016-08-29 19:48 ` [PATCH 04/12] oeqa.buildperf: strip date from buildstats directory path Markus Lehtonen
2016-08-29 19:48 ` [PATCH 05/12] oeqa.buildperf: separate output dir for each test Markus Lehtonen
2016-08-29 19:48 ` [PATCH 06/12] oeqa.buildperf: rename buildstats directories Markus Lehtonen
2016-08-29 19:48 ` [PATCH 07/12] oeqa.buildperf: don't use Gnu time Markus Lehtonen
2016-08-29 19:48 ` [PATCH 08/12] oeqa.buildperf: measure io stat Markus Lehtonen
2016-08-29 19:48 ` [PATCH 09/12] oeqa.buildperf: convert buildstats into json format Markus Lehtonen
2016-08-29 19:48 ` [PATCH 10/12] oeqa.buildperf: show skipped tests in results, too Markus Lehtonen
2016-08-29 19:48 ` [PATCH 11/12] oeqa.buildperf: include buildstats file name in results.json Markus Lehtonen
2016-08-29 19:48 ` [PATCH 12/12] oeqa.buildperf: include commands log " Markus Lehtonen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472500111-12358-3-git-send-email-markus.lehtonen@linux.intel.com \
    --to=markus.lehtonen@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.