source_route 0.1.4 → 0.1.5

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: 53ca6ceb4707f51a82dae6898626acc4d48a833d
4
- data.tar.gz: f7195096abe06dbf7be4de3c50ec29cd778be20e
3
+ metadata.gz: 89e5066f6c1b4590957260ef57b44982b01cf006
4
+ data.tar.gz: 3ae996d75fa35ba29b45e1afe7a77ae3932984d8
5
5
  SHA512:
6
- metadata.gz: f53ae0700478709b418e659d4a724a0ef5555a676ba8c8b51388d179467919ada812f5fee3523573943b74fa15ae8f5a3422016ca6e767c30739193b768d48ca
7
- data.tar.gz: c54533ac8b57235ca3ef6a92911cf84a8d5cb22e15add32f16769eb0c2148499ce3016d56bf8102efac1d87484fcf9f9bafff9321fe5a1f2aca851de99c53254
6
+ metadata.gz: 332fe83850831d9c872bdbfdf05a3d1fc3eb047704a7308a18ad93f6308beba1332b63164261917fe51468e7a128f1769a509e5061c218868723a0990a78728c
7
+ data.tar.gz: aa108ff2d48aee83a49c45d5d2a65152512a7a94a7fd33f7614939cd771a0f97949efe9d09761e2cf6d12c5cac6578aab3680497a67f5a621761547fdd5e05e4
data/README.md CHANGED
@@ -41,7 +41,10 @@ you will get a different trace file.
41
41
 
42
42
  #### In your ruby application
43
43
 
44
- SourceRoute.enable :wanted_method_name
44
+ SourceRoute.enable do
45
+ method_id :wanted_method_name
46
+ full_feature
47
+ end
45
48
  .... # here is your code
46
49
  ....
47
50
  ....
@@ -65,7 +68,7 @@ see full usage in examples/callback_in_activesupport.rb
65
68
 
66
69
  ## Why
67
70
 
68
- I always wanna upgrade my ruby(rails) skills. But everytime when I look for workaround from stack overflow I feel frustration.
71
+ I always wanna upgrade my ruby(rails) skills. But everytime when I looking for workaround from stack overflow I feel frustration.
69
72
 
70
73
  To get solution or workaround from google or stack overflow is suitable when I'm a ruby starter or deadline is urgent. But it's not really helpful for my skills.
71
74
 
@@ -92,14 +95,12 @@ Finally, I expect my working style can change from searching workaround from int
92
95
 
93
96
  ### TODO
94
97
 
95
- Add debug option to provider more verbose messages of what has happened
98
+ Dynamic indent when new child level comes.
96
99
 
97
- Open File directly from browser(chrome) by plugin?
100
+ Animation when child was click.
98
101
 
99
- Apply https://github.com/a5hik/ng-sortable
102
+ Show loading when click clear. (when $apply() take more than 1 seconds to run)
100
103
 
101
- Add vertical timeline.
102
- (see http://tympanus.net/codrops/2013/05/02/vertical-timeline/
103
- http://stackoverflow.com/questions/20896240/responsive-timeline-ui-with-bootstrap3)
104
+ Add debug option to provide more verbose messages of what has happened
104
105
 
105
- Hide defined class filter.
106
+ Open File directly from browser(chrome) by plugin?
@@ -2,9 +2,12 @@ doctype html
2
2
  html
3
3
  head
4
4
  title Source Route Result
5
- link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"
5
+ link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"
6
+ link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css"
7
+ link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"
8
+ script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"
6
9
  script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"
7
- script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
10
+ script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"
8
11
 
9
12
  css:
10
13
  .call-level-0 {}
@@ -15,7 +18,8 @@ html
15
18
  .call-level-5 { margin-left: 250px }
16
19
  .call-level-6 { margin-left: 300px }
17
20
  .call-level-7 { margin-left: 300px }
18
- body(ng-app="SourceRoute" ng-controller="MainCtrl")
21
+ .details .well { margin-bottom: 0; color: green }
22
+ body(ng-app="SourceRoute" ng-controller="MainCtrl" ng-cloak)
19
23
 
20
24
  nav.navbar.navbar-default.navbar-static-top
21
25
  .container
@@ -34,13 +38,12 @@ html
34
38
  .clearfix
35
39
 
36
40
  .container
37
- .level-header(ng-if="parentLengthList" style="padding-bottom: 10px")
41
+ .level-header(ng-if="::traces[0].hasOwnProperty('parent_ids')" style="padding-bottom: 10px")
38
42
  .btn-group>
39
- button.btn.btn-default>(ng-click="traceFilter.parent_length = length" ng-repeat="length in parentLengthList")
40
- span> Level
41
- span(ng-bind="::length")
43
+ button.btn.btn-default>(ng-click="outlineTrace()")
44
+ span> OutLine
42
45
  span
43
- button.btn.btn-primary(ng-click="traceFilter.parent_length = undefined") Clear
46
+ button.btn.btn-primary(ng-click="removeOutlineTrace()") Clear
44
47
 
45
48
  .trace-flow
46
49
  .row
@@ -50,9 +53,17 @@ html
50
53
  ng-click="traceFilter.defined_class = klass" style="height: 60px")
