Skip to content

Commit

Permalink
Rename to xcprofiler
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Dec 26, 2016
1 parent f15ce09 commit cc300e3
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 62 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
# xctracker
# xcprofiler

[![Build Status](https://travis-ci.org/giginet/xctracker.svg?branch=master)](https://travis-ci.org/giginet/xctracker)
[![Coverage Status](https://coveralls.io/repos/github/giginet/xctracker/badge.svg?branch=master)](https://coveralls.io/github/giginet/xctracker?branch=master)
[![Gem Version](https://badge.fury.io/rb/xctracker.svg)](https://badge.fury.io/rb/xctracker)
[![Build Status](https://travis-ci.org/giginet/xcprofiler.svg?branch=master)](https://travis-ci.org/giginet/xcprofiler)
[![Coverage Status](https://coveralls.io/repos/github/giginet/xcprofiler/badge.svg?branch=master)](https://coveralls.io/github/giginet/xcprofiler?branch=master)
[![Gem Version](https://badge.fury.io/rb/xcprofiler.svg)](https://badge.fury.io/rb/xcprofiler)

Command line utility to analyze build times of Swift projects

![](https://raw.githubusercontent.com/giginet/xctracker/master/assets/sample_output.png)
![](https://raw.githubusercontent.com/giginet/xcprofiler/master/assets/sample_output.png)

This tool developed in working time for Cookpad.

## Installation

```
gem install xctracker
gem install xcprofiler
```

## Usage

1. Add `-Xfrontend -debug-time-function-bodies` build flags in `Other Swift Flags` section on your Xcode project.
![](https://raw.githubusercontent.com/giginet/xctracker/master/assets/build_flags.png)
![](https://raw.githubusercontent.com/giginet/xcprofiler/master/assets/build_flags.png)

2. Build your project
3. Execute `xctracker`
3. Execute `xcprofiler`

```
$ xctracker [PRODUCT_NAME or ACTIVITY_LOG_PATH] [options]
$ xcprofiler [PRODUCT_NAME or ACTIVITY_LOG_PATH] [options]
```

`xctracker` searches the latest build log on your DerivedData directory.
`xcprofiler` searches the latest build log on your DerivedData directory.

You can also specify the `.xcactivitylog`.

```
$ xctracker MyApp
$ xctracker ~/Library/Developer/Xcode/DerivedData/MyApp-xxxxxxxxxxx/Logs/Build/0761C73D-3B6C-449A-BE89-6D11DAB748FE.xcactivitylog
$ xcprofiler MyApp
$ xcprofiler ~/Library/Developer/Xcode/DerivedData/MyApp-xxxxxxxxxxx/Logs/Build/0761C73D-3B6C-449A-BE89-6D11DAB748FE.xcactivitylog
```

Sample output is here
Expand Down Expand Up @@ -79,25 +79,25 @@ Sample output is here
You can use reporters to output tracking logs.

```ruby
require 'xctracker'
require 'xcprofiler'

tracker = Xctracker::Tracker.by_product_name('MyApp')
tracker.reporters = [
Xctracker::StandardOutputReporter.new(limit: 20, order: :time)],
Xctracker::JSONReporter.new({output_path: 'result.json'})
profiler = Xcprofiler::Profiler.by_product_name('MyApp')
profiler.reporters = [
Xcprofiler::StandardOutputReporter.new(limit: 20, order: :time)],
Xcprofiler::JSONReporter.new({output_path: 'result.json'})
]
tracker.report!
profiler.report!
```

You can also implement your own reporters.

See implementation of [built-in reporters](https://github.com/giginet/xctracker/tree/master/lib/xctracker/reporters) for detail.
See implementation of [built-in reporters](https://github.com/giginet/xcprofiler/tree/master/lib/xcprofiler/reporters) for detail.

## License

MIT License

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/giginet/xctracker.
Bug reports and pull requests are welcome on GitHub at https://github.com/giginet/xcprofiler.

4 changes: 2 additions & 2 deletions bin/xctracker → bin/xcprofiler
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
$LOAD_PATH.push File.expand_path("../../lib", __FILE__)

require 'xctracker'
require 'xcprofiler'

Xctracker.execute(ARGV)
Xcprofiler.execute(ARGV)
28 changes: 14 additions & 14 deletions lib/xctracker.rb → lib/xcprofiler.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
require "xctracker/derived_data"
require "xctracker/exceptions"
require "xctracker/execution"
require "xctracker/tracker"
require "xctracker/version"
require "xctracker/reporters/abstract_reporter"
require "xctracker/reporters/standard_output_reporter"
require "xctracker/reporters/json_reporter"
require "xcprofiler/derived_data"
require "xcprofiler/exceptions"
require "xcprofiler/execution"
require "xcprofiler/profiler"
require "xcprofiler/version"
require "xcprofiler/reporters/abstract_reporter"
require "xcprofiler/reporters/standard_output_reporter"
require "xcprofiler/reporters/json_reporter"
require "colorize"
require "optparse"
require "ostruct"

module Xctracker
module Xcprofiler
class << self
def execute(args)
options = OpenStruct.new
options.order = :time
options.reporters = [:standard_output]

parser = OptionParser.new do |opts|
opts.banner = "Usage: xctracker [product name or .xcactivitylog file] [options]".red
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 }
Expand All @@ -40,16 +40,16 @@ def execute(args)

begin
if target.end_with?('.xcactivitylog')
tracker = Tracker.by_path(target)
profiler = Profiler.by_path(target)
else
tracker = Tracker.by_product_name(target)
profiler = Profiler.by_product_name(target)
end
tracker.reporters = [
profiler.reporters = [
StandardOutputReporter.new(limit: options[:limit],
order: order,
show_invalid_locations: options[:show_invalid_locations])
]
tracker.report!
profiler.report!
rescue Exception => e
puts e.message.red
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'zlib'

module Xctracker
module Xcprofiler
class DerivedData
class << self
def all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Xctracker
module Xcprofiler
class DerivedDataNotFound < Exception
end

Expand Down
2 changes: 1 addition & 1 deletion lib/xctracker/execution.rb → lib/xcprofiler/execution.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Xctracker
module Xcprofiler
class Execution
Struct.new('Position', :path, :line, :column)

Expand Down
8 changes: 4 additions & 4 deletions lib/xctracker/tracker.rb → lib/xcprofiler/profiler.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require 'terminal-table'
require 'colorize'

module Xctracker
class Tracker
module Xcprofiler
class Profiler
attr_writer :reporters
attr_reader :derived_data

def self.by_path(activity_log_path)
derived_data = DerivedData.new(activity_log_path)
Tracker.new(derived_data)
Profiler.new(derived_data)
end

def self.by_product_name(product_name)
derived_data = DerivedData.by_product_name(product_name)
Tracker.new(derived_data)
Profiler.new(derived_data)
end

def initialize(derived_data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Xctracker
module Xcprofiler
class AbstractReporter
attr_reader :options

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'json'

module Xctracker
module Xcprofiler
class JSONReporter < AbstractReporter
def report!(executions)
json = filter_executions(executions).map(&:to_h)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'terminal-table'

module Xctracker
module Xcprofiler
class StandardOutputReporter < AbstractReporter
def report!(executions)
filtered = filter_executions(executions)
Expand Down
2 changes: 1 addition & 1 deletion lib/xctracker/version.rb → lib/xcprofiler/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Xctracker
module Xcprofiler
VERSION = "0.1.1"
end
2 changes: 1 addition & 1 deletion spec/derived_data_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
include Xctracker
include Xcprofiler

describe DerivedData do

Expand Down
2 changes: 1 addition & 1 deletion spec/execution_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
include Xctracker
include Xcprofiler

describe Execution do
context 'with location' do
Expand Down
2 changes: 1 addition & 1 deletion spec/reporters/abstract_reporter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
include Xctracker
include Xcprofiler

describe AbstractReporter do
let(:valid_executions) do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
require 'coveralls'
Coveralls.wear!

require 'xctracker'
require 'xcprofiler'

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
Expand Down
12 changes: 6 additions & 6 deletions spec/tracker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
require 'spec_helper'
include Xctracker
include Xcprofiler

describe Tracker do
describe Profiler do

before do
fixture_root = File.absolute_path(File.join(__FILE__, '../fixtures'))
allow(DerivedData).to receive(:derived_data_root).and_return(fixture_root)
end

let(:tracker) { Tracker.new(derived_data) }
let(:profiler) { Profiler.new(derived_data) }

context 'with flag not enabled data' do
let(:derived_data) { DerivedData.by_product_name('Invalid') }

describe '#report!' do
it 'raises error' do
expect {
tracker.report!
profiler.report!
}.to raise_error(BuildFlagIsNotEnabled, "'-Xfrontend -debug-time-function-bodies' flag is not enabled")
end
end
Expand All @@ -29,11 +29,11 @@
let(:reporter) { double('Reporter') }
before do
allow(reporter).to receive(:report!).with(an_instance_of(Array))
tracker.reporters = [reporter]
profiler.reporters = [reporter]
end

it 'reporters are invoked' do
tracker.report!
profiler.report!
expect(reporter).to have_received(:report!).with(an_instance_of(Array))
end
end
Expand Down
10 changes: 5 additions & 5 deletions xctracker.gemspec → xcprofiler.gemspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'xctracker/version'
require 'xcprofiler/version'

Gem::Specification.new do |spec|
spec.name = "xctracker"
spec.version = Xctracker::VERSION
spec.name = "xcprofiler"
spec.version = Xcprofiler::VERSION
spec.authors = ["giginet"]
spec.email = ["giginet.net@gmail.com"]

spec.summary = %q{CLI to analyze build times of Swift projects}
spec.description = %q{xctracker parses activity logs generated by Xcode and reports build time of Swift projects}
spec.homepage = 'https://github.com/giginet/xctracker'
spec.description = %q{xcprofiler parses activity logs generated by Xcode and reports build time of Swift projects}
spec.homepage = 'https://github.com/giginet/xcprofiler'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
Expand Down

0 comments on commit cc300e3

Please sign in to comment.