Created
May 27, 2019 03:50
-
-
Save CyrusF/94bc80cc9abd2baf703f45d94c9cf06c to your computer and use it in GitHub Desktop.
A function for cleaning the trace based on time series
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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