51
54
  span(ng-bind="klass.substring(0, 40)" popover="{{klass}}" popover-trigger="mouseenter" popover-placement="bottom")
52
55
  .traces.center-info.col-sm-12(ng-class="{{traceFilter.event}}")
53
- .trace.well.well-lg.call-level.call-level(ng-repeat="trace in traces | filter:traceFilter:true"
54
- ng-class="callLevelClass(trace)")
55
- .header(ng-click="showMoreDetail = !showMoreDetail")
56
+ .trace.well(ng-repeat="trace in traces | filter:traceFilter:true | filter:childParentFilterFn"
57
+ ng-class="callLevelClass(trace)" ng-controller="TpTraceCtrl")
58
+ .header(ng-init="showMoreDetail = false")
59
+ .btn-group.pull-right
60
+ button.btn.btn-info.btn-sm(ng-if="::hasChild()" ng-click="toggleChild()")
61
+ span(ng-hide="trace.childClosed")
62
+ i.fa.fa-angle-down
63
+ span(ng-show="trace.childClosed")
64
+ i.fa.fa-angle-right
65
+ span Child
66
+ button.btn.btn-info.btn-sm(ng-show="::containsDetail(trace)" ng-click="showMoreDetail = !showMoreDetail") Details
56
67
  span(ng-bind="trace.defined_class")
57
68
  span
58
69
  | .
@@ -61,46 +72,54 @@ html
61
72
  div(ng-if="trace.hasOwnProperty('return_value')")
62
73
  span
63
74
  | =>
64
- span<(ng-bind="trace.return_value.substring(0, 150)")
75
+ span<(ng-bind="trace.return_value.substring(0, 200) | json")
65
76
 
66
77
  .details(ng-if="showMoreDetail")
67
- .local-vars.well.well-sm(ng-if="trace.local_var" style="color: green; margin-bottom: 0")
78
+ .attrs.well.well-sm(ng-if="containsOtherAttrs(trace)")
79
+ span Attrs
80
+ div(hljs source="::combinedAttrs(trace) | json")
81
+ .local-vars.well.well-sm(ng-if="trace.local_var")
68
82
  span Local Var
69
- .local-values(ng-repeat="(key, value) in trace.local_var")
70
- span<>(ng-bind="key")
71
- span<>
72
- | =>
73
- / ? could inspect repaire it ?
74
- span<>(ng-bind="value | json")
75
- .ins-vars.well.well-sm(ng-if="trace.instance_var" style="color: blue; margin-bottom: 0")
83
+ .local-values(hljs source="::trace.local_var | json")
84
+ .ins-vars.well.well-sm(ng-if="trace.instance_var")
76
85
  span Instance Var
77
- .ins-values(ng-repeat="(key, value) in trace.instance_var")
78
- span<>(ng-bind="key")
79
- span<>
80
- | =>
81
- span<>(ng-bind="value | json")
82
- .self-obj.well.well-sm(ng-if="trace.hasOwnProperty('tp_self')" style="color: red; margin-bottom: 0")
83
- span Self
84
- div
85
- span(ng-bind="tpSelfList[trace.tp_self] | json")
86
- .path-value.well.well-sm(ng-if="trace.path")
87
- span Path
88
- div
89
- span<>(ng-bind="trace.path")
90
- span<>(ng-bind="trace.lineno")
86
+ .ins-values(hljs source="::trace.instance_var | json")
91
87
 
92
88
  .right-info.col-sm-2
93
89
 
94
- script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"
90
+ script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"
95
91
  script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.2/ui-bootstrap-tpls.min.js"
92
+ script src="http://pc035860.github.io/angular-highlightjs/angular-highlightjs.min.js"
96
93
 
97
94
  javascript:
98
- sourceRoute = angular.module('SourceRoute', ['ui.bootstrap'])
95
+ sourceRoute = angular.module('SourceRoute', ['ui.bootstrap', 'hljs'])
99
96
  sourceRoute.controller('MainCtrl', function($scope, $filter) {
100
97
  $scope.traces = angular.element("#trace-data").data('trace')
101
98
  $scope.tpSelfList = angular.element("#trace-data").data('tp-self-caches')
102
99
  $scope.tpEvents = angular.element("#trace-data").data('tp-events')
103
- $scope.parentLengthList = angular.element("#trace-data").data('tp-parent-length-list')
100
+ $scope.childParentFilter = { hide_parent_ids: [] }
101
+
102
+ $scope.childParentFilterFn = function(trace) {
103
+ if ($scope.childParentFilter.hide_parent_ids.length == 0) {
104
+ return true;
105
+ } else {
106
+ var shared_parents = _.intersection(trace.parent_ids, $scope.childParentFilter.hide_parent_ids);
107
+ if (shared_parents.length == 0) {
108
+ return true;
109
+ }
110
+ }
111
+ }
112
+
113
+ $scope.removeOutlineTrace = function() {
114
+ _.each($scope.traces, function(trace) { trace.childClosed = false; });
115
+ $scope.childParentFilter.hide_parent_ids = [];
116
+ }
117
+
118
+ $scope.outlineTrace = function() {
119
+ $scope.childParentFilter.hide_parent_ids = [];
120
+ _.chain($scope.traces).filter({parent_length: 0})
121
+ .each(function(trace) { trace.childClosed = true; $scope.childParentFilter.hide_parent_ids.push(trace.order_id) })
122
+ }
104
123
 
105
124
  $scope.traceFilter = {event: $scope.tpEvents[0]}
106
125
  if ($scope.tpEvents.length == 1 && angular.isUndefined($scope.traces[0].event)) {
@@ -113,24 +132,73 @@ html
113
132
 
114
133
  $scope.callLevelClass = function(trace) {
115
134
  if (trace.parent_length > 7) {
116
- return 'call-level-7'
135
+ return 'call-level-7';
117
136
  } else {
118
- return 'call-level-' + trace.parent_length
137
+ return 'call-level-' + trace.parent_length;
119
138
  }
120
139
  }
121
140
 
122
141
  $scope.resetTraceFilter = function() {
123
- $scope.traceFilter = {}
142
+ $scope.traceFilter = {};
124
143
  }
144
+
125
145
  $scope.currentCounter = function() {
126
- return $filter('filter')($scope.traces, $scope.traceFilter, true).length
146
+ return $filter('filter')($scope.traces, $scope.traceFilter, true).length;
147
+ }
148
+
149
+ $scope.containsOtherAttrs = function(trace) {
150
+ return trace.hasOwnProperty('path') || trace.hasOwnProperty('lineno') ||
151
+ trace.hasOwnProperty('tp_self');
152
+ }
153
+
154
+ $scope.containsDetail = function(trace) {
155
+ return $scope.containsOtherAttrs(trace) || trace.hasOwnProperty('local_var') ||
156
+ trace.hasOwnProperty('instance_var')
157
+ }
158
+
159
+ $scope.combinedAttrs = function(trace) {
160
+ var attrs = {}
161
+ if (trace.hasOwnProperty('lineno') && trace.hasOwnProperty('path')) {
162
+ attrs.path = trace.path + ":" + trace.lineno;
163
+ } else if (trace.hasOwnProperty('path')) {
164
+ attrs.path = trace.path;
165
+ }
166
+ if (trace.hasOwnProperty('tp_self')) {
167
+ attrs.self = $scope.tpSelfList[trace.tp_self];
168
+ }
169
+ return attrs;
170
+ }
171
+
172
+ })
173
+
174
+ sourceRoute.controller('TpTraceCtrl', function($scope) {
175
+ $scope.toggleChild = function() {
176
+ if ($scope.trace.childClosed) {
177
+ $scope.showChild();
178
+ } else {
179
+ $scope.hideChild();
180
+ }
181
+ }
182
+
183
+ $scope.showChild = function() {
184
+ $scope.trace.childClosed = false;
185
+ _.pull($scope.childParentFilter.hide_parent_ids, $scope.trace.order_id);
127
186
  }
128
187
 
188
+ $scope.hideChild = function() {
189
+ $scope.trace.childClosed = true;
190
+ $scope.childParentFilter.hide_parent_ids.push($scope.trace.order_id);
191
+ }
192
+
193
+ $scope.hasChild = function() {
194
+ return _.find($scope.traces, function(trace) {
195
+ return _.contains(trace.parent_ids, $scope.trace.order_id)
196
+ });
197
+ }
129
198
  })
130
199
 
131
200
  .data-collect
132
201
  / dont use local_trace_data.to_json, because ActiveSupport override it and can introduce unexpected crash for some data
133
202
  #trace-data(data-trace="#{jsonify_tp_result_chain}"
134
203
  data-tp-events="#{jsonify_events}"
135
- data-tp-self-caches="#{jsonify_tp_self_caches}"
136
- data-tp-parent-length-list="#{JSON.dump(parent_length_list)}")
204
+ data-tp-self-caches="#{jsonify_tp_self_caches}")
@@ -1,6 +1,8 @@
1
1
  module SourceRoute
2
2
 
3
3
  class TpResultChain
4
+ attr_reader :chain
5
+
4
6
  extend Forwardable
5
7
  def_delegators :@chain, :each, :index, :first, :last, :size, :push, :values_at, :pop, :[]
6
8
 
@@ -23,9 +25,11 @@ module SourceRoute
23
25
  matched_return_tp = return_chain.detect do |rtp|
24
26
  rtp[:tp_self] == ctp[:tp_self] and rtp[:method_id] == ctp[:method_id] and rtp[:defined_class] == ctp[:defined_class]
25
27
  end
26
- ctp[:return_value] = matched_return_tp[:return_value]
27
- ctp[:local_var] = matched_return_tp[:local_var] if matched_return_tp.key? :local_var
28
- ctp[:instance_var] = matched_return_tp[:instance_var] if matched_return_tp.key? :instance_var
28
+ unless matched_return_tp.nil?
29
+ ctp[:return_value] = matched_return_tp[:return_value]
30
+ ctp[:local_var] = matched_return_tp[:local_var] if matched_return_tp.key? :local_var
31
+ ctp[:instance_var] = matched_return_tp[:instance_var] if matched_return_tp.key? :instance_var
32
+ end
29
33
  end
30
34
  end
31
35
 
@@ -35,11 +39,12 @@ module SourceRoute
35
39
  return_tpr = return_chain.find do |rtpr|
36
40
  rtpr[:defined_class] == tpr[:defined_class] and rtpr[:method_id] == tpr[:method_id]
37
41
  end
38
-
39
- start_index, end_index = tpr[:order_id], return_tpr[:order_id]
40
- unless end_index == start_index + 1
41
- values_at(start_index+1 ... end_index).select { |tpr| tpr[:event] == :call }.each do |tpr|
42
- tpr[:parent_ids].push start_index
42
+ unless return_tpr.nil?
43
+ start_index, end_index = tpr[:order_id], return_tpr[:order_id]
44
+ unless end_index == start_index + 1
45
+ values_at(start_index+1 ... end_index).select { |tpr| tpr[:event] == :call }.each do |tpr|
46
+ tpr[:parent_ids].push start_index
47
+ end
43
48
  end
44
49
  end
45
50
  end
@@ -51,6 +56,26 @@ module SourceRoute
51
56
  call_chain.map { |tp| tp[:parent_length] }.uniq.sort
52
57
  end
53
58
 
59
+ def deep_cloned
60
+ chain.map { |r| r.clone }
61
+ end
62
+
63
+ def stringify
64
+ deep_cloned.map do |tr|
65
+ # to_s is safer than inspect
66
+ # ex: inspect on ActiveRecord_Relation may crash
67
+ tr[:defined_class] = tr[:defined_class].to_s if tr.key?(:defined_class)
68
+ if tr.key?(:return_value)
69
+ if tr[:return_value].nil? or tr[:return_value] == ''
70
+ tr[:return_value] = tr[:return_value].inspect
71
+ else
72
+ tr[:return_value] = tr[:return_value].to_s
73
+ end
74
+ end
75
+ tr
76
+ end
77
+ end
78
+
54
79
  private
55
80
  def init_order_id_and_parent_ids
56
81
  each_with_index do |tpr, index|
@@ -1,3 +1,3 @@
1
1
  module SourceRoute
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -50,8 +50,12 @@ module SourceRoute
50
50
 
51
51
  result_config.show_additional_attrs = [:path, :lineno]
52
52
  # JSON serialize trigger many problems when handle complicated object
53
- # result_config.include_instance_var = true
54
- # result_config.include_local_var = true
53
+
54
+ # a Back Door to open more data. but be care it could trigger weird crash when Jsonify these vars
55
+ if value == 10
56
+ result_config.include_instance_var = true
57
+ result_config.include_local_var = true
58
+ end
55
59
  end
56
60
  end
57
61
 
@@ -87,40 +91,16 @@ module SourceRoute
87
91
  self.tp = track
88
92
  end
89
93
 
90
- # TODO: move this into chain self
91
- def stringify_tp_self_caches
92
- tp_self_caches.clone.map(&:to_s)
93
- end
94
-
95
- def stringify_tp_result_chain
96
- deep_cloned = tp_result_chain.map do |tp_result|
97
- tp_result.clone
98
- end
99
- deep_cloned.map do |tr|
100
- # to_s is safer than inspect
101
- # ex: inspect on ActiveRecord_Relation may crash
102
- tr[:defined_class] = tr[:defined_class].to_s if tr.key?(:defined_class)
103
- if tr.key?(:return_value)
104
- if tr[:return_value].nil? or tr[:return_value] == ''
105
- tr[:return_value] = tr[:return_value].inspect
106
- else
107
- tr[:return_value] = tr[:return_value].to_s
108
- end
109
- end
110
- tr
111
- end
112
- end
113
-
114
94
  def jsonify_events
115
95
  JSON.dump(@condition.events.map(&:to_s))
116
96
  end
117
97
 
118
98
  def jsonify_tp_result_chain
119
- JSON.dump(stringify_tp_result_chain)
99
+ JSON.dump(tp_result_chain.stringify)
120
100
  end
121
101
 
122
102
  def jsonify_tp_self_caches
123
- JSON.dump(stringify_tp_self_caches)
103
+ JSON.dump(tp_self_caches.clone.map(&:to_s))
124
104
  end
125
105
  end # END Wrapper
126
106
 
data/test/sample_app.rb CHANGED
@@ -26,7 +26,7 @@ class SampleApp
26
26
  def initialize
27
27
  @cool = ['test', 'data']
28
28
  # todo: cant display on html easily
29
- @cool_hash = {first: :run, second: :halt, third: :stop}
29
+ @cool_hash = {first: :run, second: :halt, third: {new: true, updated: false}}
30
30
  cool_in_init = 'init data in cool app'
31
31
 
32
32
  end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class SourceRoute::WrapperTest < Minitest::Test
4
+
5
+ def setup
6
+ @wrapper = SourceRoute::Wrapper.instance
7
+ end
8
+
9
+ end
@@ -118,7 +118,6 @@ class SourceRouteTest < Minitest::Test
118
118
  SampleApp.new.nonsense
119
119
  end
120
120
  assert_equal 1, @wrapper.tp_self_caches.size
121
- assert @wrapper.stringify_tp_self_caches.first.is_a? String
122
121
  assert @wrapper.tp_self_caches.first.is_a? SampleApp
123
122
  end
124
123
 
@@ -127,7 +126,7 @@ class SourceRouteTest < Minitest::Test
127
126
  SampleApp.new.nonsense
128
127
  end
129
128
  origin_tp_result_chain = @wrapper.tp_result_chain
130
- assert @wrapper.stringify_tp_result_chain.first[:defined_class].is_a? String
129
+ assert @wrapper.tp_result_chain.stringify.first[:defined_class].is_a? String
131
130
  assert_equal origin_tp_result_chain, @wrapper.tp_result_chain
132
131
  end
133
132
 
@@ -225,6 +224,9 @@ class SourceRouteTest < Minitest::Test
225
224
  event :call, :return
226
225
  result_config.include_instance_var = true
227
226
  result_config.include_local_var = true
227
+ result_config.show_additional_attrs = [:path, :lineno]
228
+ result_config.include_tp_self = true
229
+
228
230
  result_config.filename = 'call_and_return_in_sample_app.html'
229
231
  result_config.import_return_to_call = true
230
232
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: source_route
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - raykin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -136,9 +136,10 @@ files:
136
136
  - source_route.gemspec
137
137
  - test/fake_app.rb
138
138
  - test/sample_app.rb
139
+ - test/source_route/tp_filter_test.rb
140
+ - test/source_route/wrapper_test.rb
139
141
  - test/source_route_test.rb
140
142
  - test/test_helper.rb
141
- - test/tp_filter_test.rb
142
143
  homepage: http://github.com/raykin/source-route
143
144
  licenses:
144
145
  - MIT
@@ -166,7 +167,8 @@ summary: Wrapper of TracePoint.
166
167
  test_files:
167
168
  - test/fake_app.rb
168
169
  - test/sample_app.rb
170
+ - test/source_route/tp_filter_test.rb
171
+ - test/source_route/wrapper_test.rb
169
172
  - test/source_route_test.rb
170
173
  - test/test_helper.rb
171
- - test/tp_filter_test.rb
172
174
  has_rdoc: