-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_ebpf_lat.py
75 lines (56 loc) · 2.17 KB
/
plot_ebpf_lat.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def create_scatter_plot(latency_us):
fig_scatter = plt.figure(figsize=(12, 6))
ax = fig_scatter.add_subplot(111)
ax.scatter(range(len(latency_us)), latency_us, alpha=0.5, s=20)
ax.set_title('Latency Over Time', fontsize=20)
ax.set_xlabel('Sample Number', fontsize=18)
ax.set_ylabel('Latency (μs)', fontsize=18)
ax.grid(True, alpha=0.3)
plt.tight_layout()
return fig_scatter
def create_histogram(latency_us):
fig_hist = plt.figure(figsize=(12, 6))
ax = fig_hist.add_subplot(111)
ax.hist(latency_us, bins=50, color='blue', alpha=0.6)
ax.set_title('Latency Distribution (Log Scale)', fontsize=20)
ax.set_xlabel('Latency (μs)', fontsize=18)
ax.set_ylabel('Frequency (log scale)', fontsize=18)
ax.set_yscale('log')
ax.grid(True, alpha=0.3)
# Add statistics annotations to histogram
stats_text = (
f'Mean: {latency_us.mean():.2f} μs\n'
f'Median: {latency_us.median():.2f} μs\n'
f'95th percentile: {latency_us.quantile(0.95):.2f} μs\n'
f'99th percentile: {latency_us.quantile(0.99):.2f} μs\n'
f'Max: {latency_us.max():.2f} μs'
)
ax.text(0.95, 0.95, stats_text,
transform=ax.transAxes,
verticalalignment='top',
horizontalalignment='right',
bbox=dict(boxstyle='round', facecolor='white', alpha=0.8),
fontsize=18)
plt.tight_layout()
return fig_hist
def plot_latency(csv_path):
# Read the CSV file
df = pd.read_csv(csv_path)
# Convert milliseconds to microseconds
latency_us = df['latency'] * 1000
# Create separate plots
scatter_fig = create_scatter_plot(latency_us)
hist_fig = create_histogram(latency_us)
# Save plots separately
scatter_fig.savefig('figures/eBPF/latency_scatter.png', dpi=300, bbox_inches='tight')
hist_fig.savefig('figures/eBPF/latency_histogram.png', dpi=300, bbox_inches='tight')
plt.close('all')
return scatter_fig, hist_fig
if __name__ == "__main__":
csv_file = "data/ebpf_latency.csv"
scatter_fig, hist_fig = plot_latency(csv_file)
# Display plots
plt.show()