diff options
author | SeongJae Park <sj38.park@gmail.com> | 2024-03-02 13:15:48 -0800 |
---|---|---|
committer | SeongJae Park <sj38.park@gmail.com> | 2024-03-02 13:15:48 -0800 |
commit | 1368dec93d53f9833d96989cc7e58efdc9834092 (patch) | |
tree | 945877bd4a61cf93bfe58e1a2826fdeca3e0fde4 | |
parent | 5547ff534663b408e301554b133ca74217269c03 (diff) | |
download | damo-1368dec93d53f9833d96989cc7e58efdc9834092.tar.gz |
_damon_records: Copy parse_sort_addr_ranges_input() from damo_show
The function would better to be placed on _damon_records, for users of
the modules including damo_report_{profile,times}. Copy the function as
the first step.
Signed-off-by: SeongJae Park <sj38.park@gmail.com>
-rw-r--r-- | _damon_records.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/_damon_records.py b/_damon_records.py index 8519a60a..5752c786 100644 --- a/_damon_records.py +++ b/_damon_records.py @@ -898,6 +898,23 @@ def get_records(tried_regions_of=None, record_file=None, access_pattern=None, filter_records_by_addr(records, request.address_ranges) return records, None +def parse_sort_addr_ranges_input(addr_ranges_input): + try: + ranges = [[_damo_fmt_str.text_to_bytes(start), + _damo_fmt_str.text_to_bytes(end)] + for start, end in addr_ranges_input] + except Exception as e: + return None, 'conversion to bytes failed (%s)' % e + + ranges.sort(key=lambda x: x[0]) + for idx, arange in enumerate(ranges): + start, end = arange + if start > end: + return None, 'start > end (%s)' % arange + if idx > 0 and ranges[idx - 1][1] > start: + return None, 'overlapping range' + return ranges, None + def set_access_pattern_argparser(parser): parser.add_argument('--sz_region', metavar=('<min>', '<max>'), nargs=2, default=['min', 'max'], |