test-prof 0.1.0.beta1 → 0.1.0.pre5

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +69 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +4 -0
  7. data/README.md +2 -6
  8. data/Rakefile +8 -0
  9. data/bin/setup +8 -0
  10. data/circle.yml +11 -0
  11. data/guides/any_fixture.md +1 -1
  12. data/guides/stack_prof.md +1 -1
  13. data/lib/test_prof/factory_doctor.rb +9 -11
  14. data/lib/test_prof/ruby_prof.rb +5 -2
  15. data/lib/test_prof/stack_prof.rb +5 -2
  16. data/lib/test_prof/version.rb +1 -1
  17. data/lib/test_prof.rb +1 -19
  18. data/spec/integrations/any_fixture_spec.rb +11 -0
  19. data/spec/integrations/before_all_spec.rb +11 -0
  20. data/spec/integrations/event_prof_spec.rb +100 -0
  21. data/spec/integrations/factory_doctor_spec.rb +20 -0
  22. data/spec/integrations/fixtures/rspec/any_fixture_fixture.rb +37 -0
  23. data/spec/integrations/fixtures/rspec/before_all_fixture.rb +32 -0
  24. data/spec/integrations/fixtures/rspec/event_prof_factory_create_fixture.rb +23 -0
  25. data/spec/integrations/fixtures/rspec/event_prof_fixture.rb +51 -0
  26. data/spec/integrations/fixtures/rspec/event_prof_sidekiq_fixture.rb +53 -0
  27. data/spec/integrations/fixtures/rspec/factory_doctor_fixture.rb +33 -0
  28. data/spec/integrations/fixtures/rspec/rspec_stamp_fixture_tmpl.rb +33 -0
  29. data/spec/integrations/rspec_stamp_spec.rb +53 -0
  30. data/spec/spec_helper.rb +38 -0
  31. data/spec/support/ar_models.rb +43 -0
  32. data/spec/support/instrumenter_stub.rb +19 -0
  33. data/spec/support/integration_helpers.rb +13 -0
  34. data/spec/support/transactional_context.rb +11 -0
  35. data/spec/test_prof/any_fixture_spec.rb +66 -0
  36. data/spec/test_prof/event_prof_spec.rb +138 -0
  37. data/spec/test_prof/ext/float_duration_spec.rb +12 -0
  38. data/spec/test_prof/factory_doctor_spec.rb +84 -0
  39. data/spec/test_prof/rspec_stamp/parser_spec.rb +58 -0
  40. data/spec/test_prof/rspec_stamp_spec.rb +281 -0
  41. data/spec/test_prof/ruby_prof_spec.rb +109 -0
  42. data/spec/test_prof/stack_prof_spec.rb +73 -0
  43. data/spec/test_prof_spec.rb +23 -0
  44. data/test-prof.gemspec +35 -0
  45. metadata +38 -21
  46. data/CHANGELOG.md +0 -7
  47. data/assets/flamegraph.demo.html +0 -173
  48. data/assets/flamegraph.template.html +0 -196
  49. data/assets/src/d3-tip.js +0 -352
  50. data/assets/src/d3-tip.min.js +0 -1
  51. data/assets/src/d3.flameGraph.css +0 -92
  52. data/assets/src/d3.flameGraph.js +0 -459
  53. data/assets/src/d3.flameGraph.min.css +0 -1
  54. data/assets/src/d3.flameGraph.min.js +0 -1
  55. data/assets/src/d3.v4.min.js +0 -8
  56. data/guides/factory_prof.md +0 -85
  57. data/guides/rubocop.md +0 -48
  58. data/lib/test_prof/cops/rspec/aggregate_failures.rb +0 -140
  59. data/lib/test_prof/factory_prof/factory_girl_patch.rb +0 -12
  60. data/lib/test_prof/factory_prof/printers/flamegraph.rb +0 -71
  61. data/lib/test_prof/factory_prof/printers/simple.rb +0 -28
  62. data/lib/test_prof/factory_prof.rb +0 -140
  63. data/lib/test_prof/rubocop.rb +0 -3
@@ -1,459 +0,0 @@
1
- (function() {
2
- 'use strict';
3
-
4
- function flameGraph() {
5
-
6
- var w = 960, // graph width
7
- h = 540, // graph height
8
- c = 18, // cell height
9
- selection = null, // selection
10
- tooltip = true, // enable tooltip
11
- title = "", // graph title
12
- transitionDuration = 750,
13
- transitionEase = d3.easeCubic, // tooltip offset
14
- sort = true,
15
- reversed = false, // reverse the graph direction
16
- clickHandler = null;
17
-
18
- var tip = d3.tip()
19
- .direction("s")
20
- .offset([8, 0])
21
- .attr('class', 'd3-flame-graph-tip')
22
- .html(function(d) { return label(d); });
23
-
24
- var svg;
25
-
26
- var label = function(d) {
27
- return d.data.name + " (" + d3.format(".3f")(100 * (d.x1 - d.x0), 3) + "%, " + d.data.value + " samples)";
28
- };
29
-
30
- function setDetails(t) {
31
- var details = document.getElementById("details");
32
- if (details)
33
- details.innerHTML = t;
34
- }
35
-
36
- function name(d) {
37
- return d.data.name;
38
- }
39
-
40
- var colorMapper = function(d) {
41
- return d.highlight ? "#E600E6" : colorHash(d.data);
42
- };
43
-
44
- function generateHash(name) {
45
- // Return a vector (0.0->1.0) that is a hash of the input string.
46
- // The hash is computed to favor early characters over later ones, so
47
- // that strings with similar starts have similar vectors. Only the first
48
- // 6 characters are considered.
49
- var hash = 0, weight = 1, max_hash = 0, mod = 10, max_char = 6;
50
- if (name) {
51
- for (var i = 0; i < name.length; i++) {
52
- if (i > max_char) { break; }
53
- hash += weight * (name.charCodeAt(i) % mod);
54
- max_hash += weight * (mod - 1);
55
- weight *= 0.70;
56
- }
57
- if (max_hash > 0) { hash = hash / max_hash; }
58
- }
59
- return hash;
60
- }
61
-
62
- function colorHash(data) {
63
- var name = data.name;
64
-
65
- if (data.color) {
66
- return data.color;
67
- }
68
- // Return an rgb() color string that is a hash of the provided name,
69
- // and with a warm palette.
70
- var vector = 0;
71
- if (name) {
72
- name = name.replace(/.*`/, ""); // drop module name if present
73
- name = name.replace(/\(.*/, ""); // drop extra info
74
- vector = generateHash(name);
75
- }
76
- var r = 200 + Math.round(55 * vector);
77
- var g = 0 + Math.round(230 * vector);
78
- var b = 0 + Math.round(55 * vector);
79
- data.color = "rgb(" + r + "," + g + "," + b + ")";
80
- return data.color;
81
- }
82
-
83
- function hide(d) {
84
- if(!d.data.original) {
85
- d.data.original = d.data.value;
86
- }
87
- d.data.value = 0;
88
- if(d.children) {
89
- d.children.forEach(hide);
90
- }
91
- }
92
-
93
- function show(d) {
94
- d.data.fade = false;
95
- if(d.data.original) {
96
- d.data.value = d.data.original;
97
- }
98
- if(d.children) {
99
- d.children.forEach(show);
100
- }
101
- }
102
-
103
- function getSiblings(d) {
104
- var siblings = [];
105
- if (d.parent) {
106
- var me = d.parent.children.indexOf(d);
107
- siblings = d.parent.children.slice(0);
108
- siblings.splice(me, 1);
109
- }
110
- return siblings;
111
- }
112
-
113
- function hideSiblings(d) {
114
- var siblings = getSiblings(d);
115
- siblings.forEach(function(s) {
116
- hide(s);
117
- });
118
- if(d.parent) {
119
- hideSiblings(d.parent);
120
- }
121
- }
122
-
123
- function fadeAncestors(d) {
124
- if(d.parent) {
125
- d.parent.data.fade = true;
126
- fadeAncestors(d.parent);
127
- }
128
- }
129
-
130
- function getRoot(d) {
131
- if(d.parent) {
132
- return getRoot(d.parent);
133
- }
134
- return d;
135
- }
136
-
137
- function zoom(d) {
138
- tip.hide(d);
139
- hideSiblings(d);
140
- show(d);
141
- fadeAncestors(d);
142
- update();
143
- if (typeof clickHandler === 'function') {
144
- clickHandler(d);
145
- }
146
- }
147
-
148
- function searchTree(d, term) {
149
- var re = new RegExp(term),
150
- searchResults = [];
151
-
152
- function searchInner(d) {
153
- var label = d.data.name;
154
-
155
- if (d.children) {
156
- d.children.forEach(function (child) {
157
- searchInner(child);
158
- });
159
- }
160
-
161
- if (label.match(re)) {
162
- d.highlight = true;
163
- searchResults.push(d);
164
- } else {
165
- d.highlight = false;
166
- }
167
- }
168
-
169
- searchInner(d);
170
- return searchResults;
171
- }
172
-
173
- function clear(d) {
174
- d.highlight = false;
175
- if(d.children) {
176
- d.children.forEach(function(child) {
177
- clear(child);
178
- });
179
- }
180
- }
181
-
182
- function doSort(a, b) {
183
- if (typeof sort === 'function') {
184
- return sort(a, b);
185
- } else if (sort) {
186
- return d3.ascending(a.data.name, b.data.name);
187
- } else {
188
- return 0;
189
- }
190
- }
191
-
192
- var partition = d3.partition();
193
-
194
- function update() {
195
-
196
- selection.each(function(root) {
197
- var x = d3.scaleLinear().range([0, w]),
198
- y = d3.scaleLinear().range([0, c]);
199
-
200
- root.sort(doSort);
201
- root.sum(function(d) {
202
- if (d.fade) {
203
- return 0;
204
- }
205
- // The node's self value is its total value minus all children.
206
- var v = d.v || d.value || 0;
207
- if (d.children) {
208
- for (var i = 0; i < d.children.length; i++) {
209
- v -= d.children[i].value;
210
- }
211
- }
212
- return v;
213
- });
214
- partition(root);
215
-
216
- var kx = w / (root.x1 - root.x0);
217
- function width(d) { return (d.x1 - d.x0) * kx; }
218
-
219
- var g = d3.select(this).select("svg").selectAll("g").data(root.descendants());
220
-
221
- g.transition()
222
- .duration(transitionDuration)
223
- .ease(transitionEase)
224
- .attr("transform", function(d) { return "translate(" + x(d.x0) + ","
225
- + (reversed ? y(d.depth) : (h - y(d.depth) - c)) + ")"; });
226
-
227
- g.select("rect").transition()
228
- .duration(transitionDuration)
229
- .ease(transitionEase)
230
- .attr("width", width);
231
-
232
- var node = g.enter()
233
- .append("svg:g")
234
- .attr("transform", function(d) { return "translate(" + x(d.x0) + ","
235
- + (reversed ? y(d.depth) : (h - y(d.depth) - c)) + ")"; });
236
-
237
- node.append("svg:rect").attr("width", width);
238
-
239
- if (!tooltip)
240
- node.append("svg:title");
241
-
242
- node.append("foreignObject")
243
- .append("xhtml:div");
244
-
245
- // Now we have to re-select to see the new elements (why?).
246
- g = d3.select(this).select("svg").selectAll("g").data(root.descendants());
247
-
248
- g.attr("width", width)
249
- .attr("height", function(d) { return c; })
250
- .attr("name", function(d) { return d.data.name; })
251
- .attr("class", function(d) { return d.data.fade ? "frame fade" : "frame"; });
252
-
253
- g.select("rect")
254
- .attr("height", function(d) { return c; })
255
- .attr("fill", function(d) { return colorMapper(d); });
256
-
257
- if (!tooltip)
258
- g.select("title")
259
- .text(label);
260
-
261
- g.select("foreignObject")
262
- .attr("width", width)
263
- .attr("height", function(d) { return c; })
264
- .select("div")
265
- .attr("class", "label")
266
- .style("display", function(d) { return (width(d) < 35) ? "none" : "block";})
267
- .text(name);
268
-
269
- g.on('click', zoom);
270
-
271
- g.exit().remove();
272
-
273
- g.on('mouseover', function(d) {
274
- if (tooltip) tip.show(d);
275
- setDetails(label(d));
276
- }).on('mouseout', function(d) {
277
- if (tooltip) tip.hide(d);
278
- setDetails("");
279
- });
280
- });
281
- }
282
-
283
- function merge(data, samples) {
284
- samples.forEach(function (sample) {
285
- var node = _.find(data, function (element) {
286
- return element.name === sample.name;
287
- });
288
-
289
- if (node) {
290
- if (node.original) {
291
- node.original += sample.value;
292
- } else {
293
- node.value += sample.value;
294
- }
295
- if (sample.children) {
296
- if (!node.children) {
297
- node.children = [];
298
- }
299
- merge(node.children, sample.children)
300
- }
301
- } else {
302
- data.push(sample);
303
- }
304
- });
305
- }
306
-
307
- function chart(s) {
308
- var root = d3.hierarchy(s.datum(), function(d) { return d.c || d.children; });
309
- selection = s.datum(root);
310
-
311
- if (!arguments.length) return chart;
312
-
313
- selection.each(function(data) {
314
-
315
- if (!svg) {
316
- svg = d3.select(this)
317
- .append("svg:svg")
318
- .attr("width", w)
319
- .attr("height", h)
320
- .attr("class", "partition d3-flame-graph")
321
- .call(tip);
322
-
323
- svg.append("svg:text")
324
- .attr("class", "title")
325
- .attr("text-anchor", "middle")
326
- .attr("y", "25")
327
- .attr("x", w/2)
328
- .attr("fill", "#808080")
329
- .text(title);
330
- }
331
- });
332
-
333
- // first draw
334
- update();
335
- }
336
-
337
- chart.height = function (_) {
338
- if (!arguments.length) { return h; }
339
- h = _;
340
- return chart;
341
- };
342
-
343
- chart.width = function (_) {
344
- if (!arguments.length) { return w; }
345
- w = _;
346
- return chart;
347
- };
348
-
349
- chart.cellHeight = function (_) {
350
- if (!arguments.length) { return c; }
351
- c = _;
352
- return chart;
353
- };
354
-
355
- chart.tooltip = function (_) {
356
- if (!arguments.length) { return tooltip; }
357
- if (typeof _ === "function") {
358
- tip = _;
359
- }
360
- tooltip = true;
361
- return chart;
362
- };
363
-
364
- chart.title = function (_) {
365
- if (!arguments.length) { return title; }
366
- title = _;
367
- return chart;
368
- };
369
-
370
- chart.transitionDuration = function (_) {
371
- if (!arguments.length) { return transitionDuration; }
372
- transitionDuration = _;
373
- return chart;
374
- };
375
-
376
- chart.transitionEase = function (_) {
377
- if (!arguments.length) { return transitionEase; }
378
- transitionEase = _;
379
- return chart;
380
- };
381
-
382
- chart.sort = function (_) {
383
- if (!arguments.length) { return sort; }
384
- sort = _;
385
- return chart;
386
- };
387
-
388
- chart.reversed = function (_) {
389
- if (!arguments.length) { return reversed; }
390
- reversed = _;
391
- return chart;
392
- };
393
-
394
- chart.label = function(_) {
395
- if (!arguments.length) { return label; }
396
- label = _;
397
- return chart;
398
- };
399
-
400
- chart.search = function(term) {
401
- var searchResults = [];
402
- selection.each(function(data) {
403
- searchResults = searchTree(data, term);
404
- update();
405
- });
406
- return searchResults;
407
- };
408
-
409
- chart.clear = function() {
410
- selection.each(function(data) {
411
- clear(data);
412
- update();
413
- });
414
- };
415
-
416
- chart.zoomTo = function(d) {
417
- zoom(d);
418
- };
419
-
420
- chart.resetZoom = function() {
421
- selection.each(function (data) {
422
- zoom(data); // zoom to root
423
- });
424
- };
425
-
426
- chart.onClick = function(_) {
427
- if (!arguments.length) {
428
- return clickHandler;
429
- }
430
- clickHandler = _;
431
- return chart;
432
- };
433
-
434
- chart.merge = function(samples) {
435
- var newRoot; // Need to re-create hierarchy after data changes.
436
- selection.each(function (root) {
437
- merge([root.data], [samples]);
438
- newRoot = d3.hierarchy(root.data, function(d) { return d.c || d.children; });
439
- });
440
- selection = selection.datum(newRoot);
441
- update();
442
- }
443
-
444
- chart.color = function(_) {
445
- if (!arguments.length) { return colorMapper; }
446
- colorMapper = _;
447
- return chart;
448
- };
449
-
450
- return chart;
451
- }
452
-
453
- if (typeof module !== 'undefined' && module.exports){
454
- module.exports = flameGraph;
455
- }
456
- else {
457
- d3.flameGraph = flameGraph;
458
- }
459
- })();
@@ -1 +0,0 @@
1
- .d3-flame-graph rect{stroke:#EEE;fill-opacity:.8}.d3-flame-graph rect:hover{stroke:#474747;stroke-width:.5;cursor:pointer}.d3-flame-graph .label{pointer-events:none;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;font-size:12px;font-family:Verdana;margin-left:4px;margin-right:4px;line-height:1.5;padding:0;font-weight:400;color:#000;text-align:left}.d3-flame-graph .fade{opacity:.6!important}.d3-flame-graph .title{font-size:20px;font-family:Verdana}.d3-flame-graph-tip{line-height:1;font-family:Verdana;font-size:12px;padding:12px;background:rgba(0,0,0,.8);color:#fff;border-radius:2px;pointer-events:none}.d3-flame-graph-tip:after{box-sizing:border-box;display:inline;font-size:10px;width:100%;line-height:1;color:rgba(0,0,0,.8);position:absolute;pointer-events:none}.d3-flame-graph-tip.n:after{content:"\25BC";margin:-1px 0 0;top:100%;left:0;text-align:center}.d3-flame-graph-tip.e:after{content:"\25C0";margin:-4px 0 0;top:50%;left:-8px}.d3-flame-graph-tip.s:after{content:"\25B2";margin:0 0 1px;top:-8px;left:0;text-align:center}.d3-flame-graph-tip.w:after{content:"\25B6";margin:-4px 0 0 -1px;top:50%;left:100%}
@@ -1 +0,0 @@
1
- !function(){"use strict";function t(){function t(t){var n=document.getElementById("details");n&&(n.innerHTML=t)}function n(t){return t.data.name}function e(t){var n=0,e=1,r=0;if(t){for(var a=0;a<t.length&&!(a>6);a++)n+=e*(t.charCodeAt(a)%10),r+=9*e,e*=.7;r>0&&(n/=r)}return n}function r(t){var n=t.name;if(t.color)return t.color;var r=0;n&&(r=e(n=(n=n.replace(/.*`/,"")).replace(/\(.*/,"")));var a=200+Math.round(55*r),i=0+Math.round(230*r),c=0+Math.round(55*r);return t.color="rgb("+a+","+i+","+c+")",t.color}function a(t){t.data.original||(t.data.original=t.data.value),t.data.value=0,t.children&&t.children.forEach(a)}function i(t){t.data.fade=!1,t.data.original&&(t.data.value=t.data.original),t.children&&t.children.forEach(i)}function c(t){var n=[];if(t.parent){var e=t.parent.children.indexOf(t);(n=t.parent.children.slice(0)).splice(e,1)}return n}function o(t){c(t).forEach(function(t){a(t)}),t.parent&&o(t.parent)}function u(t){t.parent&&(t.parent.data.fade=!0,u(t.parent))}function l(t){O.hide(t),o(t),i(t),u(t),s(),"function"==typeof L&&L(t)}function d(t,n){function e(t){var n=t.data.name;t.children&&t.children.forEach(function(t){e(t)}),n.match(r)?(t.highlight=!0,a.push(t)):t.highlight=!1}var r=new RegExp(n),a=[];return e(t),a}function f(t){t.highlight=!1,t.children&&t.children.forEach(function(t){f(t)})}function h(t,n){return"function"==typeof A?A(t,n):A?d3.ascending(t.data.name,n.data.name):0}function s(){y.each(function(e){function r(t){return(t.x1-t.x0)*c}var a=d3.scaleLinear().range([0,m]),i=d3.scaleLinear().range([0,E]);e.sort(h),e.sum(function(t){if(t.fade)return 0;var n=t.v||t.value||0;if(t.children)for(var e=0;e<t.children.length;e++)n-=t.children[e].value;return n}),T(e);var c=m/(e.x1-e.x0),o=d3.select(this).select("svg").selectAll("g").data(e.descendants());o.transition().duration(M).ease(k).attr("transform",function(t){return"translate("+a(t.x0)+","+(C?i(t.depth):x-i(t.depth)-E)+")"}),o.select("rect").transition().duration(M).ease(k).attr("width",r);var u=o.enter().append("svg:g").attr("transform",function(t){return"translate("+a(t.x0)+","+(C?i(t.depth):x-i(t.depth)-E)+")"});u.append("svg:rect").attr("width",r),w||u.append("svg:title"),u.append("foreignObject").append("xhtml:div"),(o=d3.select(this).select("svg").selectAll("g").data(e.descendants())).attr("width",r).attr("height",function(t){return E}).attr("name",function(t){return t.data.name}).attr("class",function(t){return t.data.fade?"frame fade":"frame"}),o.select("rect").attr("height",function(t){return E}).attr("fill",function(t){return H(t)}),w||o.select("title").text(j),o.select("foreignObject").attr("width",r).attr("height",function(t){return E}).select("div").attr("class","label").style("display",function(t){return r(t)<35?"none":"block"}).text(n),o.on("click",l),o.exit().remove(),o.on("mouseover",function(n){w&&O.show(n),t(j(n))}).on("mouseout",function(n){w&&O.hide(n),t("")})})}function g(t,n){n.forEach(function(n){var e=_.find(t,function(t){return t.name===n.name});e?(e.original?e.original+=n.value:e.value+=n.value,n.children&&(e.children||(e.children=[]),g(e.children,n.children))):t.push(n)})}function p(t){var n=d3.hierarchy(t.datum(),function(t){return t.c||t.children});if(y=t.datum(n),!arguments.length)return p;y.each(function(t){v||(v=d3.select(this).append("svg:svg").attr("width",m).attr("height",x).attr("class","partition d3-flame-graph").call(O)).append("svg:text").attr("class","title").attr("text-anchor","middle").attr("y","25").attr("x",m/2).attr("fill","#808080").text(b)}),s()}var v,m=960,x=540,E=18,y=null,w=!0,b="",M=750,k=d3.easeCubic,A=!0,C=!1,L=null,O=d3.tip().direction("s").offset([8,0]).attr("class","d3-flame-graph-tip").html(function(t){return j(t)}),j=function(t){return t.data.name+" ("+d3.format(".3f")(100*(t.x1-t.x0),3)+"%, "+t.data.value+" samples)"},H=function(t){return t.highlight?"#E600E6":r(t.data)},T=d3.partition();return p.height=function(t){return arguments.length?(x=t,p):x},p.width=function(t){return arguments.length?(m=t,p):m},p.cellHeight=function(t){return arguments.length?(E=t,p):E},p.tooltip=function(t){return arguments.length?("function"==typeof t&&(O=t),w=!0,p):w},p.title=function(t){return arguments.length?(b=t,p):b},p.transitionDuration=function(t){return arguments.length?(M=t,p):M},p.transitionEase=function(t){return arguments.length?(k=t,p):k},p.sort=function(t){return arguments.length?(A=t,p):A},p.reversed=function(t){return arguments.length?(C=t,p):C},p.label=function(t){return arguments.length?(j=t,p):j},p.search=function(t){var n=[];return y.each(function(e){n=d(e,t),s()}),n},p.clear=function(){y.each(function(t){f(t),s()})},p.zoomTo=function(t){l(t)},p.resetZoom=function(){y.each(function(t){l(t)})},p.onClick=function(t){return arguments.length?(L=t,p):L},p.merge=function(t){var n;y.each(function(e){g([e.data],[t]),n=d3.hierarchy(e.data,function(t){return t.c||t.children})}),y=y.datum(n),s()},p.color=function(t){return arguments.length?(H=t,p):H},p}"undefined"!=typeof module&&module.exports?module.exports=t:d3.flameGraph=t}();