load access pattern plot data from C++ computation Args: datapath: the path to the access pattern data file n_obj: the number of objects to plot, because the sampled objects from traceAnalyzer may be more than n_obj, this further samples down the number of objects
(datapath: str, n_obj_to_plot: int)
| 36 | |
| 37 | |
| 38 | def _load_access_pattern_data(datapath: str, n_obj_to_plot: int) -> List[List[float]]: |
| 39 | """load access pattern plot data from C++ computation |
| 40 | Args: |
| 41 | datapath: the path to the access pattern data file |
| 42 | n_obj: the number of objects to plot, because the sampled objects from traceAnalyzer |
| 43 | may be more than n_obj, this further samples down the number of objects to plot |
| 44 | Returns: |
| 45 | a list of access time list, each access time list is a list of access time of one object |
| 46 | """ |
| 47 | |
| 48 | n_total_obj = _get_num_of_lines(datapath) - 2 |
| 49 | # skip the first 20% popular objects |
| 50 | # n_total_obj = int(n_total_obj * 0.8) |
| 51 | sample_ratio = max(1, n_total_obj // n_obj_to_plot) |
| 52 | logger.debug( |
| 53 | "access pattern: sample ratio {}//{} = {}".format( |
| 54 | n_total_obj, n_obj_to_plot, sample_ratio |
| 55 | ) |
| 56 | ) |
| 57 | |
| 58 | if n_total_obj / sample_ratio > 10000: |
| 59 | print( |
| 60 | "access pattern: too many objects to plot, " |
| 61 | "try to use --n_obj_to_plot to reduce the number of objects, a reasonable number is 500" |
| 62 | ) |
| 63 | |
| 64 | ifile = open(datapath) |
| 65 | data_line = ifile.readline() |
| 66 | desc_line = data_line + ifile.readline() |
| 67 | assert "# access pattern " in desc_line, ( |
| 68 | "the input file might not be accessPattern data file" + "data " + datapath |
| 69 | ) |
| 70 | access_time_list = [] |
| 71 | |
| 72 | n_line = 0 |
| 73 | for line in ifile: |
| 74 | n_line += 1 |
| 75 | if not line.strip(): |
| 76 | continue |
| 77 | elif n_line % sample_ratio == 0: |
| 78 | access_time_list.append([float(i) for i in line.split(",")[:-1]]) |
| 79 | |
| 80 | ifile.close() |
| 81 | |
| 82 | access_time_list.sort(key=lambda x: x[0]) |
| 83 | |
| 84 | return access_time_list |
| 85 | |
| 86 | |
| 87 | def plot_access_pattern( |
no test coverage detected