test-prof-autopilot 0.0.5 → 0.0.6
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 +4 -4
- data/lib/test_prof/autopilot/factory_prof/printer.rb +3 -24
- data/lib/test_prof/autopilot/factory_prof/report.rb +30 -0
- data/lib/test_prof/autopilot/factory_prof/writer.rb +23 -9
- data/lib/test_prof/autopilot/patches/factory_prof_patch.rb +20 -43
- data/lib/test_prof/autopilot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9053434f1ede969d5dc60e8f0ed6bada6ba628220fa599c7700ab9fa4bfeec85
|
4
|
+
data.tar.gz: ba2428c6baff4d0b0c437f01b3e3f4522f1d9a3f528689bb9de317e54e94e661
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95aeca28faec87d052dbb5ce90dd953753acc8d4026be7b8b9b270e495008405de10672cfc6dee680d3839f90db6c7564faf7655614cee6346b63c0384707c9
|
7
|
+
data.tar.gz: ade585ced221e23276f229db9742896e9161ecda7455a66d24f4a81f7184cbb25e4e7d061393062ad3579d9ddf0409861e54939a41ba9dc2b0cd8bbad0657b00
|
@@ -10,31 +10,10 @@ module TestProf
|
|
10
10
|
class PrinterError < StandardError; end
|
11
11
|
|
12
12
|
def print_report(report)
|
13
|
-
result = report.
|
13
|
+
result = report.result
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
msgs = []
|
18
|
-
|
19
|
-
msgs <<
|
20
|
-
<<~MSG
|
21
|
-
Factories usage
|
22
|
-
|
23
|
-
Total: #{result["total_count"]}
|
24
|
-
Total top-level: #{result["total_top_level_count"]}
|
25
|
-
Total time: #{format("%.4f", result["total_time"])}s
|
26
|
-
Total uniq factories: #{result["total_uniq_factories"]}
|
27
|
-
|
28
|
-
total top-level total time time per call top-level time name
|
29
|
-
MSG
|
30
|
-
|
31
|
-
result["stats"].each do |stat|
|
32
|
-
time_per_call = stat["total_time"] / stat["total_count"]
|
33
|
-
|
34
|
-
msgs << format("%8d %11d %13.4fs %17.4fs %18.4fs %18s", stat["total_count"], stat["top_level_count"], stat["total_time"], time_per_call, stat["top_level_time"], stat["name"])
|
35
|
-
end
|
36
|
-
|
37
|
-
Logging.log msgs.join("\n")
|
15
|
+
# TODO: Move total_time to the report
|
16
|
+
TestProf::FactoryProf::Printers::Simple.dump(result, start_time: TestProf.now)
|
38
17
|
end
|
39
18
|
|
40
19
|
module_function :print_report
|
@@ -21,6 +21,36 @@ module TestProf
|
|
21
21
|
@type = :factory_prof
|
22
22
|
@raw_report = raw_report
|
23
23
|
end
|
24
|
+
|
25
|
+
def result
|
26
|
+
@result ||= TestProf::FactoryProf::Result.new(
|
27
|
+
raw_report["stacks"],
|
28
|
+
raw_report["raw_stats"].transform_values! { |stats| stats.transform_keys!(&:to_sym) }
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def merge(other)
|
33
|
+
report = raw_report.dup
|
34
|
+
|
35
|
+
report["stacks"] += other.raw_report["stacks"] if report["stacks"]
|
36
|
+
|
37
|
+
(report["raw_stats"].values + other.raw_report["raw_stats"].values).each_with_object({}) do |data, acc|
|
38
|
+
if acc.key?(data["name"])
|
39
|
+
current = acc[data["name"]]
|
40
|
+
|
41
|
+
current["total_count"] += data["total_count"]
|
42
|
+
current["top_level_count"] += data["top_level_count"]
|
43
|
+
current["total_time"] += data["total_time"]
|
44
|
+
current["top_level_time"] += data["top_level_time"]
|
45
|
+
else
|
46
|
+
acc[data["name"]] = data.dup
|
47
|
+
end
|
48
|
+
end.then do |stats|
|
49
|
+
report["raw_stats"] = stats
|
50
|
+
end
|
51
|
+
|
52
|
+
Report.new(report)
|
53
|
+
end
|
24
54
|
end
|
25
55
|
end
|
26
56
|
end
|
@@ -3,22 +3,36 @@
|
|
3
3
|
module TestProf
|
4
4
|
module Autopilot
|
5
5
|
module FactoryProf
|
6
|
-
#
|
7
|
-
|
6
|
+
# Class is used for writing :factory_prof report in different formats
|
7
|
+
class Writer < ReportWriter
|
8
8
|
Registry.register(:factory_prof_writer, self)
|
9
9
|
|
10
10
|
ARTIFACT_FILE = "factory_prof_report"
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
12
|
+
def generate_json
|
13
|
+
report.result.to_json
|
14
|
+
end
|
15
15
|
|
16
|
-
|
16
|
+
def generate_html
|
17
|
+
result = report.result
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
report_data = {
|
20
|
+
total_stacks: result.stacks.size,
|
21
|
+
total: result.total_count
|
22
|
+
}
|
23
|
+
|
24
|
+
report_data[:roots] = TestProf::FactoryProf::Printers::Flamegraph.convert_stacks(result)
|
20
25
|
|
21
|
-
|
26
|
+
path = TestProf::Utils::HTMLBuilder.generate(
|
27
|
+
data: report_data,
|
28
|
+
template: TestProf::FactoryProf::Printers::Flamegraph::TEMPLATE,
|
29
|
+
output: TestProf::FactoryProf::Printers::Flamegraph::OUTPUT_NAME
|
30
|
+
)
|
31
|
+
|
32
|
+
File.read(path).tap do
|
33
|
+
FileUtils.rm(path)
|
34
|
+
end
|
35
|
+
end
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
@@ -1,6 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module TestProf
|
4
|
+
using(Module.new do
|
5
|
+
refine FactoryProf::Result do
|
6
|
+
def to_json
|
7
|
+
{
|
8
|
+
stacks: stacks,
|
9
|
+
raw_stats: raw_stats
|
10
|
+
}.to_json
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end)
|
14
|
+
|
4
15
|
module Autopilot
|
5
16
|
module Patches
|
6
17
|
# Monkey-patch for 'TestProf::FactoryProf::Printers::Simple'.
|
@@ -9,52 +20,18 @@ module TestProf
|
|
9
20
|
module FactoryProfPatch
|
10
21
|
ARTIFACT_FILE = "factory_prof_report.json"
|
11
22
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if result.raw_stats == {}
|
17
|
-
{
|
18
|
-
error: "No factories detected"
|
19
|
-
}
|
20
|
-
else
|
21
|
-
{
|
22
|
-
total_count: result.stats.sum { |stat| stat[:total_count] },
|
23
|
-
total_top_level_count: result.stats.sum { |stat| stat[:top_level_count] },
|
24
|
-
total_time: result.stats.sum { |stat| stat[:top_level_time] },
|
25
|
-
total_uniq_factories: result.stats.uniq { |stat| stat[:name] }.count,
|
26
|
-
stats: result.stats
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
dir_path = FileUtils.mkdir_p(Autopilot.config.tmp_dir)[0]
|
31
|
-
file_path = File.join(dir_path, ARTIFACT_FILE)
|
23
|
+
module PrinterExt
|
24
|
+
def dump(result, **)
|
25
|
+
dir_path = FileUtils.mkdir_p(Autopilot.config.tmp_dir)[0]
|
26
|
+
file_path = File.join(dir_path, ARTIFACT_FILE)
|
32
27
|
|
33
|
-
|
34
|
-
end
|
28
|
+
File.write(file_path, result.to_json)
|
35
29
|
end
|
30
|
+
end
|
36
31
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if result.raw_stats == {}
|
41
|
-
{
|
42
|
-
error: "No factories detected"
|
43
|
-
}
|
44
|
-
else
|
45
|
-
{
|
46
|
-
total_stacks: result.stacks.size,
|
47
|
-
total: result.total_count,
|
48
|
-
roots: convert_stacks(result)
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
dir_path = FileUtils.mkdir_p(Autopilot.config.tmp_dir)[0]
|
53
|
-
file_path = File.join(dir_path, ARTIFACT_FILE)
|
54
|
-
|
55
|
-
File.write(file_path, JSON.generate(profiler_hash))
|
56
|
-
end
|
57
|
-
end
|
32
|
+
def patch
|
33
|
+
TestProf::FactoryProf::Printers::Simple.singleton_class.prepend(PrinterExt)
|
34
|
+
TestProf::FactoryProf::Printers::Flamegraph.singleton_class.prepend(PrinterExt)
|
58
35
|
end
|
59
36
|
|
60
37
|
module_function :patch
|