rdepend 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3554b4b1d7f92ffb10ab23a4448d0ac688360dd9
4
- data.tar.gz: d7ce6651c48d344354ca76e17d90bc565ee96d22
3
+ metadata.gz: 5f7a2efdd9fdd2cc0310465cac7a761bb95e403e
4
+ data.tar.gz: 98dbb422eaa304892d3e6e867d3172b1f6273693
5
5
  SHA512:
6
- metadata.gz: 69a016abcc816a5acfb306a55d649559032e6857bfe54cce1edb9e4f4ed39573c335afa0743673e063d36ad591b73d0b7270d73790d0406e7922d75eb3661684
7
- data.tar.gz: 979f0ce215b0ea2b1f6a1ae8f29b8fc74fdf2ee9138e9b520fac8c811909bc2c754a1499eb50d56dfd02c3a3959477907f49791e28ac0db0151ca739ed81dd9e
6
+ metadata.gz: 60c1b739a32928b6ccb592fffcf98f67edc58e9c8b6930d0762b5f2cca81484d699bb37848b5a8b17870711550e1d1b0a3bba1a9dc47871cd6e1f874743edd76
7
+ data.tar.gz: 008ea25590dbffccaebbdf9105cf1737b8e5699030e8de43b8dfbceaa8b7089bd43ed5b7483341ae080a3865bb6dd45a36045736df620fa972c4291ad2302a8a
data/README.md CHANGED
@@ -4,9 +4,9 @@ Mind that this Gem is very experimental, a work in progress
4
4
 
5
5
  It generates a graph visualization of the dependencies in your codebase.
6
6
 
7
- A lot of incoming links are good, as that means that a function/module is
7
+ A lot of incoming links is good, as that means that a module is
8
8
  re-used a lot.
9
- A lot of outgoing links a bad, as that means that that part of the code has
9
+ A lot of outgoing links is bad, as that means that that part of the code has
10
10
  a lot of dependencies.
11
11
 
12
12
  See also http://www.whiteboxtest.com/information-flow-metrics.php
@@ -36,6 +36,8 @@ Rdepend.with_trace do
36
36
  end
37
37
  ```
38
38
 
39
+ or
40
+
39
41
  ```ruby
40
42
  Rdepend.trace
41
43
  @een = Een.new
@@ -1,71 +1,27 @@
1
1
  # encoding: utf-8
2
-
3
2
  require 'set'
4
3
 
5
4
  module Rdepend
6
- # Generates a graphviz graph in dot format.
7
- # To use the dot printer:
8
- #
9
- # result = RubyProf.profile do
10
- # [code to profile]
11
- # end
12
- #
13
- # printer = RubyProf::Printer.new(result)
14
- # printer.print(STDOUT)
15
- #
16
- # You can use either dot viewer such as GraphViz, or the dot command line tool
17
- # to reformat the output into a wide variety of outputs:
18
- #
19
- # dot -Tpng graph.dot > graph.png
20
- #
21
5
  class Printer < RubyProf::AbstractPrinter
22
6
  CLASS_COLOR = '"#666666"'
23
7
  EDGE_COLOR = '"#666666"'
24
8
 
25
- # Creates the Printer using a RubyProf::Result.
26
9
  def initialize(result)
27
10
  super(result)
28
11
  @seen_methods = Set.new
29
12
  end
30
13
 
31
- # Print a graph report to the provided output.
32
- #
33
- # output - Any IO object, including STDOUT or a file. The default value is
34
- # STDOUT.
35
- #
36
- # options - Hash of print options. See #setup_options
37
- # for more information.
38
- #
39
- # When profiling results that cover a large number of method calls it
40
- # helps to use the :min_percent option, for example:
41
- #
42
- # Printer.new(result).print(STDOUT, :min_percent=>5)
43
- #
44
- def print(output = STDOUT, options = {})
14
+ def print(output, options = {})
45
15
  setup_options(options)
46
- add('digraph "Profile" {')
47
- #add("label=\"#{mode_name} >=#{min_percent}%\\nTotal: #{total_time}\";"
48
- add("labelloc=t;")
49
- add("labeljust=l;")
16
+ add('digraph "Profile" {', 'labelloc=t;', 'labeljust=l;')
50
17
  print_threads
51
18
  add('}')
52
- if output == STDOUT
53
- @output = File.open(output, 'w')
54
- else
55
- File.open(output, 'w') { |file| file.write(@contents.join("\n")) }
56
- end
19
+ File.open(output, 'w') { |file| file.write(@contents.join("\n")) }
57
20
  `dot -Tsvg #{output} > #{output}.svg`
58
21
  end
59
22
 
60
23
  private
61
24
 
62
- # Something of a hack, figure out which constant went with the
63
- # RubyProf.measure_mode so that we can display it. Otherwise it's easy to
64
- # forget what measurement was made.
65
- def mode_name
66
- RubyProf.constants.find{|c| RubyProf.const_get(c) == RubyProf.measure_mode}
67
- end
68
-
69
25
  def print_threads
70
26
  @result.threads.each do |thread|
71
27
  add("subgraph \"Thread #{thread.id}\" {")
@@ -75,20 +31,12 @@ module Rdepend
75
31
  end
76
32
  end
77
33
 
78
- # Determines an ID to use to represent the subject in the Dot file.
79
- def dot_id(subject)
80
- subject.object_id
81
- end
82
-
83
34
  def print_thread(thread)
84
- total_time = thread.total_time
85
35
  thread.methods.sort_by(&sort_method).reverse_each do |method|
86
- total_percentage = (method.total_time/total_time) * 100
87
- next if total_percentage < min_percent
88
36
  name = method_name(method).split("#").last
89
- add("#{dot_id(method)} [label=\"#{name}\\n(#{total_percentage.round}%)\"];")
37
+ add("#{method.object_id} [label=\"#{name}\"];")
90
38
  @seen_methods << method
91
- print_edges(total_time, method)
39
+ print_edges(method)
92
40
  end
93
41
  end
94
42
 
@@ -96,34 +44,27 @@ module Rdepend
96
44
  grouped = {}
97
45
  thread.methods.each{|m| grouped[m.klass_name] ||= []; grouped[m.klass_name] << m}
98
46
  grouped.each do |cls, methods2|
99
- # Filter down to just seen methods
100
- big_methods = methods2.select{|m| @seen_methods.include? m}
47
+ big_methods = methods2.select { |m| @seen_methods.include?(m) }
101
48
  if !big_methods.empty?
102
49
  add("subgraph cluster_#{cls.object_id} {")
103
- add("label = \"#{cls}\";")
104
- add("fontcolor = #{CLASS_COLOR};")
105
- add("fontsize = 16;")
106
- add("color = #{CLASS_COLOR};")
107
- big_methods.each do |m|
108
- add("#{m.object_id};")
109
- end
50
+ add("label = \"#{cls}\";", "fontcolor = #{CLASS_COLOR};")
51
+ add("fontsize = 16;", "color = #{CLASS_COLOR};")
52
+ big_methods.each { |m| add("#{m.object_id};") }
110
53
  add("}")
111
54
  end
112
55
  end
113
56
  end
114
57
 
115
- def print_edges(total_time, method)
116
- method.aggregate_children.sort_by(&:total_time).reverse.each do |child|
117
- target_percentage = (child.target.total_time / total_time) * 100.0
118
- next if target_percentage < min_percent
119
- # Get children method
120
- add("#{dot_id(method)} -> #{dot_id(child.target)} [label=\"#{child.called}/#{child.target.called}\" fontsize=10 fontcolor=#{EDGE_COLOR}];")
58
+ def print_edges(method)
59
+ method.aggregate_children.each do |child|
60
+ label = "#{child.called}/#{child.target.called}"
61
+ label = "label=\"#{label}\" fontsize=10 fontcolor=#{EDGE_COLOR}"
62
+ add("#{method.object_id} -> #{child.target.object_id} [#{label}];")
121
63
  end
122
64
  end
123
65
 
124
- # Silly little helper for printing to the @output
125
- def add(str)
126
- (@contents ||= []) << str
66
+ def add(*args)
67
+ @contents = (@contents || []) + [args].flatten
127
68
  end
128
69
  end
129
70
  end
data/lib/rdepend/trace.rb CHANGED
@@ -1,11 +1,7 @@
1
- at_exit do
2
- Rdepend::Trace.halt_with_message
3
- end
4
-
5
1
  module Rdepend
6
2
  class Trace
7
3
  def self.exec(&block)
8
- self.start
4
+ self.init
9
5
  yield
10
6
  self.stop
11
7
  end
@@ -17,9 +13,8 @@ module Rdepend
17
13
  def self.stop
18
14
  result = RubyProf.stop
19
15
  result.eliminate_methods!([/Integer#times/])
20
- printer = Rdepend::Printer.new(result)
21
16
  puts "Writing Ꝛdepend graph to #{$0}.dot.svg"
22
- printer.print("#{$0}.dot")
17
+ Rdepend::Printer.new(result).print("#{$0}.dot")
23
18
  end
24
19
 
25
20
  def self.halt_with_message
@@ -28,3 +23,7 @@ module Rdepend
28
23
  end
29
24
  end
30
25
  end
26
+
27
+ at_exit do
28
+ Rdepend::Trace.halt_with_message
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Rdepend
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdepend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jarra
@@ -88,7 +88,6 @@ files:
88
88
  - lib/rdepend/main.rb
89
89
  - lib/rdepend/printer.rb
90
90
  - lib/rdepend/trace.rb
91
- - lib/rdepend/trace_event.rb
92
91
  - lib/rdepend/version.rb
93
92
  - rdepend.gemspec
94
93
  homepage: ''
@@ -1,54 +0,0 @@
1
- Rdepend::TraceEvent = Struct.new(:event_type, :defined_class,
2
- :method_id, :path, :lineno) do
3
- def event_class
4
- "Rdepend::Event::#{event_type.to_s.classify}".constantize
5
- end
6
-
7
- def key
8
- "#{path}:#{method_id}"
9
- end
10
-
11
- def root?
12
- method_id == '<main>'
13
- end
14
-
15
- def defined_class
16
- self[:defined_class].to_s
17
- end
18
-
19
- def instance?
20
- !klass?
21
- end
22
-
23
- def klass?
24
- defined_class =~ /^#<(Module|Class):\w*.*>$/
25
- end
26
-
27
- def klass
28
- name.klass
29
- end
30
-
31
- def method
32
- name.method
33
- end
34
-
35
- def label
36
- if root?
37
- 'main'
38
- else
39
- method_id
40
- end
41
- end
42
-
43
- private
44
-
45
- def name
46
- if root?
47
- Rdepend::Event::RootName.new(self)
48
- elsif instance?
49
- Rdepend::Event::InstanceName.new(self)
50
- else
51
- Rdepend::Event::KlassName.new(self)
52
- end
53
- end
54
- end