stackprof-webnav 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0b0477364b7de56855e675ddd67faf38ee67c30
4
- data.tar.gz: 351fabc3894db01a0e7bf7aad98a946698500f1c
3
+ metadata.gz: 860162061e27285bfb60182eebe0b2764fae0494
4
+ data.tar.gz: 3c1faab65bd0b183b32e8fe0966f2231eda8552b
5
5
  SHA512:
6
- metadata.gz: 21b62f009b154a395474d1c56d736f1fe886b72550188c47623bcf558a1c610b62776d6f002cfde25b6d746290b0c528f819da6be459d46020aebac4d9b77e28
7
- data.tar.gz: 9cb2e6053bf5827c487815004b50f48189a29f2bb069774fb3db1b17339b0e975a73587dae29db97c0e7a82f16b0c98e7b50172af6963278fe6aa503468c2c48
6
+ metadata.gz: c3fef38f9828dd0d1df0a9cb86ad6a829cc4fabe5e2fd59986ecfefe51f4ba4b8d192bed34f96f6ff34f260780451b27b915a409387e5011da964cbdb68586c3
7
+ data.tar.gz: 49f8daf5c57d8533bf762dbf21c6c487cc1e3c9a316721bb3c28e8124e90326294eabc3830d79040fe28543f82bbefcc762d9f927ab8c7c0eee120032140e350
data/README.md CHANGED
@@ -19,17 +19,18 @@ Provides a web ui to inspect stackprof dumps.
19
19
  $ gem install stackprof-webnav
20
20
  ```
21
21
 
22
- ### Pass a dump to it
22
+ ### Pass a dump/URI to it
23
23
  ```bash
24
- $ stackprof-webnav /path/to/stackprof.dump
25
- $ stackprof-webnav http://path/to/stackprof.dump
24
+ $ stackprof-webnav -f /path/to/stackprof.dump
25
+ $ stackprof-webnav -u http://path/to/stackprof.dump
26
+ $ stackprof-webnav -b http://amazon/s3/bucketlisting.xml
26
27
  ```
27
- If the argument passed does not exist locally, it is assumed to be a URI and is treated as such.
28
28
 
29
29
  See [stackprof gem][create-dump] homepage to learn how to create dumps.
30
+ See [amazon s3 API docs][list-bucket-contents] to see the URI format for S3 bucket listings.
30
31
 
31
32
  ### Profit
32
- Open the browser at localhost:9292
33
+ Open the browser at localhost:9292. If you've used the -f or -u form, you can navigate the dump. If you've used the -b form, you'll see a listing of the keys in the bucket -- click on one that is a dump to browse through it.
33
34
 
34
35
  ## Caveats
35
36
  - no tests, this gem was created for my personal usage in a hack stream,
@@ -47,3 +48,4 @@ Open the browser at localhost:9292
47
48
  [main-screenshot]: https://github.com/alisnic/stackprof-webnav/blob/master/screenshots/main.png?raw=true
48
49
  [method-screenshot]: https://github.com/alisnic/stackprof-webnav/blob/master/screenshots/method.png?raw=true
49
50
  [file-screenshot]: https://github.com/alisnic/stackprof-webnav/blob/master/screenshots/file.png?raw=true
51
+ [list-bucket-contents]: http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html
@@ -7,20 +7,17 @@ options = {
7
7
  }
8
8
 
9
9
  parser = OptionParser.new(ARGV) do |o|
10
- o.banner = "Usage: stackprof-webnav file.dump|http://path/to/file.dump [-p NUMBER]"
10
+ o.banner = "Usage: stackprof-webnav [-f localfile.dump]|[-u http://path/to/file.dump]|[-b http://path/to/s3/bucket/listing] [-p NUMBER]"
11
+ o.on('-f [LOCALFILE]', 'Local file path to dump') {|filepath| options[:filepath] = filepath }
12
+ o.on('-u [URI]', 'URI path to dump') {|uri| options[:uri] = uri }
13
+ o.on('-b [URI]', 'URI path to Amazon S3 bucket listing') {|bucket| options[:bucket] = bucket}
11
14
  o.on('-p [PORT]', 'Server port') {|port| options[:port] = port }
12
15
  end
13
16
 
14
17
  parser.parse!
15
- parser.abort(parser.help) if ARGV.empty?
18
+ parser.abort(parser.help) unless [:filepath, :uri, :bucket].any? {|key| options.key?(key)}
16
19
 
17
- file = ARGV.pop
18
20
  server = StackProf::Webnav::Server
19
-
20
- if File.exists?(file)
21
- server.report_dump_path = File.expand_path(file)
22
- else
23
- server.report_dump_url = file
24
- end
21
+ server.cmd_options = options
25
22
 
26
23
  server.run! options[:port]
@@ -1,5 +1,6 @@
1
1
  require 'better_errors'
2
2
  require 'stringio'
3
+ require 'rexml/document'
3
4
 
4
5
  module StackProf
5
6
  module Webnav
@@ -33,6 +34,23 @@ module StackProf
33
34
  end
34
35
  end
35
36
 
37
+ def listing_dumps
38
+ xml_data = Net::HTTP.get(URI.parse(Server.report_dump_listing))
39
+ if xml_data
40
+ doc = REXML::Document.new(xml_data)
41
+ dumps = []
42
+ doc.elements.each('ListBucketResult/Contents') do |ele|
43
+ dumps << {
44
+ :key => ele.elements["Key"].text,
45
+ :date => ele.elements["LastModified"].text,
46
+ :uri => Server.report_dump_listing + ele.elements["Key"].text
47
+ }
48
+ end
49
+ end
50
+ dumps.sort_by! { |hash| hash[:date] }
51
+ dumps.reverse!
52
+ end
53
+
36
54
  def method_info name
37
55
  name = /#{Regexp.escape name}/ unless Regexp === name
38
56
  frames = report.frames.select do |frame, info|
@@ -12,19 +12,33 @@ module StackProf
12
12
  config.assets.paths << File.join(__dir__, 'css')
13
13
 
14
14
  class << self
15
- attr_accessor :report_dump_path, :report_dump_url
15
+ attr_accessor :cmd_options, :report_dump_path, :report_dump_uri, :report_dump_listing
16
16
 
17
- def presenter
18
- return @presenter unless @presenter.nil?
19
- content = if report_dump_path.nil?
20
- Net::HTTP.get(URI.parse(report_dump_url))
21
- else
22
- File.open(report_dump_path).read
23
- end
17
+ def presenter regenerate=false
18
+ return @presenter unless regenerate || @presenter.nil?
19
+ process_options
20
+ if self.report_dump_path || self.report_dump_uri
21
+ report_contents = if report_dump_path.nil?
22
+ Net::HTTP.get(URI.parse(report_dump_uri))
23
+ else
24
+ File.open(report_dump_path).read
25
+ end
26
+ report = StackProf::Report.new(Marshal.load(report_contents))
27
+ end
28
+ @presenter = Presenter.new(report)
29
+ end
24
30
 
25
- report = StackProf::Report.new(Marshal.load(content))
26
- @presenter ||= Presenter.new(report)
31
+ private
32
+ def process_options
33
+ if cmd_options[:filepath]
34
+ self.report_dump_path = cmd_options[:filepath]
35
+ elsif cmd_options[:uri]
36
+ self.report_dump_uri = cmd_options[:uri]
37
+ elsif cmd_options[:bucket]
38
+ self.report_dump_listing = cmd_options[:bucket]
39
+ end
27
40
  end
41
+
28
42
  end
29
43
 
30
44
  helpers do
@@ -48,15 +62,39 @@ module StackProf
48
62
  def file_url path
49
63
  "/file?path=#{URI.escape(path)}"
50
64
  end
65
+
66
+ def overview_url path
67
+ "/overview?path=#{URI.escape(path)}"
68
+ end
51
69
  end
52
70
 
53
71
  get '/' do
54
- @file = Server.report_dump_path || Server.report_dump_url
72
+ presenter
73
+ if Server.report_dump_listing
74
+ redirect_to '/listing'
75
+ else
76
+ redirect_to '/overview'
77
+ end
78
+ end
79
+
80
+ get '/overview' do
81
+ if params[:path]
82
+ Server.report_dump_uri = params[:path]
83
+ Server.presenter(true)
84
+ end
85
+ @file = Server.report_dump_path || Server.report_dump_uri
55
86
  @action = "overview"
56
87
  @frames = presenter.overview_frames
57
88
  render_with_layout :overview
58
89
  end
59
90
 
91
+ get '/listing' do
92
+ @file = Server.report_dump_listing
93
+ @action = "listing"
94
+ @dumps = presenter.listing_dumps
95
+ render_with_layout :listing
96
+ end
97
+
60
98
  get '/method' do
61
99
  @action = params[:name]
62
100
  @frames = presenter.method_info(params[:name])
@@ -1,5 +1,5 @@
1
1
  module StackProf
2
2
  module Webnav
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ %h3 StackProf Navigator
2
+ %hr
3
+
4
+ %p
5
+ Viewing S3 bucket at
6
+ %b= @file
7
+
8
+ %table.centered
9
+ %thead
10
+ %th Key
11
+ %th Date
12
+ %th Dump
13
+
14
+ %tbody
15
+ - @dumps.each do |dump|
16
+ %tr
17
+ %td= dump[:key]
18
+ %td= dump[:date]
19
+ %td
20
+ %a{:href => overview_url(dump[:uri])}
21
+ = dump[:uri]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackprof-webnav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Lisnic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nyny
@@ -118,6 +118,7 @@ files:
118
118
  - lib/stackprof-webnav/version.rb
119
119
  - lib/stackprof-webnav/views/file.haml
120
120
  - lib/stackprof-webnav/views/layout.haml
121
+ - lib/stackprof-webnav/views/listing.haml
121
122
  - lib/stackprof-webnav/views/method.haml
122
123
  - lib/stackprof-webnav/views/overview.haml
123
124
  - screenshots/file.png