1 | """ |
---|
2 | ------------------------------------------------------------------------------ |
---|
3 | Mango 802.11 Reference Design - Experiments Framework - Log File Tx Stats |
---|
4 | ------------------------------------------------------------------------------ |
---|
5 | License: Copyright 2014-2019, Mango Communications. All rights reserved. |
---|
6 | Distributed under the WARP license (http://warpproject.org/license) |
---|
7 | ------------------------------------------------------------------------------ |
---|
8 | This example will process the TX statistics for a given log file. |
---|
9 | |
---|
10 | Hardware Setup: |
---|
11 | - None. Parsing log data can be done completely off-line |
---|
12 | |
---|
13 | Required Script Changes: |
---|
14 | - Set LOGFILE to the file name of your WLAN Exp log HDF5 file (or pass in |
---|
15 | via command line argument) |
---|
16 | |
---|
17 | ------------------------------------------------------------------------------ |
---|
18 | """ |
---|
19 | import os |
---|
20 | import sys |
---|
21 | |
---|
22 | import numpy as np |
---|
23 | import matplotlib.mlab as mlab |
---|
24 | |
---|
25 | import wlan_exp.util as wlan_exp_util |
---|
26 | |
---|
27 | import wlan_exp.log.util as log_util |
---|
28 | import wlan_exp.log.util_hdf as hdf_util |
---|
29 | import wlan_exp.log.util_sample_data as sample_data_util |
---|
30 | |
---|
31 | |
---|
32 | #----------------------------------------------------------------------------- |
---|
33 | # Process command line arguments |
---|
34 | #----------------------------------------------------------------------------- |
---|
35 | |
---|
36 | DEFAULT_LOGFILE = 'ap_two_node_two_flow_capture.hdf5' |
---|
37 | logfile_error = False |
---|
38 | |
---|
39 | # Use log file given as command line argument, if present |
---|
40 | if(len(sys.argv) != 1): |
---|
41 | LOGFILE = str(sys.argv[1]) |
---|
42 | |
---|
43 | # Check if the string argument matchs a local file |
---|
44 | if not os.path.isfile(LOGFILE): |
---|
45 | # User specified non-existant file - give up and exit |
---|
46 | logfile_error = True |
---|
47 | |
---|
48 | else: |
---|
49 | # No command line argument - check if default file name exists locally |
---|
50 | LOGFILE = DEFAULT_LOGFILE |
---|
51 | |
---|
52 | if not os.path.isfile(LOGFILE): |
---|
53 | # No local file specified or found - check for matching sample data file |
---|
54 | try: |
---|
55 | LOGFILE = sample_data_util.get_sample_data_file(DEFAULT_LOGFILE) |
---|
56 | print("Local log file not found - Using sample data file!") |
---|
57 | except IOError as e: |
---|
58 | logfile_error = True |
---|
59 | |
---|
60 | if logfile_error: |
---|
61 | print("ERROR: Logfile {0} not found".format(LOGFILE)) |
---|
62 | sys.exit() |
---|
63 | else: |
---|
64 | print("Reading log file '{0}' ({1:5.1f} MB)\n".format(LOGFILE, (os.path.getsize(LOGFILE)/2**20))) |
---|
65 | |
---|
66 | |
---|
67 | #----------------------------------------------------------------------------- |
---|
68 | # Main script |
---|
69 | #----------------------------------------------------------------------------- |
---|
70 | |
---|
71 | # Get the log_data from the file |
---|
72 | log_data = hdf_util.hdf5_to_log_data(filename=LOGFILE) |
---|
73 | |
---|
74 | # Get the raw_log_index from the file |
---|
75 | raw_log_index = hdf_util.hdf5_to_log_index(filename=LOGFILE) |
---|
76 | |
---|
77 | # Extract just OFDM Tx events |
---|
78 | tx_log_index = log_util.filter_log_index(raw_log_index, include_only=['TX_HIGH'], |
---|
79 | merge={'TX_HIGH' : ['TX_HIGH', 'TX_HIGH_LTG']}) |
---|
80 | |
---|
81 | # Generate numpy array |
---|
82 | log_np = log_util.log_data_to_np_arrays(log_data, tx_log_index) |
---|
83 | log_tx = log_np['TX_HIGH'] |
---|
84 | |
---|
85 | # Define the fields to group by |
---|
86 | group_fields = ('addr1',) |
---|
87 | |
---|
88 | # Define the aggregation functions |
---|
89 | stat_calc = ( |
---|
90 | ('num_tx', np.mean, 'avg_num_tx'), |
---|
91 | ('length', len, 'num_pkts'), |
---|
92 | ('length', np.mean, 'avg_len'), |
---|
93 | ('length', sum, 'tot_len'), |
---|
94 | ('time_to_done', np.mean, 'avg_time')) |
---|
95 | |
---|
96 | # Calculate the aggregate statistics |
---|
97 | tx_stats = mlab.rec_groupby(log_tx, group_fields, stat_calc) |
---|
98 | |
---|
99 | # Display the results |
---|
100 | print('\nTx Statistics for {0}:\n'.format(os.path.basename(LOGFILE))) |
---|
101 | |
---|
102 | print('{0:^18} | {1:^9} | {2:^10} | {3:^14} | {4:^16} | {5:^5}'.format( |
---|
103 | 'Dest Addr', |
---|
104 | 'Num MPDUs', |
---|
105 | 'Avg Length', |
---|
106 | 'Total Tx Bytes', |
---|
107 | 'Avg Time to Done', |
---|
108 | 'Avg Num Tx')) |
---|
109 | |
---|
110 | for ii in range(len(tx_stats)): |
---|
111 | print('{0:<18} | {1:9d} | {2:10.1f} | {3:14} | {4:16.3f} | {5:5.2f}'.format( |
---|
112 | wlan_exp_util.mac_addr_to_str(tx_stats['addr1'][ii]), |
---|
113 | tx_stats['num_pkts'][ii], |
---|
114 | tx_stats['avg_len'][ii], |
---|
115 | tx_stats['tot_len'][ii], |
---|
116 | tx_stats['avg_time'][ii], |
---|
117 | tx_stats['avg_num_tx'][ii])) |
---|
118 | |
---|
119 | print('') |
---|
120 | |
---|
121 | # Uncomment this line to open an interactive console after the script runs |
---|
122 | # This console will have access to all variables defined above |
---|
123 | # wlan_exp_util.debug_here() |
---|