Module: Xcprofiler

Defined in:
lib/xcprofiler.rb,
lib/xcprofiler/version.rb,
lib/xcprofiler/profiler.rb,
lib/xcprofiler/execution.rb,
lib/xcprofiler/exceptions.rb,
lib/xcprofiler/derived_data.rb,
lib/xcprofiler/reporters/json_reporter.rb,
lib/xcprofiler/reporters/block_reporter.rb,
lib/xcprofiler/reporters/abstract_reporter.rb,
lib/xcprofiler/reporters/standard_output_reporter.rb

Defined Under Namespace

Classes: AbstractReporter, BlockReporter, BuildFlagIsNotEnabled, DerivedData, DerivedDataNotFound, Execution, JSONReporter, OutputPathIsNotSpecified, Profiler, StandardOutputReporter

Constant Summary collapse

VERSION =
"0.6.1"

Class Method Summary collapse

Class Method Details

.execute(args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/xcprofiler.rb', line 16

def execute(args)
  options = OpenStruct.new
  options.order = :time
  options.reporters = [:standard_output]

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: xcprofiler [product name or .xcactivitylog file] [options]".red

    opts.on("--[no-]show-invalids", "Show invalid location results") { |v| options.show_invalid_locations = v }
    opts.on("-o [ORDER]", [:default, :time, :file], "Sort order") { |v| options.order = v }
    opts.on("-l", "--limit [LIMIT]", Integer, "Limit for display") { |v| options.limit = v }
    opts.on("--threshold [THRESHOLD]", Integer, "Threshold of time to display(ms)") { |v| options.threshold = v }
    opts.on("--derived-data-path", String, "Root path of DerivedData") { |v| options.derived_data_path = v }
    opts.on("-t", "--truncate-at [TRUNCATE_AT]", Integer, "Truncate the method name with specified length") { |v| options.truncate_at = v }
    opts.on("--[no-]unique", "Reject duplicated location results or not") { |v| options.unique = v }
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end
  parser.parse!(args)

  target = args.pop
  unless target
    puts parser
    exit 1
  end

  order = options[:order] or :time

  begin
    if target.end_with?('.xcactivitylog')
      profiler = Profiler.by_path(target)
    else
      derived_data_path = options[:derived_data_path]
      profiler = Profiler.by_product_name(target, derived_data_path)
    end
    profiler.reporters = [StandardOutputReporter.new(limit: options[:limit],
                                 threshold: options[:threshold],
                                 order: order,
                                 show_invalid_locations: options[:show_invalid_locations],
                                 truncate_at: options[:truncate_at],
                                 unique: options[:unique])]
    profiler.report!
  rescue Exception => e
    puts e.message.red
  end
end