1"""
2Test lldb data formatter subsystem.
3"""
4
5from __future__ import print_function
6
7
8import lldb
9from lldbsuite.test.lldbbench import *
10from lldbsuite.test.decorators import *
11from lldbsuite.test.lldbtest import *
12from lldbsuite.test import lldbutil
13
14
15class TestBenchmarkLibcxxMap(BenchBase):
16
17    @benchmarks_test
18    def test_run_command(self):
19        """Benchmark the std::map data formatter (libc++)"""
20        self.build()
21        self.data_formatter_commands()
22
23    def setUp(self):
24        # Call super's setUp().
25        BenchBase.setUp(self)
26
27    def data_formatter_commands(self):
28        """Benchmark the std::map data formatter (libc++)"""
29        self.runCmd("file " +self.getBuildArtifact("a.out"),
30                    CURRENT_EXECUTABLE_SET)
31
32        bkpt = self.target().FindBreakpointByID(
33            lldbutil.run_break_set_by_source_regexp(
34                self, "break here"))
35
36        self.runCmd("run", RUN_SUCCEEDED)
37
38        # The stop reason of the thread should be breakpoint.
39        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
40                    substrs=['stopped',
41                             'stop reason = breakpoint'])
42
43        # This is the function to remove the custom formats in order to have a
44        # clean slate for the next test case.
45        def cleanup():
46            self.runCmd('type format clear', check=False)
47            self.runCmd('type summary clear', check=False)
48            self.runCmd('type filter clear', check=False)
49            self.runCmd('type synth clear', check=False)
50            self.runCmd(
51                "settings set target.max-children-count 256",
52                check=False)
53
54        # Execute the cleanup function during test case tear down.
55        self.addTearDownHook(cleanup)
56
57        sw = Stopwatch()
58
59        sw.start()
60        self.expect('frame variable -A map', substrs=['[300]', '300'])
61        sw.stop()
62
63        print("time to print: %s" % (sw))
64