ruby_prof-json 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby_prof-json.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "ruby-debug", :platforms => [:ruby_18]
8
+ gem "ruby-debug19", :platforms => [:ruby_19], :require => "ruby-debug"
9
+ gem "awesome_print"
10
+ end
data/README.textile ADDED
@@ -0,0 +1,17 @@
1
+ h1. RubyProf/JSON
2
+
3
+ This is a small project that adds a JSON printer to RubyProf to enable easy processing and querying of profiled sessions. Note that the JSON schema may change.
4
+
5
+ h2. Usage
6
+
7
+ For now (at least), usage is limited to scripts that directly call RubyProf's API (and not the `ruby_prof` script—I can't see an easy way to register a new formatter without directly manipulating the script).
8
+
9
+ <pre><code>
10
+ # Assuming `result` is a RubyProf::Result
11
+ printer = RubyProf::JsonPrinter.new(result)
12
+ printer.print(output)
13
+ </code></pre>
14
+
15
+ h2. Example
16
+
17
+ See the prime number example.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ # require "bundler/gem_tasks"
@@ -0,0 +1,595 @@
1
+ {
2
+ "threads": [
3
+ {
4
+ "methods": [
5
+ {
6
+ "total_time": 0.382603,
7
+ "class": "JsonPrinterTest",
8
+ "source_file": "test/json_printer_test.rb",
9
+ "method": "setup",
10
+ "called": 1,
11
+ "parents": [
12
+
13
+ ],
14
+ "self_time": 2.1e-05,
15
+ "line": 15,
16
+ "children": [
17
+ {
18
+ "total_time": 0.193215,
19
+ "class": "Object",
20
+ "source_file": "./test/prime.rb",
21
+ "method": "run_primes",
22
+ "called": 1,
23
+ "self_time": 6.0e-06,
24
+ "line": 46,
25
+ "wait_time": 0.0
26
+ },
27
+ {
28
+ "total_time": 0.189367,
29
+ "class": "JsonPrinterTest",
30
+ "source_file": "test/json_printer_test.rb",
31
+ "method": "go",
32
+ "called": 1,
33
+ "self_time": 1.0e-05,
34
+ "line": 7,
35
+ "wait_time": 0.0
36
+ }
37
+ ],
38
+ "wait_time": 0.0
39
+ },
40
+ {
41
+ "total_time": 0.382572,
42
+ "class": "Object",
43
+ "source_file": "./test/prime.rb",
44
+ "method": "run_primes",
45
+ "called": 2,
46
+ "parents": [
47
+ {
48
+ "total_time": 0.189357,
49
+ "class": "JsonPrinterTest",
50
+ "source_file": "test/json_printer_test.rb",
51
+ "method": "go",
52
+ "called": 1,
53
+ "self_time": 6.0e-06,
54
+ "line": 7,
55
+ "wait_time": 0.0
56
+ },
57
+ {
58
+ "total_time": 0.193215,
59
+ "class": "JsonPrinterTest",
60
+ "source_file": "test/json_printer_test.rb",
61
+ "method": "setup",
62
+ "called": 1,
63
+ "self_time": 6.0e-06,
64
+ "line": 15,
65
+ "wait_time": 0.0
66
+ }
67
+ ],
68
+ "self_time": 1.2e-05,
69
+ "line": 46,
70
+ "children": [
71
+ {
72
+ "total_time": 0.380085,
73
+ "class": "Object",
74
+ "source_file": "./test/prime.rb",
75
+ "method": "find_primes",
76
+ "called": 2,
77
+ "self_time": 7.0e-06,
78
+ "line": 24,
79
+ "wait_time": 0.0
80
+ },
81
+ {
82
+ "total_time": 0.002475,
83
+ "class": "Object",
84
+ "source_file": "./test/prime.rb",
85
+ "method": "make_random_array",
86
+ "called": 2,
87
+ "self_time": 1.1e-05,
88
+ "line": 7,
89
+ "wait_time": 0.0
90
+ }
91
+ ],
92
+ "wait_time": 0.0
93
+ },
94
+ {
95
+ "total_time": 0.380085,
96
+ "class": "Object",
97
+ "source_file": "./test/prime.rb",
98
+ "method": "find_primes",
99
+ "called": 2,
100
+ "parents": [
101
+ {
102
+ "total_time": 0.380085,
103
+ "class": "Object",
104
+ "source_file": "./test/prime.rb",
105
+ "method": "run_primes",
106
+ "called": 2,
107
+ "self_time": 7.0e-06,
108
+ "line": 46,
109
+ "wait_time": 0.0
110
+ }
111
+ ],
112
+ "self_time": 7.0e-06,
113
+ "line": 24,
114
+ "children": [
115
+ {
116
+ "total_time": 0.380078,
117
+ "class": "Array",
118
+ "source_file": "ruby_runtime",
119
+ "method": "select",
120
+ "called": 2,
121
+ "self_time": 0.001538,
122
+ "line": 0,
123
+ "wait_time": 0.0
124
+ }
125
+ ],
126
+ "wait_time": 0.0
127
+ },
128
+ {
129
+ "total_time": 0.380078,
130
+ "class": "Array",
131
+ "source_file": "ruby_runtime",
132
+ "method": "select",
133
+ "called": 2,
134
+ "parents": [
135
+ {
136
+ "total_time": 0.380078,
137
+ "class": "Object",
138
+ "source_file": "./test/prime.rb",
139
+ "method": "find_primes",
140
+ "called": 2,
141
+ "self_time": 0.001538,
142
+ "line": 24,
143
+ "wait_time": 0.0
144
+ }
145
+ ],
146
+ "self_time": 0.001538,
147
+ "line": 0,
148
+ "children": [
149
+ {
150
+ "total_time": 0.37854,
151
+ "class": "Object",
152
+ "source_file": "./test/prime.rb",
153
+ "method": "is_prime",
154
+ "called": 2000,
155
+ "self_time": 0.002603,
156
+ "line": 16,
157
+ "wait_time": 0.0
158
+ }
159
+ ],
160
+ "wait_time": 0.0
161
+ },
162
+ {
163
+ "total_time": 0.37854,
164
+ "class": "Object",
165
+ "source_file": "./test/prime.rb",
166
+ "method": "is_prime",
167
+ "called": 2000,
168
+ "parents": [
169
+ {
170
+ "total_time": 0.37854,
171
+ "class": "Array",
172
+ "source_file": "ruby_runtime",
173
+ "method": "select",
174
+ "called": 2000,
175
+ "self_time": 0.002603,
176
+ "line": 0,
177
+ "wait_time": 0.0
178
+ }
179
+ ],
180
+ "self_time": 0.002603,
181
+ "line": 16,
182
+ "children": [
183
+ {
184
+ "total_time": 0.375493,
185
+ "class": "Integer",
186
+ "source_file": "ruby_runtime",
187
+ "method": "upto",
188
+ "called": 2000,
189
+ "self_time": 0.292475,
190
+ "line": 0,
191
+ "wait_time": 0.0
192
+ },
193
+ {
194
+ "total_time": 0.000444,
195
+ "class": "Fixnum",
196
+ "source_file": "ruby_runtime",
197
+ "method": "-",
198
+ "called": 2000,
199
+ "self_time": 0.000444,
200
+ "line": 0,
201
+ "wait_time": 0.0
202
+ }
203
+ ],
204
+ "wait_time": 0.0
205
+ },
206
+ {
207
+ "total_time": 0.375493,
208
+ "class": "Integer",
209
+ "source_file": "ruby_runtime",
210
+ "method": "upto",
211
+ "called": 2000,
212
+ "parents": [
213
+ {
214
+ "total_time": 0.375493,
215
+ "class": "Object",
216
+ "source_file": "./test/prime.rb",
217
+ "method": "is_prime",
218
+ "called": 2000,
219
+ "self_time": 0.292475,
220
+ "line": 16,
221
+ "wait_time": 0.0
222
+ }
223
+ ],
224
+ "self_time": 0.292475,
225
+ "line": 0,
226
+ "children": [
227
+ {
228
+ "total_time": 0.051727,
229
+ "class": "Fixnum",
230
+ "source_file": "ruby_runtime",
231
+ "method": "%",
232
+ "called": 155239,
233
+ "self_time": 0.051727,
234
+ "line": 0,
235
+ "wait_time": 0.0
236
+ },
237
+ {
238
+ "total_time": 0.031291,
239
+ "class": "Fixnum",
240
+ "source_file": "ruby_runtime",
241
+ "method": "==",
242
+ "called": 155239,
243
+ "self_time": 0.031291,
244
+ "line": 0,
245
+ "wait_time": 0.0
246
+ }
247
+ ],
248
+ "wait_time": 0.0
249
+ },
250
+ {
251
+ "total_time": 0.189367,
252
+ "class": "JsonPrinterTest",
253
+ "source_file": "test/json_printer_test.rb",
254
+ "method": "go",
255
+ "called": 1,
256
+ "parents": [
257
+ {
258
+ "total_time": 0.189367,
259
+ "class": "JsonPrinterTest",
260
+ "source_file": "test/json_printer_test.rb",
261
+ "method": "setup",
262
+ "called": 1,
263
+ "self_time": 1.0e-05,
264
+ "line": 15,
265
+ "wait_time": 0.0
266
+ }
267
+ ],
268
+ "self_time": 1.0e-05,
269
+ "line": 7,
270
+ "children": [
271
+ {
272
+ "total_time": 0.189357,
273
+ "class": "Object",
274
+ "source_file": "./test/prime.rb",
275
+ "method": "run_primes",
276
+ "called": 1,
277
+ "self_time": 6.0e-06,
278
+ "line": 46,
279
+ "wait_time": 0.0
280
+ }
281
+ ],
282
+ "wait_time": 0.0
283
+ },
284
+ {
285
+ "total_time": 0.051727,
286
+ "class": "Fixnum",
287
+ "source_file": "ruby_runtime",
288
+ "method": "%",
289
+ "called": 155239,
290
+ "parents": [
291
+ {
292
+ "total_time": 0.051727,
293
+ "class": "Integer",
294
+ "source_file": "ruby_runtime",
295
+ "method": "upto",
296
+ "called": 155239,
297
+ "self_time": 0.051727,
298
+ "line": 0,
299
+ "wait_time": 0.0
300
+ }
301
+ ],
302
+ "self_time": 0.051727,
303
+ "line": 0,
304
+ "children": [
305
+
306
+ ],
307
+ "wait_time": 0.0
308
+ },
309
+ {
310
+ "total_time": 0.031291,
311
+ "class": "Fixnum",
312
+ "source_file": "ruby_runtime",
313
+ "method": "==",
314
+ "called": 155239,
315
+ "parents": [
316
+ {
317
+ "total_time": 0.031291,
318
+ "class": "Integer",
319
+ "source_file": "ruby_runtime",
320
+ "method": "upto",
321
+ "called": 155239,
322
+ "self_time": 0.031291,
323
+ "line": 0,
324
+ "wait_time": 0.0
325
+ }
326
+ ],
327
+ "self_time": 0.031291,
328
+ "line": 0,
329
+ "children": [
330
+
331
+ ],
332
+ "wait_time": 0.0
333
+ },
334
+ {
335
+ "total_time": 0.002475,
336
+ "class": "Object",
337
+ "source_file": "./test/prime.rb",
338
+ "method": "make_random_array",
339
+ "called": 2,
340
+ "parents": [
341
+ {
342
+ "total_time": 0.002475,
343
+ "class": "Object",
344
+ "source_file": "./test/prime.rb",
345
+ "method": "run_primes",
346
+ "called": 2,
347
+ "self_time": 1.1e-05,
348
+ "line": 46,
349
+ "wait_time": 0.0
350
+ }
351
+ ],
352
+ "self_time": 1.1e-05,
353
+ "line": 7,
354
+ "children": [
355
+ {
356
+ "total_time": 0.002442,
357
+ "class": "Array",
358
+ "source_file": "ruby_runtime",
359
+ "method": "each_index",
360
+ "called": 2,
361
+ "self_time": 0.001495,
362
+ "line": 0,
363
+ "wait_time": 0.0
364
+ },
365
+ {
366
+ "total_time": 2.2e-05,
367
+ "class": "Class",
368
+ "source_file": "ruby_runtime",
369
+ "method": "new",
370
+ "called": 2,
371
+ "self_time": 6.0e-06,
372
+ "line": 0,
373
+ "wait_time": 0.0
374
+ }
375
+ ],
376
+ "wait_time": 0.0
377
+ },
378
+ {
379
+ "total_time": 0.002442,
380
+ "class": "Array",
381
+ "source_file": "ruby_runtime",
382
+ "method": "each_index",
383
+ "called": 2,
384
+ "parents": [
385
+ {
386
+ "total_time": 0.002442,
387
+ "class": "Object",
388
+ "source_file": "./test/prime.rb",
389
+ "method": "make_random_array",
390
+ "called": 2,
391
+ "self_time": 0.001495,
392
+ "line": 7,
393
+ "wait_time": 0.0
394
+ }
395
+ ],
396
+ "self_time": 0.001495,
397
+ "line": 0,
398
+ "children": [
399
+ {
400
+ "total_time": 0.000524,
401
+ "class": "Kernel",
402
+ "source_file": "ruby_runtime",
403
+ "method": "rand",
404
+ "called": 2000,
405
+ "self_time": 0.000524,
406
+ "line": 0,
407
+ "wait_time": 0.0
408
+ },
409
+ {
410
+ "total_time": 0.000423,
411
+ "class": "Array",
412
+ "source_file": "ruby_runtime",
413
+ "method": "[]=",
414
+ "called": 2000,
415
+ "self_time": 0.000423,
416
+ "line": 0,
417
+ "wait_time": 0.0
418
+ }
419
+ ],
420
+ "wait_time": 0.0
421
+ },
422
+ {
423
+ "total_time": 0.000524,
424
+ "class": "Kernel",
425
+ "source_file": "ruby_runtime",
426
+ "method": "rand",
427
+ "called": 2000,
428
+ "parents": [
429
+ {
430
+ "total_time": 0.000524,
431
+ "class": "Array",
432
+ "source_file": "ruby_runtime",
433
+ "method": "each_index",
434
+ "called": 2000,
435
+ "self_time": 0.000524,
436
+ "line": 0,
437
+ "wait_time": 0.0
438
+ }
439
+ ],
440
+ "self_time": 0.000524,
441
+ "line": 0,
442
+ "children": [
443
+
444
+ ],
445
+ "wait_time": 0.0
446
+ },
447
+ {
448
+ "total_time": 0.000444,
449
+ "class": "Fixnum",
450
+ "source_file": "ruby_runtime",
451
+ "method": "-",
452
+ "called": 2000,
453
+ "parents": [
454
+ {
455
+ "total_time": 0.000444,
456
+ "class": "Object",
457
+ "source_file": "./test/prime.rb",
458
+ "method": "is_prime",
459
+ "called": 2000,
460
+ "self_time": 0.000444,
461
+ "line": 16,
462
+ "wait_time": 0.0
463
+ }
464
+ ],
465
+ "self_time": 0.000444,
466
+ "line": 0,
467
+ "children": [
468
+
469
+ ],
470
+ "wait_time": 0.0
471
+ },
472
+ {
473
+ "total_time": 0.000423,
474
+ "class": "Array",
475
+ "source_file": "ruby_runtime",
476
+ "method": "[]=",
477
+ "called": 2000,
478
+ "parents": [
479
+ {
480
+ "total_time": 0.000423,
481
+ "class": "Array",
482
+ "source_file": "ruby_runtime",
483
+ "method": "each_index",
484
+ "called": 2000,
485
+ "self_time": 0.000423,
486
+ "line": 0,
487
+ "wait_time": 0.0
488
+ }
489
+ ],
490
+ "self_time": 0.000423,
491
+ "line": 0,
492
+ "children": [
493
+
494
+ ],
495
+ "wait_time": 0.0
496
+ },
497
+ {
498
+ "total_time": 2.2e-05,
499
+ "class": "Class",
500
+ "source_file": "ruby_runtime",
501
+ "method": "new",
502
+ "called": 2,
503
+ "parents": [
504
+ {
505
+ "total_time": 2.2e-05,
506
+ "class": "Object",
507
+ "source_file": "./test/prime.rb",
508
+ "method": "make_random_array",
509
+ "called": 2,
510
+ "self_time": 6.0e-06,
511
+ "line": 7,
512
+ "wait_time": 0.0
513
+ }
514
+ ],
515
+ "self_time": 6.0e-06,
516
+ "line": 0,
517
+ "children": [
518
+ {
519
+ "total_time": 1.2e-05,
520
+ "class": "Array",
521
+ "source_file": "ruby_runtime",
522
+ "method": "initialize",
523
+ "called": 2,
524
+ "self_time": 1.2e-05,
525
+ "line": 0,
526
+ "wait_time": 0.0
527
+ },
528
+ {
529
+ "total_time": 4.0e-06,
530
+ "class": "<Class::Array>",
531
+ "source_file": "ruby_runtime",
532
+ "method": "allocate",
533
+ "called": 2,
534
+ "self_time": 4.0e-06,
535
+ "line": 0,
536
+ "wait_time": 0.0
537
+ }
538
+ ],
539
+ "wait_time": 0.0
540
+ },
541
+ {
542
+ "total_time": 1.2e-05,
543
+ "class": "Array",
544
+ "source_file": "ruby_runtime",
545
+ "method": "initialize",
546
+ "called": 2,
547
+ "parents": [
548
+ {
549
+ "total_time": 1.2e-05,
550
+ "class": "Class",
551
+ "source_file": "ruby_runtime",
552
+ "method": "new",
553
+ "called": 2,
554
+ "self_time": 1.2e-05,
555
+ "line": 0,
556
+ "wait_time": 0.0
557
+ }
558
+ ],
559
+ "self_time": 1.2e-05,
560
+ "line": 0,
561
+ "children": [
562
+
563
+ ],
564
+ "wait_time": 0.0
565
+ },
566
+ {
567
+ "total_time": 4.0e-06,
568
+ "class": "<Class::Array>",
569
+ "source_file": "ruby_runtime",
570
+ "method": "allocate",
571
+ "called": 2,
572
+ "parents": [
573
+ {
574
+ "total_time": 4.0e-06,
575
+ "class": "Class",
576
+ "source_file": "ruby_runtime",
577
+ "method": "new",
578
+ "called": 2,
579
+ "self_time": 4.0e-06,
580
+ "line": 0,
581
+ "wait_time": 0.0
582
+ }
583
+ ],
584
+ "self_time": 4.0e-06,
585
+ "line": 0,
586
+ "children": [
587
+
588
+ ],
589
+ "wait_time": 0.0
590
+ }
591
+ ],
592
+ "thread_id": 2148446640
593
+ }
594
+ ]
595
+ }
@@ -0,0 +1,58 @@
1
+ require "ruby-prof"
2
+ require 'json/pure'
3
+
4
+ module RubyProf
5
+ class JsonPrinter < AbstractPrinter
6
+ attr_reader :threads
7
+ def initialize(result)
8
+ super(result)
9
+ @threads = {
10
+ :overall_time => 0, # TODO
11
+ :threads => result.threads.keys.map {|thread_id| thread_info(thread_id) }
12
+ }
13
+ end
14
+
15
+ def print(output = STDOUT, options = {})
16
+ output.puts JSON.pretty_generate(@threads)
17
+ end
18
+
19
+ private
20
+ def thread_info(thread_id)
21
+ {
22
+ :thread_id => thread_id,
23
+ :methods => @result.threads[thread_id].sort.reverse.map {|method| method_info(method) }
24
+ }
25
+ end
26
+
27
+ def method_info(method)
28
+ time_info(method).merge(
29
+ location_info(method)
30
+ ).merge(
31
+ :parents => method.aggregate_parents.find_all {|caller| caller.parent}.sort_by(&:total_time).map {|caller|
32
+ time_info(caller).merge(location_info(caller.parent.target))
33
+ },
34
+ :children => method.aggregate_children.sort_by(&:total_time).reverse.map {|child|
35
+ time_info(child).merge(location_info(child.target))
36
+ }
37
+ )
38
+ end
39
+
40
+ def time_info(method_or_call)
41
+ {
42
+ :called => method_or_call.called,
43
+ :self_time => method_or_call.self_time,
44
+ :total_time => method_or_call.total_time,
45
+ :wait_time => method_or_call.wait_time
46
+ }
47
+ end
48
+
49
+ def location_info(method)
50
+ {
51
+ :class => method.klass_name,
52
+ :method => method.method_name,
53
+ :source_file => method.source_file,
54
+ :line => method.line
55
+ }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Rubyprof
2
+ module Json
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "ruby_prof-json/version"
2
+
3
+ require "ruby-prof/json_printer"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby_prof-json/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby_prof-json"
7
+ s.version = Rubyprof::Json::VERSION
8
+ s.authors = ["Andrew O'Brien"]
9
+ s.email = ["obrien.andrew@gmail.com"]
10
+ s.homepage = "http://github.com/AndrewO/ruby_prof-json"
11
+ s.summary = %q{Outputs ruby-prof results as JSON.}
12
+ s.description = %q{If you need to process results from a profiling session, JSON is a good place to start.}
13
+
14
+ s.rubyforge_project = "ruby_prof-json"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "json_pure"
24
+ s.add_runtime_dependency "ruby-prof"
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+ require 'ruby-debug'
3
+ require 'ruby-prof/json_printer'
4
+ require File.dirname(__FILE__) + '/prime'
5
+
6
+ class JsonPrinterTest < Test::Unit::TestCase
7
+ def go
8
+ run_primes(1000)
9
+ end
10
+
11
+ def setup
12
+ RubyProf::measure_mode = RubyProf::WALL_TIME # WALL_TIME so we can use sleep in our test and get same measurements on linux and doze
13
+
14
+ @result = RubyProf.profile do
15
+ begin
16
+ run_primes(1000)
17
+ go
18
+ rescue => e
19
+ p e
20
+ end
21
+ end
22
+ end
23
+
24
+ def test_json_string
25
+ assert_nothing_raised do
26
+ output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : StringIO.new('')
27
+
28
+ printer = RubyProf::JsonPrinter.new(@result)
29
+ printer.print(output)
30
+ end
31
+ end
32
+ end
data/test/prime.rb ADDED
@@ -0,0 +1,55 @@
1
+ # A silly little test program that finds prime numbers. It
2
+ # is intentionally badly designed to show off the use
3
+ # of ruby-prof.
4
+ #
5
+ # Source from http://people.cs.uchicago.edu/~bomb154/154/maclabs/profilers-lab/
6
+
7
+ def make_random_array(length, maxnum)
8
+ result = Array.new(length)
9
+ result.each_index do |i|
10
+ result[i] = rand(maxnum)
11
+ end
12
+
13
+ result
14
+ end
15
+
16
+ def is_prime(x)
17
+ y = 2
18
+ y.upto(x-1) do |i|
19
+ return false if (x % i) == 0
20
+ end
21
+ true
22
+ end
23
+
24
+ def find_primes(arr)
25
+ result = arr.select do |value|
26
+ is_prime(value)
27
+ end
28
+ result
29
+ end
30
+
31
+ def find_largest(primes)
32
+ largest = primes.first
33
+
34
+ # Intentionally use upto for example purposes
35
+ # (upto is also called from is_prime)
36
+ 0.upto(primes.length-1) do |i|
37
+ sleep(0.02)
38
+ prime = primes[i]
39
+ if prime > largest
40
+ largest = prime
41
+ end
42
+ end
43
+ largest
44
+ end
45
+
46
+ def run_primes(length=10, maxnum=1000)
47
+ # Create random numbers
48
+ random_array = make_random_array(length, maxnum)
49
+
50
+ # Find the primes
51
+ primes = find_primes(random_array)
52
+
53
+ # Find the largest primes
54
+ # largest = find_largest(primes)
55
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_prof-json
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andrew O'Brien
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-15 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json_pure
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: ruby-prof
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: If you need to process results from a profiling session, JSON is a good place to start.
50
+ email:
51
+ - obrien.andrew@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - README.textile
62
+ - Rakefile
63
+ - examples/prime.json
64
+ - lib/ruby-prof/json_printer.rb
65
+ - lib/ruby_prof-json.rb
66
+ - lib/ruby_prof-json/version.rb
67
+ - ruby_prof-json.gemspec
68
+ - test/json_printer_test.rb
69
+ - test/prime.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/AndrewO/ruby_prof-json
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project: ruby_prof-json
100
+ rubygems_version: 1.3.9.2
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Outputs ruby-prof results as JSON.
104
+ test_files:
105
+ - test/json_printer_test.rb
106
+ - test/prime.rb