How to use the pympler.summary.get_diff 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_tracker.py View on Github external
# now an indicator object should be listed
        o = self._get_indicator()
        sn = tmp_tracker.create_summary()
        self.assertEqual(self._contains_indicator(sn), 1)
        # with ignore_self enabled a second summary should not list the first
        # summary
        sn = tmp_tracker.create_summary()
        sn2 = tmp_tracker.create_summary()
        tmp = summary._sweep(summary.get_diff(sn, sn2))
        self.assertEqual(len(tmp), 0)
        # but with ignore_self turned off, there should be some difference
        tmp_tracker = tracker.SummaryTracker(ignore_self=False)
        sn = tmp_tracker.create_summary()
        tmp_tracker.new_obj = self._get_indicator()
        sn2 = tmp_tracker.create_summary()
        tmp = summary._sweep(summary.get_diff(sn, sn2))
        self.failIfEqual(len(tmp), 0)
github pympler / pympler / test / muppy / test_tracker.py View on Github external
ignore_self is enabled.

        """
        # at the beginning, there should not be an indicator object listed
        tmp_tracker = tracker.SummaryTracker()
        sn = tmp_tracker.create_summary()
        self.assertEqual(self._contains_indicator(sn), None)
        # now an indicator object should be listed
        o = self._get_indicator()
        sn = tmp_tracker.create_summary()
        self.assertEqual(self._contains_indicator(sn), 1)
        # with ignore_self enabled a second summary should not list the first
        # summary
        sn = tmp_tracker.create_summary()
        sn2 = tmp_tracker.create_summary()
        tmp = summary._sweep(summary.get_diff(sn, sn2))
        self.assertEqual(len(tmp), 0)
        # but with ignore_self turned off, there should be some difference
        tmp_tracker = tracker.SummaryTracker(ignore_self=False)
        sn = tmp_tracker.create_summary()
        tmp_tracker.new_obj = self._get_indicator()
        sn2 = tmp_tracker.create_summary()
        tmp = summary._sweep(summary.get_diff(sn, sn2))
        self.failIfEqual(len(tmp), 0)
github pympler / pympler / test / muppy / test_summary.py View on Github external
def test_print_diff(self):
        """Test summary can be printed."""
        try:
            self._stdout = sys.stdout
            stream = StringIO()
            sys.stdout = stream
            sum1 = summary.summarize(muppy.get_objects())
            sum2 = summary.summarize(muppy.get_objects())
            sumdiff = summary.get_diff(sum1, sum2)
            summary.print_(sumdiff)
            self.assertIn('str', stream.getvalue())
            self.assertNotIn("
github pympler / pympler / pympler / tracker.py View on Github external
def diff(self, summary1=None, summary2=None):
        """Compute diff between to summaries.

        If no summary is provided, the diff from the last to the current
        summary is used. If summary1 is provided the diff from summary1
        to the current summary is used. If summary1 and summary2 are
        provided, the diff between these two is used.

        """
        res = None
        if summary2 is None:
            self.s1 = self.create_summary()
            if summary1 is None:
                res = summary.get_diff(self.s0, self.s1)
            else:
                res = summary.get_diff(summary1, self.s1)
            self.s0 = self.s1
        else:
            if summary1 is not None:
                res = summary.get_diff(summary1, summary2)
            else:
                raise ValueError(
                    "You cannot provide summary2 without summary1.")
        return summary._sweep(res)
github facebookincubator / memory-analyzer / memory_analyzer / analysis_utils.py View on Github external
the first PID listed to the first PID in the file. Any unmatched or non-first
    PIDs will be ignored because we don't know what to compare them to.
    """
    try:
        prev_items = list(frontend_utils.get_pages(snapshot_file))
    except pickle.UnpicklingError as e:
        frontend_utils.echo_error(
            f"Error unpickling the data from {snapshot_file}: {e}"
        )
        return None

    differences = []
    for cur_item in cur_items:
        for prev_item in prev_items:
            if cur_item.pid == prev_item.pid:
                diff = summary.get_diff(cur_item.data, prev_item.data)
                differences.append(
                    RetrievedObjects(
                        pid=cur_item.pid,
                        title=f"Snapshot Differences for {cur_item.pid}",
                        data=diff,
                    )
                )
    if not differences:
        diff = summary.get_diff(cur_items[0].data, prev_items[0].data)
        differences.append(
            RetrievedObjects(pid=0, title=f"Snapshot Differences", data=diff)
        )
    return differences
github pympler / pympler / pympler / tracker.py View on Github external
def diff(self, summary1=None, summary2=None):
        """Compute diff between to summaries.

        If no summary is provided, the diff from the last to the current
        summary is used. If summary1 is provided the diff from summary1
        to the current summary is used. If summary1 and summary2 are
        provided, the diff between these two is used.

        """
        res = None
        if summary2 is None:
            self.s1 = self.create_summary()
            if summary1 is None:
                res = summary.get_diff(self.s0, self.s1)
            else:
                res = summary.get_diff(summary1, self.s1)
            self.s0 = self.s1
        else:
            if summary1 is not None:
                res = summary.get_diff(summary1, summary2)
            else:
                raise ValueError(
                    "You cannot provide summary2 without summary1.")
        return summary._sweep(res)
github pympler / pympler / pympler / muppy.py View on Github external
(s_before, s_after) = _get_summaries(function, *args)
        # ignore all objects used for the measurement
        ignore = []
        if s_before != s_after:
            ignore.append(s_before)
        for row in s_before:
            # ignore refs from summary and frame (loop)
            if len(gc.get_referrers(row)) == 2:
                ignore.append(row)
            for item in row:
                # ignore refs from summary and frame (loop)
                if len(gc.get_referrers(item)) == 2:
                    ignore.append(item)
        for o in ignore:
            s_after = summary._subtract(s_after, o)
        res = summary.get_diff(s_before, s_after)
        return summary._sweep(res)
github HenryHu / pybbs / rosters.py View on Github external
def handle_signal_abort(self, signum, frame):
        Log.warn("Someone want to kill me! But I'll not die now! Hahahaha!")
        s = summary.summarize(muppy.get_objects())
        Log.debug("Current memory usage:")
        summary.print_(s)
        diff = summary.get_diff(self.mem_sum, s)
        self.mem_sum = s
        Log.debug("New memory usage:")
        summary.print_(diff)
github pympler / pympler / pympler / tracker.py View on Github external
summary is used. If summary1 is provided the diff from summary1
        to the current summary is used. If summary1 and summary2 are
        provided, the diff between these two is used.

        """
        res = None
        if summary2 is None:
            self.s1 = self.create_summary()
            if summary1 is None:
                res = summary.get_diff(self.s0, self.s1)
            else:
                res = summary.get_diff(summary1, self.s1)
            self.s0 = self.s1
        else:
            if summary1 is not None:
                res = summary.get_diff(summary1, summary2)
            else:
                raise ValueError(
                    "You cannot provide summary2 without summary1.")
        return summary._sweep(res)