summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorIonut Chisanovici <ionutx.chisanovici@intel.com>2014-05-28 15:52:26 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-06-20 14:03:05 +0100
commit4a1fc6851d21500150715f0e8fa03c0b228ec5f2 (patch)
tree7a60e7e4af4a80a97c1395d03ddeede6d196d83e /lib
parentb21a2af9411da17d49521820fa512292e89c856e (diff)
downloadbitbake-contrib-4a1fc6851d21500150715f0e8fa03c0b228ec5f2.tar.gz
toaster: Add performance testing script
This is implemented as a django management command. For the moment the 'manage.py perf' command will track the toaster 'gui' urls http response code and load time. To use it: 1. do your toaster builds 2. ensure toaster is started 1. cd bitbake/lib/toaster 2. ln -s ../../../build/toaster.sqlite 3. ./manage.py perf Signed-off-by: Ionut Chisanovici <ionutx.chisanovici@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/toaster/toastermain/management/commands/perf.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/toaster/toastermain/management/commands/perf.py b/lib/toaster/toastermain/management/commands/perf.py
new file mode 100644
index 000000000..d28f26ab1
--- /dev/null
+++ b/lib/toaster/toastermain/management/commands/perf.py
@@ -0,0 +1,53 @@
+from django.core.management.base import BaseCommand
+from django.test.client import Client
+import os, sys, re
+import requests
+import toastermain.settings as settings
+
+class Command(BaseCommand):
+ help = "Test the response time for all toaster urls"
+
+ def handle(self, *args, **options):
+ root_urlconf = __import__(settings.ROOT_URLCONF)
+ patterns = root_urlconf.urls.urlpatterns
+ global full_url
+ for pat in patterns:
+ if pat.__class__.__name__ == 'RegexURLResolver':
+ url_root_res = str(pat).split('^')[1].replace('>', '')
+ if 'gui' in url_root_res:
+ for url_patt in pat.url_patterns:
+ full_url = self.get_full_url(url_patt, url_root_res)
+ info = self.url_info(full_url)
+ status_code = info[0]
+ load_time = info[1]
+ print 'Trying \'' + full_url + '\', ' + str(status_code) + ', ' + str(load_time)
+
+ def get_full_url(self, url_patt, url_root_res):
+ full_url = str(url_patt).split('^')[1].replace('$>', '').replace('(?P<file_path>(?:/[', '/bin/busybox').replace('.*', '')
+ full_url = str(url_root_res + full_url)
+ full_url = re.sub('\(\?P<.*?>\\\d\+\)', '1', full_url)
+ full_url = 'http://localhost:8000/' + full_url
+ return full_url
+
+ def url_info(self, full_url):
+ client = Client()
+ info = []
+ try:
+ resp = client.get(full_url, follow = True)
+ except Exception as e_status_code:
+ self.error('Url: %s, error: %s' % (full_url, e_status_code))
+ resp = type('object', (), {'status_code':0, 'content': str(e_status_code)})
+ status_code = resp.status_code
+ info.append(status_code)
+ try:
+ req = requests.get(full_url)
+ except Exception as e_load_time:
+ self.error('Url: %s, error: %s' % (full_url, e_load_time))
+ load_time = req.elapsed
+ info.append(load_time)
+ return info
+
+ def error(self, *args):
+ for arg in args:
+ print >>sys.stderr, arg,
+ print >>sys.stderr