|
| 1 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +"""Request a selection of pages that are populat on www.m.o from your local |
| 6 | +runserver, so that django-silk can capture performance info on them. |
| 7 | +
|
| 8 | +Usage: |
| 9 | +
|
| 10 | + 1. In your .env set ENABLE_DJANGO_SILK=True |
| 11 | + 2. Start your runserver on port 8000 |
| 12 | + 3. python profiling/hit_popular_pages.py |
| 13 | + 3. View results at http://localhost:8000/silk/ |
| 14 | +
|
| 15 | +""" |
| 16 | + |
| 17 | +import sys |
| 18 | +import time |
| 19 | + |
| 20 | +import requests |
| 21 | + |
| 22 | +paths = [ |
| 23 | + "/en-US/firefox/126.0/whatsnew/", |
| 24 | + "/en-US/firefox/", |
| 25 | + "/en-US/firefox/windows/", |
| 26 | + "/en-US/firefox/new/?reason=manual-update", |
| 27 | + "/en-US/firefox/download/thanks/", |
| 28 | + "/en-US/firefox/new/?reason=outdated", |
| 29 | + "/en-US/firefox/features/", |
| 30 | + "/en-US/firefox/all/", |
| 31 | + "/en-US/firefox/welcome/18/", |
| 32 | + "/en-US/", |
| 33 | + "/en-US/firefox/installer-help/?channel=release&installer_lang=en-US", |
| 34 | + "/en-US/firefox/download/thanks/?s=direct", |
| 35 | + "/en-US/firefox/welcome/19/", |
| 36 | + "/en-US/firefox/enterprise/?reason=manual-update", |
| 37 | + "/en-US/products/vpn/", |
| 38 | + "/en-US/firefox/browsers/windows-64-bit/", |
| 39 | + "/en-US/firefox/mac/", |
| 40 | + "/en-US/about/", |
| 41 | + "/en-US/firefox/android/124.0/releasenotes/", |
| 42 | + "/en-US/firefox/browsers/mobile/get-app/", |
| 43 | + "/en-US/firefox/browsers/", |
| 44 | + "/en-US/firefox/nightly/firstrun/", |
| 45 | + "/en-US/firefox/developer/", |
| 46 | + "/en-US/account/", |
| 47 | + "/en-US/contribute/", |
| 48 | + "/en-US/firefox/browsers/mobile/android/", |
| 49 | + "/en-US/privacy/archive/firefox-fire-tv/2023-06/", |
| 50 | + "/en-US/firefox/121.0/system-requirements/", |
| 51 | + "/en-US/firefox/browsers/mobile/", |
| 52 | + "/en-US/firefox/releases/", |
| 53 | + "/en-US/MPL/", |
| 54 | + "/en-US/firefox/enterprise/", |
| 55 | + "/en-US/security/advisories/", |
| 56 | + "/en-US/firefox/browsers/what-is-a-browser/", |
| 57 | + "/en-US/firefox/channel/desktop/?reason=manual-update", |
| 58 | + "/en-US/firefox/pocket/", |
| 59 | + "/en-US/firefox/channel/desktop/", |
| 60 | + "/en-US/firefox/welcome/17b/", |
| 61 | + "/en-US/firefox/welcome/17c/", |
| 62 | + "/en-US/firefox/welcome/17a/", |
| 63 | + "/en-US/firefox/set-as-default/thanks/", |
| 64 | + "/en-US/careers/listings/", |
| 65 | + "/en-US/firefox/browsers/chromebook/", |
| 66 | + "/en-US/firefox/nothing-personal/", |
| 67 | + "/en-US/newsletter/existing/", |
| 68 | + "/en-US/about/legal/terms/firefox/", |
| 69 | + "/en-US/firefox/linux/", |
| 70 | + "/en-US/firefox/browsers/mobile/focus/", |
| 71 | + "/en-US/products/vpn/download/", |
| 72 | + "/en-US/about/manifesto/", |
| 73 | + "/en-US/stories/joy-of-color/", |
| 74 | + "/en-US/contact/", |
| 75 | + "/en-US/about/legal/defend-mozilla-trademarks/", |
| 76 | +] |
| 77 | + |
| 78 | + |
| 79 | +def _log(*args): |
| 80 | + sys.stdout.write("\n".join(args)) |
| 81 | + |
| 82 | + |
| 83 | +def hit_pages(paths, times=3): |
| 84 | + _base_url = "http://localhost:8000" |
| 85 | + |
| 86 | + for path in paths: |
| 87 | + for _ in range(times): |
| 88 | + time.sleep(0.5) |
| 89 | + url = f"{_base_url}{path}" |
| 90 | + requests.get(url) |
| 91 | + |
| 92 | + _log("All done") |
| 93 | + |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + hit_pages(paths) |
0 commit comments