-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshaped-measure.py
executable file
·41 lines (30 loc) · 1.01 KB
/
shaped-measure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import sys
from selenium import webdriver
from my_trafficshaper import TrafficShaper
def measure(url):
"""
Loads URL in Chrome and returns page load time in milliseconds.
Page load time is defined as the time elapsed between navigationStart and
loadEventEnd.
"""
if not (url.startswith("http://") or url.startswith("https://")):
url = "http://" + url
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
wd = webdriver.Chrome(chrome_options=options)
try:
wd.get(url)
loadTime = wd.execute_script("return (window.performance.timing.loadEventEnd - \
window.performance.timing.navigationStart)")
return loadTime
finally:
wd.quit()
def main():
url = sys.argv[1]
delay = sys.argv[2]
bw = sys.argv[3]
with TrafficShaper(up_bandwidth=bw, down_bandwidth=bw, delay_ms=delay):
print measure(url.decode('utf-8'))
if __name__ == "__main__":
main()