How to use the pympler.summary._subtract function in Pympler

To help you get started, we’ve selected a few Pympler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pympler / pympler / test / muppy / test_summary.py View on Github external
self.assert_(row[2] == totalsize, totalsize)
                checked_str = True
            if row[0] == summary._repr({}):
                self.assert_(row[1] == 0)
                self.assert_(row[2] == 0)
                checked_dict = True
            if row[0] == summary._repr((1,)):
                self.assert_(row[1] == -1)
                self.assert_(row[2] == -getsizeof((1,)))
                checked_tuple = True

        self.assert_(checked_str, "no str found in summary")
        self.assert_(checked_dict, "no dict found in summary")
        self.assert_(checked_tuple, "no tuple found in summary")

        summary._subtract(summ, 'quick')
        summary._subtract(summ, 'brown')
        checked_str = False
        for row in summ:
            if row[0] == summary._repr(''):
                self.assert_(row[1] == 1)
                self.assert_(row[2] == getsizeof('fox'))
                checked_str = True
        self.assert_(checked_str, "no str found in summ")
github pympler / pympler / test / muppy / test_summary.py View on Github external
def test_subtract(self):
        """Test that a single object's data is correctly subtracted from a summary.
        - result in correct total size and total number of objects
        - if object was not listed before, it should be listed negative
          afterwards
        """

        objects = ['the', 'quick', 'brown', 'fox', 1298, 123, 234, [], {}]
        summ = summary.summarize(objects)
        summary._subtract(summ, 'the')
        summary._subtract(summ, {})
        summary._subtract(summ, (1,))
        # to verify that these rows where actually included afterwards
        checked_str = checked_dict = checked_tuple = False
        for row in summ:
            if row[0] == summary._repr(''):
                totalsize = getsizeof('quick') + getsizeof('brown') +\
                            getsizeof('fox')
                self.assert_(row[1] == 3, "%s != %s" % (row[1], 3))
                self.assert_(row[2] == totalsize, totalsize)
                checked_str = True
            if row[0] == summary._repr({}):
                self.assert_(row[1] == 0)
                self.assert_(row[2] == 0)
                checked_dict = True
            if row[0] == summary._repr((1,)):
github pympler / pympler / test / muppy / test_summary.py View on Github external
checked_str = True
            if row[0] == summary._repr({}):
                self.assert_(row[1] == 0)
                self.assert_(row[2] == 0)
                checked_dict = True
            if row[0] == summary._repr((1,)):
                self.assert_(row[1] == -1)
                self.assert_(row[2] == -getsizeof((1,)))
                checked_tuple = True

        self.assert_(checked_str, "no str found in summary")
        self.assert_(checked_dict, "no dict found in summary")
        self.assert_(checked_tuple, "no tuple found in summary")

        summary._subtract(summ, 'quick')
        summary._subtract(summ, 'brown')
        checked_str = False
        for row in summ:
            if row[0] == summary._repr(''):
                self.assert_(row[1] == 1)
                self.assert_(row[2] == getsizeof('fox'))
                checked_str = True
        self.assert_(checked_str, "no str found in summ")
github pympler / pympler / test / muppy / test_summary.py View on Github external
summary._subtract(summ, {})
        summary._subtract(summ, [])
        summ = summary._sweep(summ)
        found_dict = found_tuple = False
        for row in summ:
            if row[0] == "":
                found_dict = True
            if row[0] == "":
                found_tuple = True
        self.assert_(found_dict == False)
        self.assert_(found_tuple == False)
        # do not remove row if one of the sizes is not empty
        # e.g. if the number of objects of a type did not change, but the
        # total size did
        summ = summary._subtract(summ, 'the')
        summ = summary._subtract(summ, 'quick')
        summ = summary._subtract(summ, 'brown')
        summ = summary._subtract(summ, '42')
        summ = summary._sweep(summ)
        found_string = False
        for row in summ:
            if row[0] == summary._repr(''):
                found_string = True
                self.assert_(row[1] == 0)
                totalsize = getsizeof('fox') - getsizeof('42')
                self.assert_(row[2] == totalsize)
        self.assert_(found_string == True)
github pympler / pympler / test / muppy / test_summary.py View on Github external
summ = summary._sweep(summ)
        found_dict = found_tuple = False
        for row in summ:
            if row[0] == "":
                found_dict = True
            if row[0] == "":
                found_tuple = True
        self.assert_(found_dict == False)
        self.assert_(found_tuple == False)
        # do not remove row if one of the sizes is not empty
        # e.g. if the number of objects of a type did not change, but the
        # total size did
        summ = summary._subtract(summ, 'the')
        summ = summary._subtract(summ, 'quick')
        summ = summary._subtract(summ, 'brown')
        summ = summary._subtract(summ, '42')
        summ = summary._sweep(summ)
        found_string = False
        for row in summ:
            if row[0] == summary._repr(''):
                found_string = True
                self.assert_(row[1] == 0)
                totalsize = getsizeof('fox') - getsizeof('42')
                self.assert_(row[2] == totalsize)
        self.assert_(found_string == True)
github pympler / pympler / pympler / tracker.py View on Github external
for k, v in self.summaries.items():
                store_info(k)
                summary._traverse(v, store_info)

            # do the summary
            res = summary.summarize(muppy.get_objects())

            # remove ids stored in the ref_counter
            for _id in ref_counter:
                # referenced in frame, ref_counter, ref_counter.keys()
                if len(gc.get_referrers(_id)) == (3):
                    summary._subtract(res, _id)
            for o in all_of_them:
                # referenced in frame, summary, all_of_them
                if len(gc.get_referrers(o)) == (ref_counter[id(o)] + 2):
                    summary._subtract(res, o)

        return res
github pympler / pympler / pympler / tracker.py View on Github external
ref_counter[id(o)] = 1

            # store infos on every single object related to the summaries
            store_info(self.summaries)
            for k, v in self.summaries.items():
                store_info(k)
                summary._traverse(v, store_info)

            # do the summary
            res = summary.summarize(muppy.get_objects())

            # remove ids stored in the ref_counter
            for _id in ref_counter:
                # referenced in frame, ref_counter, ref_counter.keys()
                if len(gc.get_referrers(_id)) == (3):
                    summary._subtract(res, _id)
            for o in all_of_them:
                # referenced in frame, summary, all_of_them
                if len(gc.get_referrers(o)) == (ref_counter[id(o)] + 2):
                    summary._subtract(res, o)

        return res