예제 #1
0
    def get_hit_ratio(self, **kwargs):
        """

        :param kwargs:
        :return: a numpy array of CACHE_SIZE+3, 0~CACHE_SIZE corresponds to hit rate of size 0~CACHE_SIZE,
         size 0 should always be 0, CACHE_SIZE+1 is out of range, CACHE_SIZE+2 is cold miss,
         so total is CACHE_SIZE+3 buckets
        """
        kargs = {"cache_size": kwargs.get("cache_size", self.cache_size)}

        # deprecated
        if 'begin' in kwargs:
            kargs['begin'] = kwargs['begin']
        if 'end' in kwargs:
            kargs['end'] = kwargs['end']

        if self.block_unit_size != 0:
            hit_ratio = c_LRUProfiler.get_hit_ratio_with_size(
                self.reader.c_reader,
                block_unit_size=self.block_unit_size,
                **kargs)
        else:
            hit_ratio = c_LRUProfiler.get_hit_ratio_seq(
                self.reader.c_reader, **kargs)
        return hit_ratio
예제 #2
0
 def save_reuse_dist(self, file_loc, rd_type):
     """
     save reuse distance to file_loc
     allowed reuse distance including normal reuse distance (rd),
     future/forward reuse distance (frd)
     :param file_loc:
     :param rd_type:
     :return:
     """
     assert rd_type == 'rd' or rd_type == 'frd', \
         "please provide a valid reuse distance type, currently support rd and frd"
     c_LRUProfiler.save_reuse_dist(self.reader.c_reader, file_loc, rd_type)
예제 #3
0
 def save_reuse_dist(self, file_loc, rd_type):
     """
     save reuse distance to file_loc
     allowed reuse distance including normal reuse distance (rd),
     future/forward reuse distance (frd)
     :param file_loc:
     :param rd_type:
     :return:
     """
     assert rd_type == 'rd' or rd_type == 'frd', \
         "please provide a valid reuse distance type, currently support rd and frd"
     c_LRUProfiler.save_reuse_dist(self.reader.c_reader, file_loc, rd_type)
예제 #4
0
    def load_reuse_dist(self, file_loc, rd_type):
        """
        load reuse distance from file_loc
        allowed reuse distance including normal reuse distance (rd),
        future/forward reuse distance (frd)

        :param file_loc:
        :param rd_type:
        :return:
        """
        assert rd_type == 'rd' or rd_type == 'frd', \
            "please provide a valid reuse distance type, currently support rd and frd"
        if not os.path.exists(file_loc):
            WARNING("pre-computed reuse distance file does not exist")
        c_LRUProfiler.load_reuse_dist(self.reader.c_reader, file_loc, rd_type)
        self.reader.already_load_rd = True
예제 #5
0
    def load_reuse_dist(self, file_loc, rd_type):
        """
        load reuse distance from file_loc
        allowed reuse distance including normal reuse distance (rd),
        future/forward reuse distance (frd)

        :param file_loc:
        :param rd_type:
        :return:
        """
        assert rd_type == 'rd' or rd_type == 'frd', \
            "please provide a valid reuse distance type, currently support rd and frd"
        if not os.path.exists(file_loc):
            WARNING("pre-computed reuse distance file does not exist")
        c_LRUProfiler.load_reuse_dist(self.reader.c_reader, file_loc, rd_type)
        self.reader.already_load_rd = True
예제 #6
0
    def get_hit_ratio_shards(self, sample_ratio=0.01, **kwargs):
        """
        experimental function
        :param sample_ratio:
        :param kwargs:
        :return:
        """
        # from PyMimircache.cacheReader.tracePreprocesser import TracePreprocessor
        # kargs = {}
        # if 'cache_size' not in kwargs:
        #     kargs['cache_size'] = self.cache_size
        # else:
        #     kargs['cache_size'] = kwargs['cache_size']

        # pp = TracePreprocessor(self.reader)
        # N1, N2, traceName, fmt = pp.prepare_for_shards(sample_ratio=sample_ratio, has_time=False)
        # correction = N2 - N1
        # print("correction: {}".format(correction))
        # # correction = 0
        # tempReader = BinaryReader(traceName, init_params={"label":1, "fmt": fmt})

        correction = 0
        kargs = {"cache_size": kwargs.get("cache_size", self.cache_size)}
        if self.block_unit_size != 0:
            print("not supported yet")
            return None
        else:
            hit_ratio = c_LRUProfiler.get_hit_ratio_seq_shards(self.reader.c_reader, sample_ratio=sample_ratio,
                                                       **kargs)
        return hit_ratio
