Add a script to post new OS X builds to perf dashboard
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jun 2015 19:28:38 +0000 (19:28 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jun 2015 19:28:38 +0000 (19:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145955

Reviewed by Darin Adler.

Added a new script pull-osx.py and relaxed the restrictions on commits accepted by the dashboard API.

* public/api/report-commits.php:
(main): Allow more characters than [A-Za-z0-9] in revision. e.g. "10.10.3 14D136".
Also allow commits without the author, commit time, and commit message as OS versions do not have those.

* tools/pull-osx.py: Added.
(main): Fetch the list of builds from a website and submit them per submissionSize with submissionInterval.
Once all builds have been submitted, wait for a long time as specified by fetchInterval.
(setup_auth): Sets up basic or digest auth to access the dashboard.
(fetch_available_builds): Fetches and parses the XML document from an internal website.
(textContent): A helper function to get the text content out of a XML node.
(submit_commits): Submits commits to the perf dashboard.

* tools/pull-svn.py:
(fetch_commit):

* tools/util.py: Extracted submit_commits and text_content from pull-svn.py to be reused in pull-osx.py.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185539 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/perf.webkit.org/ChangeLog
Websites/perf.webkit.org/public/api/report-commits.php
Websites/perf.webkit.org/tools/pull-osx.py [new file with mode: 0755]
Websites/perf.webkit.org/tools/pull-svn.py
Websites/perf.webkit.org/tools/util.py [new file with mode: 0644]

index affd2bb..b01d375 100644 (file)
@@ -1,5 +1,31 @@
 2015-06-13  Ryosuke Niwa  <rniwa@webkit.org>
 
+        Add a script to post new OS X builds to perf dashboard
+        https://bugs.webkit.org/show_bug.cgi?id=145955
+
+        Reviewed by Darin Adler.
+
+        Added a new script pull-osx.py and relaxed the restrictions on commits accepted by the dashboard API.
+
+        * public/api/report-commits.php:
+        (main): Allow more characters than [A-Za-z0-9] in revision. e.g. "10.10.3 14D136".
+        Also allow commits without the author, commit time, and commit message as OS versions do not have those.
+
+        * tools/pull-osx.py: Added.
+        (main): Fetch the list of builds from a website and submit them per submissionSize with submissionInterval.
+        Once all builds have been submitted, wait for a long time as specified by fetchInterval.
+        (setup_auth): Sets up basic or digest auth to access the dashboard.
+        (fetch_available_builds): Fetches and parses the XML document from an internal website.
+        (textContent): A helper function to get the text content out of a XML node.
+        (submit_commits): Submits commits to the perf dashboard.
+
+        * tools/pull-svn.py:
+        (fetch_commit):
+
+        * tools/util.py: Extracted submit_commits and text_content from pull-svn.py to be reused in pull-osx.py.
+
+2015-06-13  Ryosuke Niwa  <rniwa@webkit.org>
+
         Perf dashboard's v2 UI shouldn't hide auto-detected outliers
         https://bugs.webkit.org/show_bug.cgi?id=145940
 
index d4026f2..6e6c734 100644 (file)
@@ -18,12 +18,9 @@ function main($post_data) {
             exit_with_error('MissingRepositoryName', array('commit' => $commit_info));
         if (!array_key_exists('revision', $commit_info))
             exit_with_error('MissingRevision', array('commit' => $commit_info));
-        if (!ctype_alnum($commit_info['revision']))
-            exit_with_error('InvalidRevision', array('commit' => $commit_info));
-        if (!array_key_exists('time', $commit_info))
-            exit_with_error('MissingTimestamp', array('commit' => $commit_info));
-        if (!array_key_exists('author', $commit_info) || !is_array($commit_info['author']))
-            exit_with_error('MissingAuthorOrInvalidFormat', array('commit' => $commit_info));
+        require_format('Revision', $commit_info['revision'], '/^[A-Za-z0-9 \.]+$/');
+        if (array_key_exists('author', $commit_info) && !is_array($commit_info['author']))
+            exit_with_error('InvalidAuthorFormat', array('commit' => $commit_info));
     }
 
     $db->begin_transaction();
@@ -34,16 +31,20 @@ function main($post_data) {
             exit_with_error('FailedToInsertRepository', array('commit' => $commit_info));
         }
 
-        $account = array_get($commit_info['author'], 'account');
-        $committer_query = array('repository' => $repository_id, 'account' => $account);
-        $committer_data = $committer_query;
-        $name = array_get($commit_info['author'], 'name');
-        if ($name)
-            $committer_data['name'] = $name;
-        $committer_id = $db->update_or_insert_row('committers', 'committer', $committer_query, $committer_data);
-        if (!$committer_id) {
-            $db->rollback_transaction();
-            exit_with_error('FailedToInsertCommitter', array('committer' => $committer_data));
+        $author = array_get($commit_info, 'author');
+        $committer_id = NULL;
+        if ($author) {
+            $account = array_get($author, 'account');
+            $committer_query = array('repository' => $repository_id, 'account' => $account);
+            $committer_data = $committer_query;
+            $name = array_get($author, 'name');
+            if ($name)
+                $committer_data['name'] = $name;
+            $committer_id = $db->update_or_insert_row('committers', 'committer', $committer_query, $committer_data);
+            if (!$committer_id) {
+                $db->rollback_transaction();
+                exit_with_error('FailedToInsertCommitter', array('committer' => $committer_data));
+            }
         }
 
         $parent_revision = array_get($commit_info, 'parent');
@@ -61,9 +62,9 @@ function main($post_data) {
             'repository' => $repository_id,
             'revision' => $commit_info['revision'],
             'parent' => $parent_id,
-            'time' => $commit_info['time'],
+            'time' => array_get($commit_info, 'time'),
             'committer' => $committer_id,
-            'message' => $commit_info['message'],
+            'message' => array_get($commit_info, 'message'),
             'reported' => true,
         );
         $db->update_or_insert_row('commits', 'commit', array('repository' => $repository_id, 'revision' => $data['revision']), $data);
diff --git a/Websites/perf.webkit.org/tools/pull-osx.py b/Websites/perf.webkit.org/tools/pull-osx.py
new file mode 100755 (executable)
index 0000000..69e3d25
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+import argparse
+import json
+import sys
+import time
+import urllib
+import urllib2
+
+from xml.dom.minidom import parseString as parseXmlString
+from util import submit_commits
+from util import text_content
+
+
+HTTP_AUTH_HANDLERS = {
+    'basic': urllib2.HTTPBasicAuthHandler,
+    'digest': urllib2.HTTPDigestAuthHandler,
+}
+
+
+def main(argv):
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--config', required=True, help='Path to a config JSON file')
+    args = parser.parse_args()
+
+    with open(args.config) as config_file:
+        config = json.load(config_file)
+
+    setup_auth(config['server'])
+
+    url = config['buildSourceURL']
+    submission_size = config['submissionSize']
+    reported_revisions = set()
+
+    while True:
+        print "Fetching available builds from %s" % url
+        available_builds = fetch_available_builds(url, config['trainVersionMap'])
+        available_builds = filter(lambda commit: commit['revision'] not in reported_revisions, available_builds)
+        print "%d builds available" % len(available_builds)
+
+        while True:
+            commits_to_submit = available_builds[:submission_size]
+            revisions_to_report = map(lambda commit: commit['revision'], commits_to_submit)
+            print "Submitting builds (%d remaining):" % len(available_builds), json.dumps(revisions_to_report)
+            available_builds = available_builds[submission_size:]
+
+            submit_commits(commits_to_submit, config['server']['url'], config['slave']['name'], config['slave']['password'])
+            reported_revisions |= set(revisions_to_report)
+
+            time.sleep(config['submissionInterval'])
+
+        time.sleep(config['fetchInterval'])
+
+
+def setup_auth(server):
+    auth = server.get('auth')
+    if not auth:
+        return
+
+    password_manager = urllib2.HTTPPasswordMgr()
+    password_manager.add_password(realm=auth['realm'], uri=server['url'], user=auth['username'], passwd=auth['password'])
+    auth_handler = HTTP_AUTH_HANDLERS[auth['type']](password_manager)
+    urllib2.install_opener(urllib2.build_opener(auth_handler))
+
+
+def fetch_available_builds(url, train_version_map):
+    output = urllib2.urlopen(url).read()
+    try:
+        xml = parseXmlString(output)
+    except Exception, error:
+        raise Exception(error, output)
+    available_builds = []
+    for image in xml.getElementsByTagName('baseASR'):
+        id = text_content(image.getElementsByTagName('id')[0])
+        train = text_content(image.getElementsByTagName('train')[0])
+        build = text_content(image.getElementsByTagName('build')[0])
+        if train not in train_version_map:
+            continue
+        available_builds.append({
+            'repository': 'OS X',
+            'revision': train_version_map[train] + ' ' + build})
+
+    return available_builds
+
+
+if __name__ == "__main__":
+    main(sys.argv)
index da6d0ad..01f0b49 100755 (executable)
@@ -8,6 +8,8 @@ import time
 import urllib2
 
 from xml.dom.minidom import parseString as parseXmlString
+from util import submit_commits
+from util import text_content
 
 
 def main(argv):
@@ -103,9 +105,9 @@ def fetch_commit(repository_name, repository_url, revision):
             return None
         raise error
     xml = parseXmlString(output)
-    time = textContent(xml.getElementsByTagName("date")[0])
-    author_account = textContent(xml.getElementsByTagName("author")[0])
-    message = textContent(xml.getElementsByTagName("msg")[0])
+    time = text_content(xml.getElementsByTagName("date")[0])
+    author_account = text_content(xml.getElementsByTagName("author")[0])
+    message = text_content(xml.getElementsByTagName("msg")[0])
     return {
         'repository': repository_name,
         'revision': revision,
@@ -115,16 +117,6 @@ def fetch_commit(repository_name, repository_url, revision):
     }
 
 
-def textContent(element):
-    text = ''
-    for child in element.childNodes:
-        if child.nodeType == child.TEXT_NODE:
-            text += child.data
-        else:
-            text += textContent(child)
-    return text
-
-
 name_account_compound_regex = re.compile(r'^\s*(?P<name>(\".+\"|[^<]+?))\s*\<(?P<account>.+)\>\s*$')
 
 
@@ -136,28 +128,5 @@ def resolve_author_name_from_account(helper, account):
     return output.strip()
 
 
-def submit_commits(commits, dashboard_url, slave_name, slave_password):
-    try:
-        payload = json.dumps({
-            'slaveName': slave_name,
-            'slavePassword': slave_password,
-            'commits': commits,
-        })
-        request = urllib2.Request(dashboard_url + '/api/report-commits')
-        request.add_header('Content-Type', 'application/json')
-        request.add_header('Content-Length', len(payload))
-
-        output = urllib2.urlopen(request, payload).read()
-        try:
-            result = json.loads(output)
-        except Exception, error:
-            raise Exception(error, output)
-
-        if result.get('status') != 'OK':
-            raise Exception(result)
-    except Exception as error:
-        sys.exit('Failed to submit commits: %s' % str(error))
-
-
 if __name__ == "__main__":
     main(sys.argv)
diff --git a/Websites/perf.webkit.org/tools/util.py b/Websites/perf.webkit.org/tools/util.py
new file mode 100644 (file)
index 0000000..2449a34
--- /dev/null
@@ -0,0 +1,36 @@
+import json
+import sys
+import urllib2
+
+
+def submit_commits(commits, dashboard_url, slave_name, slave_password):
+    try:
+        payload = json.dumps({
+            'slaveName': slave_name,
+            'slavePassword': slave_password,
+            'commits': commits,
+        })
+        request = urllib2.Request(dashboard_url + '/api/report-commits')
+        request.add_header('Content-Type', 'application/json')
+        request.add_header('Content-Length', len(payload))
+
+        output = urllib2.urlopen(request, payload).read()
+        try:
+            result = json.loads(output)
+        except Exception, error:
+            raise Exception(error, output)
+
+        if result.get('status') != 'OK':
+            raise Exception(result)
+    except Exception as error:
+        sys.exit('Failed to submit commits: %s' % str(error))
+
+
+def text_content(element):
+    text = ''
+    for child in element.childNodes:
+        if child.nodeType == child.TEXT_NODE:
+            text += child.data
+        else:
+            text += text_content(child)
+    return text