Exemplo n.º 1
0
 def test_basic(self):
     with open(os.path.join(os.path.dirname(__file__), "data/multithread.json")) as f:
         sample_data = json.loads(f.read())
     fg = FlameGraph(sample_data)
     trees = fg.parse(sample_data)
     for tree in trees.values():
         self.assertEqual(depth(tree), 5)
     ofile = "result_flamegraph.html"
     fg.save(ofile)
     self.assertTrue(os.path.exists(ofile))
     os.remove(ofile)
Exemplo n.º 2
0
 def test_load(self):
     fg = FlameGraph()
     fg.load(
         os.path.join(os.path.dirname(__file__), "data/multithread.json"))
     for tree in fg.trees.values():
         self.assertGreater(depth(tree.root), 1)
     ofile = "result_flamegraph.html"
     fg.save(ofile)
     self.assertTrue(os.path.exists(ofile))
     os.remove(ofile)
     ofile = "result_flamegraph.html"
     fg.save(ofile)
     self.assertTrue(os.path.exists(ofile))
     os.remove(ofile)
Exemplo n.º 3
0
    def test_dump_perfetto(self):
        with open(
                os.path.join(os.path.dirname(__file__),
                             "data/multithread.json")) as f:
            sample_data = json.loads(f.read())
        fg = FlameGraph(sample_data)
        data = fg.dump_to_perfetto()
        self.assertEqual(len(data), 5)
        for callsite_info in data:
            self.assertIn("name", callsite_info)
            self.assertIn("flamegraph", callsite_info)

        # Test if FlameGraph can handle empty tree
        sample_data["traceEvents"].append({
            "ph": "M",
            "pid": 1,
            "tid": 1,
            "name": "thread_name",
            "args": {
                "name": "MainThread"
            }
        })
        fg = FlameGraph(sample_data)
        self.assertEqual(len(fg.trees), 6)
        data = fg.dump_to_perfetto()
        self.assertEqual(len(data), 5)
Exemplo n.º 4
0
 def test_load(self):
     fg = FlameGraph()
     fg.load(
         os.path.join(os.path.dirname(__file__), "data/multithread.json"))
     ofile = "result_flamegraph.html"
     fg.save(ofile)
     self.assertTrue(os.path.exists(ofile))
     os.remove(ofile)