summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastermain/management/commands/perf.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/toastermain/management/commands/perf.py')
-rw-r--r--bitbake/lib/toaster/toastermain/management/commands/perf.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastermain/management/commands/perf.py b/bitbake/lib/toaster/toastermain/management/commands/perf.py
new file mode 100644
index 0000000000..d28f26ab16
--- /dev/null
+++ b/bitbake/lib/toaster/toastermain/management/commands/perf.py
@@ -0,0 +1,53 @@
1from django.core.management.base import BaseCommand
2from django.test.client import Client
3import os, sys, re
4import requests
5import toastermain.settings as settings
6
7class Command(BaseCommand):
8 help = "Test the response time for all toaster urls"
9
10 def handle(self, *args, **options):
11 root_urlconf = __import__(settings.ROOT_URLCONF)
12 patterns = root_urlconf.urls.urlpatterns
13 global full_url
14 for pat in patterns:
15 if pat.__class__.__name__ == 'RegexURLResolver':
16 url_root_res = str(pat).split('^')[1].replace('>', '')
17 if 'gui' in url_root_res:
18 for url_patt in pat.url_patterns:
19 full_url = self.get_full_url(url_patt, url_root_res)
20 info = self.url_info(full_url)
21 status_code = info[0]
22 load_time = info[1]
23 print 'Trying \'' + full_url + '\', ' + str(status_code) + ', ' + str(load_time)
24
25 def get_full_url(self, url_patt, url_root_res):
26 full_url = str(url_patt).split('^')[1].replace('$>', '').replace('(?P<file_path>(?:/[', '/bin/busybox').replace('.*', '')
27 full_url = str(url_root_res + full_url)
28 full_url = re.sub('\(\?P<.*?>\\\d\+\)', '1', full_url)
29 full_url = 'http://localhost:8000/' + full_url
30 return full_url
31
32 def url_info(self, full_url):
33 client = Client()
34 info = []
35 try:
36 resp = client.get(full_url, follow = True)
37 except Exception as e_status_code:
38 self.error('Url: %s, error: %s' % (full_url, e_status_code))
39 resp = type('object', (), {'status_code':0, 'content': str(e_status_code)})
40 status_code = resp.status_code
41 info.append(status_code)
42 try:
43 req = requests.get(full_url)
44 except Exception as e_load_time:
45 self.error('Url: %s, error: %s' % (full_url, e_load_time))
46 load_time = req.elapsed
47 info.append(load_time)
48 return info
49
50 def error(self, *args):
51 for arg in args:
52 print >>sys.stderr, arg,
53 print >>sys.stderr