Exemplo n.º 1
0
    def show(self):
        """
        Displays the input stack as a treemap using the d3IpyPlus tool.

        Creates the ids and the columns that are passed in the treemap object,
        which is used to generate a html file that is to be displayed.
        """

        # Temp file for the csv file
        temp_file = str(file.TempFileName())
        self._generate_csv(temp_file)

        # Generate the ids we use for the hierarchies and the columns of the
        # input file
        ids = [str(i) for i in range(1, self.display_options.depth + 1)]
        cols = [self.data_options.weight_units] + ids

        # Retrieve data from the temporary file that holds the csv format
        # that d3 uses
        data = d3.from_csv(temp_file, ';', columns=cols)

        # Create the treemap with the supplied display options
        tmap = d3.TreeMap(id=ids[0:self.display_options.depth],
                          value=self.data_options.weight_units,
                          color=self.data_options.weight_units,
                          legend=True,
                          width=700)

        temp_display_file = str(file.TempFileName())
        with open(temp_display_file, "w") as out:
            out.write(tmap.dump_html(data))

        username = os.environ['SUDO_USER']
        subprocess.call(
            ["su", "-", "-c", "firefox " + temp_display_file, username])
Exemplo n.º 2
0
    def show(self):
        """
        Calls g2 to show a track separated graph.

        The conversion for the MARPLE format happens here, a new CPEL file being
        created.

        """
        tmp_cpel = str(file.TempFileName())
        g2_path = config.get_option_from_section('g2', 'path')
        g2_path = os.path.expanduser(g2_path)
        logger.info("G2 path: %s", g2_path)

        # We create a generator that yields EventDatum from
        event_generator = self.data.datum_generator
        writer = CpelWriter(event_generator, self.display_options.track)
        writer.write(str(tmp_cpel))

        try:
            subprocess.call([g2_path, "--cpel-input", str(tmp_cpel)])
        except FileNotFoundError as fnfe:
            output.error_(
                "G2 not found at {}. Check your config file?".format(
                    fnfe.filename),
                "Could not find G2 at {}, FileNotFoundError raised. "
                "Change your config file to show the correct G2 path.".format(
                    fnfe.filename))
Exemplo n.º 3
0
    def _make(self):
        """
        Uses Brendan Gregg's flamegraph tool to convert data to flamegraph.

        """
        stacks_temp_file = str(file.TempFileName())
        counts = collections.Counter()

        stack_data = self.data.datum_generator
        for stack in stack_data:
            new_counts = collections.Counter({stack.stack: stack.weight})
            counts += new_counts

        with open(stacks_temp_file, "w") as out:
            for stack, count in counts.items():
                out.write(";".join(stack) + " {}\n".format(count))

        with open(self.svg_temp_file, "w") as out:
            if self.display_options.coloring:
                sp = subprocess.Popen([
                    FLAMEGRAPH_DIR, "--color=" + self.display_options.coloring,
                    "--countname=" + self.data_options.weight_units,
                    stacks_temp_file
                ],
                                      stdout=out)
            else:
                sp = subprocess.Popen([FLAMEGRAPH_DIR, stacks_temp_file],
                                      stdout=out)
        # Wait for the subprocess to generate the svg file so the show method
        # doesn't try to open it while it's being written to
        sp.wait()

        return counts  # for testing
Exemplo n.º 4
0
    def __init__(self, data):
        """
        Initialise the flamegraph.

        :param data:
            A `data_io.StackData` object that encapsulated the collected data
            we want to display as a flamegraph

        """
        # Initialise the base class
        super().__init__(data)

        coloring = config.get_option_from_section(
            consts.DisplayOptions.FLAMEGRAPH.value, "coloring")
        self.display_options = self.DisplayOptions(coloring)
        self.svg_temp_file = str(file.TempFileName())
Exemplo n.º 5
0
 def test_simple(self):
     tfn = file.TempFileName()
     self.assertEqual(paths.TMP_DIR + "date.tmp", str(tfn))