Commit 7de5b270 authored by Marlene Böhmer's avatar Marlene Böhmer

log conversion script for xlap

parent 4d7c840e
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python3
import sys
import os
import pandas as pd
def load_log(logname):
log = pd.read_csv(logname, index_col=0)
log['timestamp'] = pd.to_datetime(log['timestamp'])
log['direction'] = log['direction'].str[10:]
log['data'] = log['data'].str[12:-2]
log['rel_time'] = (log['timestamp'] - log['timestamp'][0]).apply(to_sec)
return log
def to_sec(x):
return x.total_seconds()
def to_microsec(x):
return int(x.timestamp() * 1000000)
def inverse_direction(x):
if x == 'IN':
return 'OUT'
elif x == 'OUT':
return 'IN'
else:
raise Exception()
def rtt_pair_filter(log):
filtered_log = log[~((log['port'] == 15) & (log['channel'] == 3))]
# drop subsequent duplicate OUT, keep first
filtered_log = filtered_log[~((filtered_log['direction'] == 'OUT')
& (filtered_log['direction'].shift(1) == 'OUT')
& (filtered_log['port'].shift(1) == filtered_log['port'])
& (filtered_log['channel'].shift(1) == filtered_log['channel'])
& (filtered_log['data'].shift(1) == filtered_log['data'])
)]
# repeatedly drop IN not matching previous OUT, keep first matching
change = True
while change:
length = len(filtered_log)
filtered_log = filtered_log[~((filtered_log['direction'] == 'IN')
& (filtered_log['direction'].shift(1) == 'OUT')
& ((filtered_log['port'].shift(1) != filtered_log['port'])
| (filtered_log['channel'].shift(1) != filtered_log['channel'])
)
)]
change = len(filtered_log) != length
# drop subsequent IN, keep first
filtered_log = filtered_log[~((filtered_log['direction'] == 'IN')
& (filtered_log['direction'].shift(1) != 'OUT')
)]
# drop subsequent OUT, keep last
filtered_log = filtered_log[~((filtered_log['direction'] == 'OUT')
& (filtered_log['direction'].shift(-1) != 'IN')
)]
return filtered_log
# command line arguments should be the 3 logs in the following order: pc, pi prrt, pi uart
if len(sys.argv) == 5 and \
os.path.exists(os.path.abspath(sys.argv[1])) and \
os.path.exists(os.path.abspath(sys.argv[2])) and \
os.path.exists(os.path.abspath(sys.argv[3])) and \
os.path.isdir(os.path.abspath(sys.argv[4])):
log_pc = load_log(sys.argv[1])
log_pi_prrt = load_log(sys.argv[2])
log_pi_uart = load_log(sys.argv[3])
save_path = os.path.abspath(sys.argv[4])
else:
sys.exit('Give 3 logs as command line arguments (order: pc, pi prrt, pi uart) and a path to which the converted '
'logs should be written.')
key = ['direction', 'port', 'channel', 'data']
log_pc.set_index(key)
log_pi_prrt.set_index(key)
log_pi_uart.set_index(key)
log_pc = log_pc.drop_duplicates(subset=key, keep=False)
log_pc = rtt_pair_filter(log_pc)
log_pi_prrt['direction'] = log_pi_prrt['direction'].apply(inverse_direction)
log_pi_prrt = log_pi_prrt.drop_duplicates(subset=key, keep=False)
log_pi_prrt = rtt_pair_filter(log_pi_prrt)
log_pi_uart = log_pi_uart.drop_duplicates(subset=key, keep=False)
log_pi_uart = rtt_pair_filter(log_pi_uart)
pi_log = pd.merge(log_pi_prrt, log_pi_uart, on=key, how='inner', suffixes=('_prrt', '_uart'))
merged_log = pd.merge(log_pc, pi_log, on=key, how='inner')
log1 = merged_log[merged_log['direction'] == 'OUT'].reset_index(drop=True)
log2 = merged_log[merged_log['direction'] == 'IN'].reset_index(drop=True)
merged_log = log1.join(log2, lsuffix='_1', rsuffix='_2')
merged_log.index.name = 'SeqNo'
xlap_sender = pd.DataFrame()
xlap_sender['PrrtSendRequest_T'] = merged_log['timestamp_1'].apply(to_microsec)
xlap_sender['PrrtReceiveResponse_T'] = merged_log['timestamp_2'].apply(to_microsec)
xlap_sender['Kind'] = 0
xlap_receiver = pd.DataFrame()
xlap_receiver['PrrtReceiveRequest_T'] = merged_log['timestamp_prrt_1'].apply(to_microsec)
xlap_receiver['UartSendRequest_T'] = merged_log['timestamp_uart_1'].apply(to_microsec)
xlap_receiver['UartReceiveResponse_T'] = merged_log['timestamp_uart_2'].apply(to_microsec)
xlap_receiver['PrrtSendResponse_T'] = merged_log['timestamp_prrt_2'].apply(to_microsec)
xlap_receiver['Kind'] = 0
xlap_sender.to_csv(os.path.join(save_path, 'sender.csv'))
xlap_receiver.to_csv(os.path.join(save_path, 'receiver.csv'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment