This repository was archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze.py
More file actions
executable file
·56 lines (47 loc) · 1.43 KB
/
analyze.py
File metadata and controls
executable file
·56 lines (47 loc) · 1.43 KB
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
#!/usr/bin/env python3
import sys, json
import numpy as np
from pyshark import FileCapture
from pathlib import Path
from dist_analysis import Aggregate, Analyze
from dist_analysis import defaultAppendFn
##
try:
with open('.traces') as f:
ROOT_FOLDER = Path( f.readlines()[0] ).expanduser()
except:
ROOT_FOLDER = Path('traces')
##
with open(ROOT_FOLDER/'config.json') as f:
CONFIG = json.load(f)
##
if len(sys.argv)>1:
FILE=sys.argv[1]
else:
_keys = list(CONFIG.keys())
for i,x in enumerate(_keys):
print(f'[{i}] {x}')
_num = int( input('Choice by index: ') )
FILE = _keys[_num]
##
p = CONFIG[FILE]
_file = (ROOT_FOLDER / FILE).as_posix()
cap = FileCapture(_file, display_filter=p['filter'])
results = Aggregate(cap, limit=p['limit']*1E-3,
appendFn=defaultAppendFn,
filterFn=None)
##
_timestamp, _length = zip(*results)
time_delta = np.diff( _timestamp )
_length = np.array(_length[1:])
##
export_filename = (ROOT_FOLDER/FILE).with_suffix('.npy')
_delta_nano = np.array(time_delta) * 1E9
export = np.stack([_delta_nano, _length]).T.astype(np.uint64)
np.save(export_filename, export)
##
if 'interval_percent' in p:
_cutoff = p['interval_cutoff'] if 'interval_cutoff' in p else 1E9
Analyze(time_delta, percent=p['interval_percent'], cutoff=_cutoff, xlabel='Video Frame Interval (Second)')
if 'length_percent' in p:
Analyze(_length, percent=70, xlabel='Video Frame Length (Byte)')