예제 #7
0
    def get_hit_ratio_shards(self, sample_ratio=0.01, **kwargs):
        """
        experimental function
        :param sample_ratio:
        :param kwargs:
        :return:
        """
        # from PyMimircache.cacheReader.tracePreprocesser import TracePreprocessor
        # kargs = {}
        # if 'cache_size' not in kwargs:
        #     kargs['cache_size'] = self.cache_size
        # else:
        #     kargs['cache_size'] = kwargs['cache_size']

        # pp = TracePreprocessor(self.reader)
        # N1, N2, traceName, fmt = pp.prepare_for_shards(sample_ratio=sample_ratio, has_time=False)
        # correction = N2 - N1
        # print("correction: {}".format(correction))
        # # correction = 0
        # tempReader = BinaryReader(traceName, init_params={"label":1, "fmt": fmt})

        correction = 0
        kargs = {"cache_size": kwargs.get("cache_size", self.cache_size)}
        if self.block_unit_size != 0:
            print("not supported yet")
            return None
        else:
            hit_ratio = c_LRUProfiler.get_hit_ratio_seq_shards(
                self.reader.c_reader, sample_ratio=sample_ratio, **kargs)
        return hit_ratio
예제 #8
0
 def get_future_reuse_distance(self, **kargs):
     """
     get future reuse_distance as a numpy array
     :param kargs:
     :return:
     """
     if self.block_unit_size != 0:
         WARNING("future reuse distance calculation does not support variable obj size, "
             "calculating without considering size")
     frd = c_LRUProfiler.get_future_reuse_dist(self.reader.c_reader, **kargs)
     return frd
예제 #9
0
 def get_reuse_distance(self, **kargs):
     """
     get reuse distance as a numpy array
     :param kargs:
     :return:
     """
     if self.block_unit_size != 0:
         WARNING(
             "reuse distance calculation does not support variable obj size, "
             "calculating without considering size")
     rd = c_LRUProfiler.get_reuse_dist_seq(self.reader.c_reader, **kargs)
     return rd
예제 #10
0
    def get_hit_ratio(self, **kwargs):
        """

        :param kwargs:
        :return: a numpy array of CACHE_SIZE+3, 0~CACHE_SIZE corresponds to hit rate of size 0~CACHE_SIZE,
         size 0 should always be 0, CACHE_SIZE+1 is out of range, CACHE_SIZE+2 is cold miss,
         so total is CACHE_SIZE+3 buckets
        """
        kargs = {"cache_size": kwargs.get("cache_size", self.cache_size)}

        # deprecated
        if 'begin' in kwargs:
            kargs['begin'] = kwargs['begin']
        if 'end' in kwargs:
            kargs['end'] = kwargs['end']

        if self.block_unit_size != 0 :
            hit_ratio = c_LRUProfiler.get_hit_ratio_with_size(self.reader.c_reader,
                                                            block_unit_size=self.block_unit_size, **kargs)
        else:
            hit_ratio = c_LRUProfiler.get_hit_ratio_seq(self.reader.c_reader, **kargs)
        return hit_ratio
예제 #11
0
 def get_hit_count(self, **kargs):
     """
     0~size(included) are for counting rd=0~size, size+1 is
     out of range, size+2 is cold miss, so total is size+3 buckets
     :param kargs:
     :return:
     """
     if 'cache_size' not in kargs:
         kargs['cache_size'] = self.cache_size
     if self.block_unit_size != 0:
         WARNING("not supported yet")
         return None
     else:
         hit_count = c_LRUProfiler.get_hit_count_seq(self.reader.c_reader, **kargs)
     return hit_count
예제 #12
0
 def get_hit_count(self, **kargs):
     """
     0~size(included) are for counting rd=0~size, size+1 is
     out of range, size+2 is cold miss, so total is size+3 buckets
     :param kargs:
     :return:
     """
     if 'cache_size' not in kargs:
         kargs['cache_size'] = self.cache_size
     if self.block_unit_size != 0:
         WARNING("not supported yet")
         return None
     else:
         hit_count = c_LRUProfiler.get_hit_count_seq(
             self.reader.c_reader, **kargs)
     return hit_count
예제 #13
0
    def get_hit_ratio_phase_cont(self, **kwargs):
        """

        :param kwargs:
        :return: a numpy array of CACHE_SIZE+3, 0~CACHE_SIZE corresponds to hit rate of size 0~CACHE_SIZE,
         size 0 should always be 0, CACHE_SIZE+1 is out of range, CACHE_SIZE+2 is cold miss,
         so total is CACHE_SIZE+3 buckets for the given phase
        """

        kargs = {
            "current_phase": kwargs.get("current_phase"),
            "num_phases": kwargs.get("num_phases")
        }

        hit_ratio = c_LRUProfiler.get_hit_ratio_phase_cont(self.reader.c_reader, **kargs)
        return hit_ratio
예제 #14
0
    def get_hit_ratio_phase_cont(self, **kwargs):
        """

        :param kwargs:
        :return: a numpy array of CACHE_SIZE+3, 0~CACHE_SIZE corresponds to hit rate of size 0~CACHE_SIZE,
         size 0 should always be 0, CACHE_SIZE+1 is out of range, CACHE_SIZE+2 is cold miss,
         so total is CACHE_SIZE+3 buckets for the given phase
        """

        kargs = {
            "current_phase": kwargs.get("current_phase"),
            "num_phases": kwargs.get("num_phases")
        }

        hit_ratio = c_LRUProfiler.get_hit_ratio_phase_cont(
            self.reader.c_reader, **kargs)
        return hit_ratio
예제 #15
0
 def get_reversed_reuse_dist(self):
     return c_LRUProfiler.get_reversed_reuse_dist(self.reader.c_reader)