source: ReferenceDesigns/w3_802.11/python/examples/log/log_process_tx_stats.py

Last change on this file was 6320, checked in by chunter, 5 years ago

1.8.0 release wlan-exp

File size: 4.1 KB
Line 
1"""
2------------------------------------------------------------------------------
3Mango 802.11 Reference Design - Experiments Framework - Log File Tx Stats
4------------------------------------------------------------------------------
5License:   Copyright 2014-2019, Mango Communications. All rights reserved.
6           Distributed under the WARP license (http://warpproject.org/license)
7------------------------------------------------------------------------------
8This example will process the TX statistics for a given log file.
9
10Hardware Setup:
11    - None.  Parsing log data can be done completely off-line
12
13Required 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"""
19import os
20import sys
21
22import numpy as np
23import matplotlib.mlab as mlab
24
25import wlan_exp.util as wlan_exp_util
26
27import wlan_exp.log.util as log_util
28import wlan_exp.log.util_hdf as hdf_util
29import wlan_exp.log.util_sample_data as sample_data_util
30
31
32#-----------------------------------------------------------------------------
33# Process command line arguments
34#-----------------------------------------------------------------------------
35
36DEFAULT_LOGFILE = 'ap_two_node_two_flow_capture.hdf5'
37logfile_error   = False
38
39# Use log file given as command line argument, if present
40if(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
48else:
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
60if logfile_error:
61    print("ERROR: Logfile {0} not found".format(LOGFILE))
62    sys.exit()
63else:
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
72log_data      = hdf_util.hdf5_to_log_data(filename=LOGFILE)
73
74# Get the raw_log_index from the file
75raw_log_index = hdf_util.hdf5_to_log_index(filename=LOGFILE)
76
77# Extract just OFDM Tx events
78tx_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
82log_np = log_util.log_data_to_np_arrays(log_data, tx_log_index)
83log_tx = log_np['TX_HIGH']
84
85# Define the fields to group by
86group_fields = ('addr1',)
87
88# Define the aggregation functions
89stat_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
97tx_stats = mlab.rec_groupby(log_tx, group_fields, stat_calc)
98
99# Display the results
100print('\nTx Statistics for {0}:\n'.format(os.path.basename(LOGFILE)))
101
102print('{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
110for 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
119print('')
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()
Note: See TracBrowser for help on using the repository browser.