Created
May 14, 2018 23:02
-
-
Save cfoch/716a446ee0c14d719fcc2d26fb8f635c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# cfoch-tesis results | |
# Copyright (c) 2018 Fabian Orccon <cfoch.fabian@gmail.com> | |
# | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 2.1 of the License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# Lesser General Public License for more details. | |
# | |
# You should have received a copy of the GNU Lesser General Public | |
# License along with this program; if not, write to the | |
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, | |
import argparse | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import os | |
DEFAULT_HEAD_REMOVE = 7 | |
LATENCY_PATTERN = "time=(guint64)" | |
LATENCY_PATTERN_LEN = len(LATENCY_PATTERN) | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-i", "--trace-file", | |
help="The path to the output of the trace log.", required=True) | |
parser.add_argument("-H", "--head-remove", | |
help="Ignore h last lines from the start of the trace file.", | |
default=DEFAULT_HEAD_REMOVE, required=False) | |
parser.add_argument("-d", "--display", | |
help="Sets whether to display or not a plot of the latency.", | |
action="store_true", required=False) | |
args = parser.parse_args() | |
def plot_latency_data(data): | |
plt.plot(data * 1e-9) | |
plt.title("Latencia por Buffer") | |
plt.ylabel("Latencia (segundos)") | |
plt.xlabel("Buffer") | |
plt.show() | |
def get_latency_from_log_string(log_str): | |
lines = log_str.split("\n") | |
lines = lines[args.head_remove:-1] | |
data = [] | |
for line in lines: | |
start = line.find(LATENCY_PATTERN) + LATENCY_PATTERN_LEN | |
subline = line[start:] | |
end = subline.find(",") | |
latency_str = subline[:end] | |
latency = int(latency_str) | |
data.append(latency) | |
return np.array(data) | |
with open(args.trace_file, "r") as f: | |
log_str = f.read() | |
latency_data = get_latency_from_log_string(log_str) | |
print("Latency average: ", np.average(latency_data)) | |
if args.display: | |
plot_latency_data(latency_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment