Exemplo n.º 1
0
    def test_FIFO_csv(self):
        reader = CsvReader("{}/trace.csv".format(DAT_FOLDER),
                           init_params={"header":True, 'label':5, 'delimiter':','})
        p1 = CGeneralProfiler(reader, "FIFO", cache_size=2000, bin_size=200, num_of_threads=os.cpu_count())
        p2 = PyGeneralProfiler(reader, 'FIFO', cache_size=2000, bin_size=200, num_of_threads=os.cpu_count())

        hc1 = p1.get_hit_count()
        hc2 = p2.get_hit_count()
        self.assertEqual(hc1[0], 0)
        self.assertEqual(hc1[8], 187)
        self.assertListEqual(list(hc1), list(hc2))

        hr1 = p1.get_hit_ratio()
        hr2 = p2.get_hit_ratio()
        self.assertAlmostEqual(hr1[0], 0.0)
        self.assertAlmostEqual(hr2[0], 0.0)
        self.assertAlmostEqual(hr1[2], hr2[2])
        self.assertAlmostEqual(hr1[2], 0.148702055216)

        # get hit count again to make sure the value won't change
        hc = p1.get_hit_count()
        self.assertEqual(hc[0], 0)
        self.assertEqual(hc[8], 187)

        p1.plotHRC(figname="test_c_c.png", cache_unit_size=32*1024)
        p2.plotHRC(figname="test_c_py.png", cache_unit_size=32*1024)
        reader.close()
Exemplo n.º 2
0
    def test_FIFO_bin(self):
        reader = BinaryReader("{}/trace.vscsi".format(DAT_FOLDER),
                              init_params={"label":6, "real_time":7, "fmt": "<3I2H2Q"})

        p1 = CGeneralProfiler(reader, "FIFO", cache_size=2000, bin_size=200, num_of_threads=os.cpu_count())
        p2 = PyGeneralProfiler(reader, 'FIFO', cache_size=2000, bin_size=200, num_of_threads=os.cpu_count())

        hc1 = p1.get_hit_count()
        hc2 = p2.get_hit_count()

        self.assertEqual(hc1[0], 0)
        self.assertEqual(hc1[8], 187)
        self.assertListEqual(list(hc1), list(hc2))

        hr1 = p1.get_hit_ratio()
        hr2 = p2.get_hit_ratio()
        self.assertAlmostEqual(hr1[0], 0.0)
        self.assertAlmostEqual(hr2[0], 0.0)
        self.assertAlmostEqual(hr1[2], hr2[2])
        self.assertAlmostEqual(hr1[2], 0.148702055216)

        # get hit count again to make sure the value won't change
        hc = p1.get_hit_count()
        self.assertEqual(hc[0], 0)
        self.assertEqual(hc[8], 187)

        p1.plotHRC(figname="test_b_c.png", cache_unit_size=32*1024)
        p2.plotHRC(figname="test_b_py.png", cache_unit_size=32*1024)
        reader.close()
Exemplo n.º 3
0
    def test_FIFO_bin(self):
        reader = BinaryReader("{}/trace.vscsi".format(DAT_FOLDER),
                              init_params={
                                  "label": 6,
                                  "real_time": 7,
                                  "fmt": "<3I2H2Q"
                              })

        p1 = CGeneralProfiler(reader,
                              "FIFO",
                              cache_size=2000,
                              bin_size=200,
                              num_of_threads=os.cpu_count())
        p2 = PyGeneralProfiler(reader,
                               'FIFO',
                               cache_size=2000,
                               bin_size=200,
                               num_of_threads=os.cpu_count())

        hc1 = p1.get_hit_count()
        hc2 = p2.get_hit_count()

        self.assertEqual(hc1[0], 0)
        self.assertEqual(hc1[8], 187)
        self.assertListEqual(list(hc1), list(hc2))

        hr1 = p1.get_hit_ratio()
        hr2 = p2.get_hit_ratio()
        self.assertAlmostEqual(hr1[0], 0.0)
        self.assertAlmostEqual(hr2[0], 0.0)
        self.assertAlmostEqual(hr1[2], hr2[2])
        self.assertAlmostEqual(hr1[2], 0.148702055216)

        # get hit count again to make sure the value won't change
        hc = p1.get_hit_count()
        self.assertEqual(hc[0], 0)
        self.assertEqual(hc[8], 187)

        p1.plotHRC(figname="test_b_c.png", cache_unit_size=32 * 1024)
        p2.plotHRC(figname="test_b_py.png", cache_unit_size=32 * 1024)
        reader.close()
Exemplo n.º 4
0
    def test_FIFO_csv(self):
        reader = CsvReader("{}/trace.csv".format(DAT_FOLDER),
                           init_params={
                               "header": True,
                               'label': 5,
                               'delimiter': ','
                           })
        p1 = CGeneralProfiler(reader,
                              "FIFO",
                              cache_size=2000,
                              bin_size=200,
                              num_of_threads=os.cpu_count())
        p2 = PyGeneralProfiler(reader,
                               'FIFO',
                               cache_size=2000,
                               bin_size=200,
                               num_of_threads=os.cpu_count())

        hc1 = p1.get_hit_count()
        hc2 = p2.get_hit_count()
        self.assertEqual(hc1[0], 0)
        self.assertEqual(hc1[8], 187)
        self.assertListEqual(list(hc1), list(hc2))

        hr1 = p1.get_hit_ratio()
        hr2 = p2.get_hit_ratio()
        self.assertAlmostEqual(hr1[0], 0.0)
        self.assertAlmostEqual(hr2[0], 0.0)
        self.assertAlmostEqual(hr1[2], hr2[2])
        self.assertAlmostEqual(hr1[2], 0.148702055216)

        # get hit count again to make sure the value won't change
        hc = p1.get_hit_count()
        self.assertEqual(hc[0], 0)
        self.assertEqual(hc[8], 187)

        p1.plotHRC(figname="test_c_c.png", cache_unit_size=32 * 1024)
        p2.plotHRC(figname="test_c_py.png", cache_unit_size=32 * 1024)
        reader.close()
    def test_cGeneralProfiler(self):
        reader = BinaryReader("{}/trace.vscsi".format(DAT_FOLDER),
                              init_params={"label":6, "real_time":7, "fmt": "<3I2H2Q"})

        p1 = CGeneralProfiler(reader, "FIFO", cache_size=2000, bin_size=200, num_of_threads=os.cpu_count())
        ea = p1.get_eviction_age()
Exemplo n.º 6
0
    def profiler(self,
                 algorithm,
                 cache_params=None,
                 cache_size=-1,
                 bin_size=-1,
                 use_general_profiler=False,
                 **kwargs):
        """
        get a profiler instance, this should not be used by most users

        :param algorithm:  name of algorithm
        :param cache_params: parameters of given cache replacement algorithm
        :param cache_size: size of cache
        :param bin_size: bin_size for generalProfiler
        :param use_general_profiler: this option is for LRU only, if it is True,
                                        then return a cGeneralProfiler for LRU,
                                        otherwise, return a LRUProfiler for LRU.

                                        Note: LRUProfiler does not require cache_size/bin_size params,
                                        it does not sample thus provides a smooth curve, however, it is O(logN) at each step,
                                        in constrast, cGeneralProfiler samples the curve, but use O(1) at each step
        :param kwargs: num_of_threads
        :return: a profiler instance
        """

        num_of_threads = kwargs.get("num_of_threads", DEF_NUM_THREADS)
        assert self.reader is not None, "you haven't opened a trace yet"

        if algorithm.lower() == "lru" and not use_general_profiler:
            profiler = LRUProfiler(self.reader, cache_size, cache_params)
        else:
            assert cache_size != -1, "you didn't provide size for cache"
            assert cache_size <= self.num_of_req(), "you cannot specify cache size({}) " \
                                                        "larger than trace length({})".format(cache_size,
                                                                                              self.num_of_req())
            if isinstance(algorithm, str):
                if algorithm.lower() in C_AVAIL_CACHE:
                    profiler = CGeneralProfiler(
                        self.reader,
                        CACHE_NAME_CONVRETER[algorithm.lower()],
                        cache_size,
                        bin_size,
                        cache_params=cache_params,
                        num_of_threads=num_of_threads)
                else:
                    profiler = PyGeneralProfiler(
                        self.reader,
                        self.cacheclass_mapping[algorithm.lower()],
                        cache_size,
                        bin_size,
                        cache_params=cache_params,
                        num_of_threads=num_of_threads)
            else:
                profiler = PyGeneralProfiler(self.reader,
                                             algorithm,
                                             cache_size,
                                             bin_size,
                                             cache_params=cache_params,
                                             num_of_threads=num_of_threads)

        return profiler