WasThreadStackProcessor 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +1,32 @@
1
-
2
-
3
- require 'threadStackCombinator'
4
- require 'threadStackExtractor'
5
- require 'threadStack'
6
-
7
- require 'rubygems'
8
- require 'hirb'
9
-
10
- class WasThreadStackProcessor
11
-
12
- attr_accessor :threadStackCombinator
13
-
14
- def initialize(threadStackCombinator)
15
- @threadStackCombinator = threadStackCombinator
16
- end
17
-
18
- def process(file)
19
- threadStackExtractor = ThreadStackExtractor.new(file)
20
- threadStacks = threadStackExtractor.getThreadStacks
21
-
22
- threadStacks.each { |threadStack| @threadStackCombinator.combine(ThreadStack.new(threadStack))}
23
- end
24
-
25
- def children_sorted
26
- threadStackCombinator.combinedThreadStacks.compact.sort { |a,b| b.count <=> a.count}
27
- end
28
-
29
- def text_count
30
- ""
31
- end
32
- end
1
+
2
+
3
+ require 'threadStackCombinator'
4
+ require 'threadStackExtractor'
5
+ require 'threadStack'
6
+
7
+ require 'rubygems'
8
+ require 'hirb'
9
+
10
+ class WasThreadStackProcessor
11
+
12
+ attr_accessor :threadStackCombinator
13
+
14
+ def initialize(threadStackCombinator)
15
+ @threadStackCombinator = threadStackCombinator
16
+ end
17
+
18
+ def process(file)
19
+ threadStackExtractor = ThreadStackExtractor.new(file)
20
+ threadStacks = threadStackExtractor.getThreadStacks
21
+
22
+ threadStacks.each { |threadStack| @threadStackCombinator.combine(ThreadStack.new(threadStack))}
23
+ end
24
+
25
+ def children_sorted
26
+ threadStackCombinator.combinedThreadStacks.compact.sort { |a,b| b.count <=> a.count}
27
+ end
28
+
29
+ def text_count
30
+ ""
31
+ end
32
+ end
@@ -1,68 +1,68 @@
1
- class ThreadStack
2
-
3
- class Call
4
- attr_accessor :text
5
- attr_accessor :count
6
- attr_accessor :children
7
-
8
- def initialize(text)
9
- @text = text
10
- @children = Array.new
11
- @count = 1
12
- end
13
-
14
- def merge(call)
15
- if call.nil?
16
- false
17
- elsif @text == call.text
18
- @count += 1
19
- @children.compact!
20
- if @children.count{ |x| x.merge(call.children[0])} == 0
21
- @children << call.children[0]
22
- end
23
- @children.compact!
24
- true
25
- else
26
- false
27
- end
28
- end
29
-
30
- def text_count
31
- "#{text} (#{count})"
32
- end
33
-
34
- def children_sorted
35
- children.compact.sort { |a,b| b.count <=> a.count}
36
- end
37
- end
38
-
39
- attr_reader :call
40
-
41
- def initialize(stack)
42
- previousCall = nil
43
- stack.each { |text|
44
- call = Call.new(text)
45
- if not previousCall.nil?
46
- call.children << previousCall
47
- end
48
- previousCall = call
49
- }
50
- @call = previousCall
51
- end
52
-
53
- def merge(threadStack)
54
- @call.merge(threadStack.call)
55
- end
56
-
57
- def children_sorted
58
- call.children_sorted
59
- end
60
-
61
- def count
62
- call.count
63
- end
64
-
65
- def text_count
66
- call.text_count
67
- end
68
- end
1
+ class ThreadStack
2
+
3
+ class Call
4
+ attr_accessor :text
5
+ attr_accessor :count
6
+ attr_accessor :children
7
+
8
+ def initialize(text)
9
+ @text = text
10
+ @children = Array.new
11
+ @count = 1
12
+ end
13
+
14
+ def merge(call)
15
+ if call.nil?
16
+ false
17
+ elsif @text == call.text
18
+ @count += 1
19
+ @children.compact!
20
+ if @children.count{ |x| x.merge(call.children[0])} == 0
21
+ @children << call.children[0]
22
+ end
23
+ @children.compact!
24
+ true
25
+ else
26
+ false
27
+ end
28
+ end
29
+
30
+ def text_count
31
+ "#{text} - (#{count})"
32
+ end
33
+
34
+ def children_sorted
35
+ children.compact.sort { |a,b| b.count <=> a.count}
36
+ end
37
+ end
38
+
39
+ attr_reader :call
40
+
41
+ def initialize(stack)
42
+ previousCall = nil
43
+ stack.each { |text|
44
+ call = Call.new(text.chomp)
45
+ if not previousCall.nil?
46
+ call.children << previousCall
47
+ end
48
+ previousCall = call
49
+ }
50
+ @call = previousCall
51
+ end
52
+
53
+ def merge(threadStack)
54
+ @call.merge(threadStack.call)
55
+ end
56
+
57
+ def children_sorted
58
+ call.children_sorted
59
+ end
60
+
61
+ def count
62
+ call.count
63
+ end
64
+
65
+ def text_count
66
+ call.text_count
67
+ end
68
+ end
@@ -1,11 +1,11 @@
1
- class ThreadStackCombinator
2
- attr_accessor :combinedThreadStacks
3
-
4
- def initialize
5
- @combinedThreadStacks = Array.new
6
- end
7
-
8
- def combine(threadStack)
9
- @combinedThreadStacks << threadStack unless @combinedThreadStacks.count { |combinedThreadStack| combinedThreadStack.merge(threadStack)} > 0
10
- end
1
+ class ThreadStackCombinator
2
+ attr_accessor :combinedThreadStacks
3
+
4
+ def initialize
5
+ @combinedThreadStacks = Array.new
6
+ end
7
+
8
+ def combine(threadStack)
9
+ @combinedThreadStacks << threadStack unless @combinedThreadStacks.count { |combinedThreadStack| combinedThreadStack.merge(threadStack)} > 0
10
+ end
11
11
  end
@@ -1,25 +1,25 @@
1
- class ThreadStackExtractor
2
-
3
- def initialize(file)
4
- @file = file
5
- end
6
-
7
- def getThreadStacks
8
- stacks = Array.new()
9
-
10
- stack = Array.new()
11
- while (line = @file.gets)
12
- encoded = line.encode('UTF-8', 'UTF-8', { :invalid => :replace })
13
- case encoded
14
- when /^3XMTHREADINFO\s*(.*)/ then
15
- stacks << stack unless stack.empty?
16
- stack = Array.new()
17
- when /^4XESTACKTRACE\s*(.*)/ then
18
- stack << $1
19
- end
20
- end
21
- stacks << stack unless stack.empty?
22
-
23
- return stacks
24
- end
25
- end
1
+ class ThreadStackExtractor
2
+
3
+ def initialize(file)
4
+ @file = file
5
+ end
6
+
7
+ def getThreadStacks
8
+ stacks = Array.new()
9
+
10
+ stack = Array.new()
11
+ while (line = @file.gets)
12
+ encoded = line.encode('UTF-8', 'UTF-8', { :invalid => :replace })
13
+ case encoded
14
+ when /^3XMTHREADINFO\s*(.*)/ then
15
+ stacks << stack unless stack.empty?
16
+ stack = Array.new()
17
+ when /^4XESTACKTRACE\s*(.*)/ then
18
+ stack << $1
19
+ end
20
+ end
21
+ stacks << stack unless stack.empty?
22
+
23
+ return stacks
24
+ end
25
+ end
@@ -1,42 +1,42 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'wasThreadStackProcessor'
3
- require 'threadStackExtractor'
4
- require 'threadStackCombinator'
5
-
6
- describe WasThreadStackProcessor do
7
-
8
- it "must extract the threads and combine it" do
9
- file = double("File")
10
- file.stub(:gets).and_return('3XMTHREADINFO "WebContainer : 425" (TID:0x000000000B48E100, sys_thread_t:0x000000000AA11040, state:R, native ID:0x000000000000146B) prio=5',
11
- '4XESTACKTRACE at com/ibm/io/async/AsyncLibrary.aio_getioev3(Native Method)',
12
- '4XESTACKTRACE at com/ibm/io/async/AsyncLibrary.getCompletionData3(AsyncLibrary.java:602(Compiled Code))',
13
- '4XESTACKTRACE at com/ibm/io/async/ResultHandler.runEventProcessingLoop(ResultHandler.java:287(Compiled Code))',
14
- '4XESTACKTRACE at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))',
15
- '4XESTACKTRACE at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1551(Compiled Code))',
16
- '3XMTHREADINFO "NotificationServiceDispatcher : 143" (TID:0x00002AAAD843EF00, sys_thread_t:0x000000000AA1D1C0, state:CW, native ID:0x0000000000000F76) prio=5',
17
- '4XESTACKTRACE at java/lang/Object.wait(Native Method)',
18
- '4XESTACKTRACE at java/lang/Object.wait(Object.java:231(Compiled Code))',
19
- '4XESTACKTRACE at com/ibm/ws/util/BoundedBuffer.waitGet_(BoundedBuffer.java:195(Compiled Code))',
20
- '4XESTACKTRACE at com/ibm/ws/util/BoundedBuffer.take(BoundedBuffer.java:564(Compiled Code))',
21
- '4XESTACKTRACE at com/ibm/ws/util/ThreadPool.getTask(ThreadPool.java:840(Compiled Code))',
22
- '4XESTACKTRACE at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1558(Compiled Code))',
23
- '3XMTHREADINFO "Java indexing" (TID:0x00002AAAE42C1800, sys_thread_t:0x00002AAAD89EF530, state:CW, native ID:0x0000000000000FA8) prio=4',
24
- '4XESTACKTRACE at java/lang/Object.wait(Native Method)',
25
- '4XESTACKTRACE at java/lang/Object.wait(Object.java:199(Compiled Code))',
26
- '4XESTACKTRACE at org/eclipse/jdt/internal/core/search/processing/JobManager.run(JobManager.java:350)',
27
- '4XESTACKTRACE at java/lang/Thread.run(Thread.java:811)',
28
- '3XMTHREADINFO "Worker-1" (TID:0x000000000B2C1C00, sys_thread_t:0x00000000088A5208, state:CW, native ID:0x0000000000000FAB) prio=5',
29
- '4XESTACKTRACE at java/lang/Object.wait(Native Method)',
30
- '4XESTACKTRACE at java/lang/Object.wait(Object.java:231(Compiled Code))',
31
- '4XESTACKTRACE at org/eclipse/core/internal/jobs/WorkerPool.sleep(WorkerPool.java:181(Compiled Code))',
32
- '4XESTACKTRACE at org/eclipse/core/internal/jobs/WorkerPool.startJob(WorkerPool.java:218(Compiled Code))',
33
- '4XESTACKTRACE at org/eclipse/core/internal/jobs/Worker.run(Worker.java:51)',
34
- nil)
35
- threadStackCombinator = double("ThreadStackCombinator")
36
- threadStackCombinator.should_receive(:combine).exactly(4).times
37
-
38
- wasThreadStackProcessor = WasThreadStackProcessor.new(threadStackCombinator)
39
-
40
- wasThreadStackProcessor.process(file)
41
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'wasThreadStackProcessor'
3
+ require 'threadStackExtractor'
4
+ require 'threadStackCombinator'
5
+
6
+ describe WasThreadStackProcessor do
7
+
8
+ it "must extract the threads and combine it" do
9
+ file = double("File")
10
+ file.stub(:gets).and_return('3XMTHREADINFO "WebContainer : 425" (TID:0x000000000B48E100, sys_thread_t:0x000000000AA11040, state:R, native ID:0x000000000000146B) prio=5',
11
+ '4XESTACKTRACE at com/ibm/io/async/AsyncLibrary.aio_getioev3(Native Method)',
12
+ '4XESTACKTRACE at com/ibm/io/async/AsyncLibrary.getCompletionData3(AsyncLibrary.java:602(Compiled Code))',
13
+ '4XESTACKTRACE at com/ibm/io/async/ResultHandler.runEventProcessingLoop(ResultHandler.java:287(Compiled Code))',
14
+ '4XESTACKTRACE at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))',
15
+ '4XESTACKTRACE at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1551(Compiled Code))',
16
+ '3XMTHREADINFO "NotificationServiceDispatcher : 143" (TID:0x00002AAAD843EF00, sys_thread_t:0x000000000AA1D1C0, state:CW, native ID:0x0000000000000F76) prio=5',
17
+ '4XESTACKTRACE at java/lang/Object.wait(Native Method)',
18
+ '4XESTACKTRACE at java/lang/Object.wait(Object.java:231(Compiled Code))',
19
+ '4XESTACKTRACE at com/ibm/ws/util/BoundedBuffer.waitGet_(BoundedBuffer.java:195(Compiled Code))',
20
+ '4XESTACKTRACE at com/ibm/ws/util/BoundedBuffer.take(BoundedBuffer.java:564(Compiled Code))',
21
+ '4XESTACKTRACE at com/ibm/ws/util/ThreadPool.getTask(ThreadPool.java:840(Compiled Code))',
22
+ '4XESTACKTRACE at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1558(Compiled Code))',
23
+ '3XMTHREADINFO "Java indexing" (TID:0x00002AAAE42C1800, sys_thread_t:0x00002AAAD89EF530, state:CW, native ID:0x0000000000000FA8) prio=4',
24
+ '4XESTACKTRACE at java/lang/Object.wait(Native Method)',
25
+ '4XESTACKTRACE at java/lang/Object.wait(Object.java:199(Compiled Code))',
26
+ '4XESTACKTRACE at org/eclipse/jdt/internal/core/search/processing/JobManager.run(JobManager.java:350)',
27
+ '4XESTACKTRACE at java/lang/Thread.run(Thread.java:811)',
28
+ '3XMTHREADINFO "Worker-1" (TID:0x000000000B2C1C00, sys_thread_t:0x00000000088A5208, state:CW, native ID:0x0000000000000FAB) prio=5',
29
+ '4XESTACKTRACE at java/lang/Object.wait(Native Method)',
30
+ '4XESTACKTRACE at java/lang/Object.wait(Object.java:231(Compiled Code))',
31
+ '4XESTACKTRACE at org/eclipse/core/internal/jobs/WorkerPool.sleep(WorkerPool.java:181(Compiled Code))',
32
+ '4XESTACKTRACE at org/eclipse/core/internal/jobs/WorkerPool.startJob(WorkerPool.java:218(Compiled Code))',
33
+ '4XESTACKTRACE at org/eclipse/core/internal/jobs/Worker.run(Worker.java:51)',
34
+ nil)
35
+ threadStackCombinator = double("ThreadStackCombinator")
36
+ threadStackCombinator.should_receive(:combine).exactly(4).times
37
+
38
+ wasThreadStackProcessor = WasThreadStackProcessor.new(threadStackCombinator)
39
+
40
+ wasThreadStackProcessor.process(file)
41
+ end
42
42
  end
@@ -1,12 +1,12 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'wasThreadStackProcessor'
5
-
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
-
12
- end
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'wasThreadStackProcessor'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -1,53 +1,53 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
- require 'threadStackCombinator'
3
-
4
- describe ThreadStackCombinator do
5
-
6
- before(:each) do
7
- @threadStackCombinator = ThreadStackCombinator.new
8
- end
9
-
10
- describe 'after creation' do
11
- it 'must contain no CombinedThreadStack' do
12
- @threadStackCombinator.combinedThreadStacks.size.should be 0
13
- end
14
- end
15
-
16
- describe 'after combine' do
17
- before(:each) do
18
- @threadStack = ThreadStack.new(['at com/ibm/io/async/AsyncLibrary.aio_getioev3(Native Method)',
19
- 'at com/ibm/io/async/AsyncLibrary.getCompletionData3(AsyncLibrary.java:602(Compiled Code))',
20
- 'at com/ibm/io/async/ResultHandler.runEventProcessingLoop(ResultHandler.java:287(Compiled Code))',
21
- 'at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))',
22
- 'at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1551(Compiled Code))'])
23
-
24
- @threadStack2 = ThreadStack.new(['at java/lang/Object.wait(Native Method)',
25
- 'at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))',
26
- 'at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1551(Compiled Code))'])
27
-
28
- @threadStack3 = ThreadStack.new(['at java/lang/Object.wait(Native Method)',
29
- 'at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))'])
30
- end
31
-
32
- it 'one threadStack must contain one threadStack' do
33
- @threadStackCombinator.combine(@threadStack)
34
-
35
- @threadStackCombinator.combinedThreadStacks.size.should be 1
36
-
37
- end
38
-
39
- it 'two threadStacks with common accesor must contain on threadStack' do
40
- @threadStackCombinator.combine(@threadStack)
41
- @threadStackCombinator.combine(@threadStack2)
42
-
43
- @threadStackCombinator.combinedThreadStacks.size.should be 1
44
- end
45
-
46
- it 'two threadStacks with no common accesor must contain on threadStack' do
47
- @threadStackCombinator.combine(@threadStack)
48
- @threadStackCombinator.combine(@threadStack3)
49
-
50
- @threadStackCombinator.combinedThreadStacks.size.should be 2
51
- end
52
- end
53
- end
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'threadStackCombinator'
3
+
4
+ describe ThreadStackCombinator do
5
+
6
+ before(:each) do
7
+ @threadStackCombinator = ThreadStackCombinator.new
8
+ end
9
+
10
+ describe 'after creation' do
11
+ it 'must contain no CombinedThreadStack' do
12
+ @threadStackCombinator.combinedThreadStacks.size.should be 0
13
+ end
14
+ end
15
+
16
+ describe 'after combine' do
17
+ before(:each) do
18
+ @threadStack = ThreadStack.new(['at com/ibm/io/async/AsyncLibrary.aio_getioev3(Native Method)',
19
+ 'at com/ibm/io/async/AsyncLibrary.getCompletionData3(AsyncLibrary.java:602(Compiled Code))',
20
+ 'at com/ibm/io/async/ResultHandler.runEventProcessingLoop(ResultHandler.java:287(Compiled Code))',
21
+ 'at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))',
22
+ 'at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1551(Compiled Code))'])
23
+
24
+ @threadStack2 = ThreadStack.new(['at java/lang/Object.wait(Native Method)',
25
+ 'at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))',
26
+ 'at com/ibm/ws/util/ThreadPool$Worker.run(ThreadPool.java:1551(Compiled Code))'])
27
+
28
+ @threadStack3 = ThreadStack.new(['at java/lang/Object.wait(Native Method)',
29
+ 'at com/ibm/io/async/ResultHandler$2.run(ResultHandler.java:881(Compiled Code))'])
30
+ end
31
+
32
+ it 'one threadStack must contain one threadStack' do
33
+ @threadStackCombinator.combine(@threadStack)
34
+
35
+ @threadStackCombinator.combinedThreadStacks.size.should be 1
36
+
37
+ end
38
+
39
+ it 'two threadStacks with common accesor must contain on threadStack' do
40
+ @threadStackCombinator.combine(@threadStack)
41
+ @threadStackCombinator.combine(@threadStack2)
42
+
43
+ @threadStackCombinator.combinedThreadStacks.size.should be 1
44
+ end
45
+
46
+ it 'two threadStacks with no common accesor must contain on threadStack' do
47
+ @threadStackCombinator.combine(@threadStack)
48
+ @threadStackCombinator.combine(@threadStack3)
49
+
50
+ @threadStackCombinator.combinedThreadStacks.size.should be 2
51
+ end
52
+ end
53
+ end