# class RubyProf::MultiPrinter

Helper class to simplify printing profiles of several types from one profiling run. Currently prints a flat profile, a callgrind profile, a call stack profile and a graph profile.

### Public Class Methods

needs_dir?() click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 14
    def self.needs_dir?
      true
    end

new(result, printers = [:stack, :graph, :tree, :flat]) click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 7
    def initialize(result, printers = [:stack, :graph, :tree, :flat])
      @stack_printer = CallStackPrinter.new(result) if printers.include?(:stack)
      @graph_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph)
      @tree_printer = CallTreePrinter.new(result) if printers.include?(:tree)
      @flat_printer = FlatPrinter.new(result) if printers.include?(:flat)
    end

### Public Instance Methods

flat_profile() click to toggle source

the name of the flat profile file

    # File lib/ruby-prof/printers/multi_printer.rb, line 49
    def flat_profile
      "#{@directory}/#{@profile}.flat.txt"
    end

graph_profile() click to toggle source

the name of the graph profile file

    # File lib/ruby-prof/printers/multi_printer.rb, line 39
    def graph_profile
      "#{@directory}/#{@profile}.graph.html"
    end

print(options) click to toggle source

create profile files under options or the current directory. options is used as the base name for the pofile file, defaults to “profile”.

    # File lib/ruby-prof/printers/multi_printer.rb, line 21
    def print(options)
      validate_print_params(options)

      @profile = options.delete(:profile) || "profile"
      @directory = options.delete(:path) || File.expand_path(".")

      print_to_stack(options) if @stack_printer
      print_to_graph(options) if @graph_printer
      print_to_tree(options) if @tree_printer
      print_to_flat(options) if @flat_printer
    end

print_to_flat(options) click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 69
    def print_to_flat(options)
      File.open(flat_profile, "w") do |f|
        @flat_printer.print(f, options)
      end
    end

print_to_graph(options) click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 59
    def print_to_graph(options)
      File.open(graph_profile, "w") do |f|
        @graph_printer.print(f, options)
      end
    end

print_to_stack(options) click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 53
    def print_to_stack(options)
      File.open(stack_profile, "w") do |f|
        @stack_printer.print(f, options.merge(:graph => "#{@profile}.graph.html"))
      end
    end

print_to_tree(options) click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 65
    def print_to_tree(options)
      @tree_printer.print(options.merge(:path => @directory, :profile => @profile))
    end

stack_profile() click to toggle source

the name of the call stack profile file

    # File lib/ruby-prof/printers/multi_printer.rb, line 34
    def stack_profile
      "#{@directory}/#{@profile}.stack.html"
    end

tree_profile() click to toggle source

the name of the callgrind profile file

    # File lib/ruby-prof/printers/multi_printer.rb, line 44
    def tree_profile
      "#{@directory}/#{@profile}.callgrind.out.#{$$}"
    end

validate_print_params(options) click to toggle source

    # File lib/ruby-prof/printers/multi_printer.rb, line 75
    def validate_print_params(options)
      if options.is_a?(IO)
        raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
      elsif !options.is_a?(Hash)
        raise ArgumentError, "#{self.class.name}#print requires an options hash"
      end
    end