Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import csv
- import os
- import requests
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.chrome.service import Service
- from selenium.webdriver.chrome.options import Options
- from datetime import datetime
- import matplotlib.pyplot as plt
- from datetime import datetime
- class Measurement:
- def __init__(self, measure_time: float, latency: float, file_size: float, variant: str):
- self.measure_time = measure_time # The exact time the measurement was made in milliseconds
- self.latency = latency # The latency in seconds
- self.variant = variant # Variant string (v0, v1, v2, v3)
- self.file_size = file_size # File size in KB
- def __repr__(self):
- return (f"Measurement(measure_time={self.measure_time:.2f}, "
- f"latency={self.latency:.2f} seconds, file_size={self.file_size} KB, variant='{self.variant}')")
- def run():
- # Setup Chrome options.
- chrome_options = Options()
- chrome_options.add_argument("--use-gl=desktop")
- chrome_options.add_argument("--enable-gpu-rasterization")
- chrome_options.add_argument("--ignore-gpu-blocklist")
- chrome_options.add_argument("--enable-webgl")
- chrome_options.add_argument("--enable-webgl2")
- chrome_options.add_argument("--use-gl=angle")
- # Set up logging to capture console logs.
- chrome_options.set_capability("goog:loggingPrefs", {"browser": "ALL"})
- # Initialize the web driver.
- driver = webdriver.Chrome(options=chrome_options)
- request_timestamps = {}
- measurements = []
- # pageUrl = 'http://chimay.science.uva.nl:8092/player/24b85f65-6b67-4657-8316-4f914d1a467f/f6baba31-1901-42e6-9b7d-3eeea1e91a75'
- # pageUrl = 'http://34.90.61.78:8092/player/12ecbd47-169f-44b0-bf67-1d616dad19dc/06913a13-4c76-4c0b-97c2-f2e758738bfa'
- pageUrl = 'http://ec2-18-202-178-55.eu-west-1.compute.amazonaws.com:8092/player/28ad1095-7272-45de-9da4-0ed81942b599/5a658725-1037-4ffe-b1d8-a4aa2e6491ca'
- # pageUrl = 'http://20.82.114.202:8092/player/164007e1-20a0-4a12-9a3f-cfb6dfb9ed09/b211d327-e824-44a5-b886-b8b64c3aa17d'
- # Navigate to the page.
- driver.get(pageUrl)
- # Log in with access code.
- code_input = driver.find_element(By.ID, "Code")
- code_input.send_keys("sander")
- submit_button = driver.find_element(By.XPATH, '//button[text()="Submit"]')
- submit_button.click()
- # Wait for the network to be idle.
- driver.implicitly_wait(5)
- # Start experience.
- start_button = driver.find_element(By.XPATH, '//button[text()="Start"]')
- start_button.click()
- # Wait for the network to be idle.
- driver.implicitly_wait(5)
- # Keep listening for requests and responses for a longer period to capture HLS segment requests.
- time.sleep(5 * 60)
- job_id = os.getenv("SLURM_JOB_ID", "no_job_id")
- task_id = os.getenv("SLURM_PROCID", "no_task_id")
- node_id = os.getenv("SLURM_NODEID", "no_node_id")
- # Parse console logs captured by the browser.
- for entry in driver.get_log('browser'):
- message = entry['message']
- print(f"{task_id} - {entry['level']} - {entry['message']}")
- if '[hls]' in message and '.ts,' in message:
- _, url, endTime, latency, fileSize = message.split(',')
- variant = url[-8:-6]
- measurement = Measurement(int(endTime), float(latency), float(fileSize[:-3]), variant)
- measurements.append(measurement)
- variant_map = {'v0': 0, 'v1': 1, 'v2': 2, 'v3': 3}
- y_labels = ['v0', 'v1', 'v2', 'v3']
- x_values = [m.measure_time for m in measurements]
- y_values = [variant_map[m.variant] for m in measurements]
- z_values = [m.latency for m in measurements]
- a_values = [m.file_size for m in measurements]
- # Get SLURM job ID, process ID and task ID to make unique filenames.
- output_filename = f"measurement_data_{job_id}_{node_id}_{task_id}.csv"
- with open(output_filename, mode="w", newline="") as file:
- writer = csv.writer(file)
- # Write headers.
- writer.writerow(["Time", "Variant", "Latency", "File_size"])
- # Write each pair of x and y values to the CSV.
- for x, y, z, a in zip(x_values, y_values, z_values, a_values):
- writer.writerow([x, y, z, a])
- driver.quit()
- if __name__ == "__main__":
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement