Skip to content

Instantly share code, notes, and snippets.

@CyrusF
Created May 27, 2019 03:50
Show Gist options
  • Select an option

  • Save CyrusF/94bc80cc9abd2baf703f45d94c9cf06c to your computer and use it in GitHub Desktop.

Select an option

Save CyrusF/94bc80cc9abd2baf703f45d94c9cf06c to your computer and use it in GitHub Desktop.
A function for cleaning the trace based on time series
def cleaner(syscall_list, max_block_size, times):
def _clean_once(syscall_list, max_block_size):
def _block_cmp(syscall_list, j, i):
if j + 2 * i - 1 >= len(syscall_list):
return False
for k in range(i):
if syscall_list[j+k] != syscall_list[j+i+k]:
return False
return True
for i in range(min(max_block_size, len(syscall_list) // 2), 0, -1):
j = 0
while j <= len(syscall_list) - i * 2:
if _block_cmp(syscall_list, j, i):
syscall_list = syscall_list[:j]+syscall_list[j+i:]
print(syscall_list)
else:
j += 1
return syscall_list
for i in range(times):
print("=====")
syscall_list = _clean_once(syscall_list, max_block_size)
return syscall_list
cleaner([1,2,3,2,3,4,2,3,2,3,2,3,4,4], 5, 3)
# Output:
# =====
# [1, 2, 3, 4, 2, 3, 2, 3, 2, 3, 4, 4]
# [1, 2, 3, 4, 2, 3, 2, 3, 4, 4]
# [1, 2, 3, 4, 2, 3, 4, 4]
# [1, 2, 3, 4, 2, 3, 4]
# =====
# [1, 2, 3, 4]
# =====
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment