Skip to content

Commit 4ddb999

Browse files
Utilize Ruby Logger class to created timestamped output to find performance issues. (#668)
1 parent e2d13ef commit 4ddb999

File tree

10 files changed

+187
-120
lines changed

10 files changed

+187
-120
lines changed

Rakefile

+27-20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require "etc"
1111
$root = Pathname.new(__FILE__).dirname.realpath
1212
$lib = $root / "lib"
1313

14+
require "logger"
1415
require "ruby-progressbar"
1516
require "yard"
1617
require "minitest/test_task"
@@ -19,6 +20,12 @@ require_relative $root / "lib" / "architecture"
1920
require_relative $root / "lib" / "portfolio_design"
2021
require_relative $root / "lib" / "proc_cert_design"
2122

23+
$logger = Logger.new(STDOUT, datetime_format: "%v %r")
24+
$logger.level = Logger::INFO
25+
$logger.formatter = proc do |severity, datetime, progname, msg|
26+
"[#{severity}] #{datetime.strftime('%F %T')}: #{msg}\n"
27+
end
28+
2229
directory "#{$root}/.stamps"
2330

2431
# Load and execute Rakefile for each backend.
@@ -426,22 +433,22 @@ namespace :test do
426433
These are basic but fast-running tests to check the database and tools
427434
DESC
428435
task :smoke do
429-
puts "UPDATE: Starting test:smoke"
430-
puts "UPDATE: Running gen:isa_explorer_browser_ext"
436+
$logger.info "Starting test:smoke"
437+
$logger.info "Running gen:isa_explorer_browser_ext"
431438
Rake::Task["gen:isa_explorer_browser_ext"].invoke
432-
puts "UPDATE: Running test:idl_compiler"
439+
$logger.info "Running test:idl_compiler"
433440
Rake::Task["test:idl_compiler"].invoke
434-
puts "UPDATE: Running test:lib"
441+
$logger.info "Running test:lib"
435442
Rake::Task["test:lib"].invoke
436-
puts "UPDATE: Running test:schema"
443+
$logger.info "Running test:schema"
437444
Rake::Task["test:schema"].invoke
438-
puts "UPDATE: Running test:idl"
445+
$logger.info "Running test:idl"
439446
Rake::Task["test:idl"].invoke
440-
puts "UPDATE: Running test:inst_encodings"
447+
$logger.info "Running test:inst_encodings"
441448
Rake::Task["test:inst_encodings"].invoke
442-
puts "UPDATE: Running test:llvm"
449+
$logger.info "Running test:llvm"
443450
Rake::Task["test:llvm"].invoke
444-
puts "UPDATE: Done test:smoke"
451+
$logger.info "Done test:smoke"
445452
end
446453

447454
desc <<~DESC
@@ -450,41 +457,41 @@ namespace :test do
450457
These tests must pass before a commit will be allowed in the main branch on GitHub
451458
DESC
452459
task :regress do
453-
puts "UPDATE: Starting test:regress"
460+
$logger.info "Starting test:regress"
454461
Rake::Task["test:smoke"].invoke
455462

456-
puts "UPDATE: Running gen:isa_explorer_browser"
463+
$logger.info "Running gen:isa_explorer_browser"
457464
Rake::Task["gen:isa_explorer_browser"].invoke
458465

459-
puts "UPDATE: Running gen:isa_explorer_spreadsheet"
466+
$logger.info "Running gen:isa_explorer_spreadsheet"
460467
Rake::Task["gen:isa_explorer_spreadsheet"].invoke
461468

462-
puts "UPDATE: Running gen:html_manual MANUAL_NAME=isa VERSIONS=all"
469+
$logger.info "Running gen:html_manual MANUAL_NAME=isa VERSIONS=all"
463470
ENV["MANUAL_NAME"] = "isa"
464471
ENV["VERSIONS"] = "all"
465472
Rake::Task["gen:html_manual"].invoke
466473

467-
puts "UPDATE: Running gen:ext_pdf EXT=B VERSION=latest"
474+
$logger.info "Running gen:ext_pdf EXT=B VERSION=latest"
468475
ENV["EXT"] = "B"
469476
ENV["VERSION"] = "latest"
470477
Rake::Task["gen:ext_pdf"].invoke
471478

472-
puts "UPDATE: Running gen:html for example_rv64_with_overlay"
479+
$logger.info "Running gen:html for example_rv64_with_overlay"
473480
Rake::Task["gen:html"].invoke("example_rv64_with_overlay")
474481

475-
puts "UPDATE: Generating MockProcessor-CRD.pdf"
482+
$logger.info "Generating MockProcessor-CRD.pdf"
476483
Rake::Task["#{$root}/gen/proc_crd/pdf/MockProcessor-CRD.pdf"].invoke
477484

478-
puts "UPDATE: Generating MockProcessor-CTP.pdf"
485+
$logger.info "Generating MockProcessor-CTP.pdf"
479486
Rake::Task["#{$root}/gen/proc_ctp/pdf/MockProcessor-CTP.pdf"].invoke
480487

481-
puts "UPDATE: Generating MockProfileRelease.pdf"
488+
$logger.info "Generating MockProfileRelease.pdf"
482489
Rake::Task["#{$root}/gen/profile/pdf/MockProfileRelease.pdf"].invoke
483490

484-
puts "UPDATE: Generating Go Language Support"
491+
$logger.info "Generating Go Language Support"
485492
Rake::Task["gen:go"].invoke
486493

487-
puts "UPDATE: Done test:regress"
494+
$logger.info "Done test:regress"
488495
end
489496

490497
desc <<~DESC

backends/cfg_html_doc/html_gen.rake

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ rule %r{#{$root}/\.stamps/html-gen-.*\.stamp} => proc { |tname|
230230
playbook_path = $root / "gen" / "cfg_html_doc" / config_name / "antora" / "playbook.yaml"
231231
Rake::Task[playbook_path].invoke
232232

233+
$logger.info "Running Antora under npm to create #{config_name}"
234+
233235
sh [
234236
"npm exec -- antora",
235237
"--stacktrace",
@@ -240,6 +242,9 @@ rule %r{#{$root}/\.stamps/html-gen-.*\.stamp} => proc { |tname|
240242
"--fetch",
241243
playbook_path
242244
].join(" ")
245+
246+
$logger.info "Done running Antora under npm to create #{config_name}"
247+
243248
FileUtils.touch t.name
244249
end
245250

backends/isa_explorer/isa_explorer.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -237,40 +237,40 @@ def gen_xlsx(arch, output_pname)
237237
raise ArgumentError, "output_pname is a #{output_pname.class} class but needs to be String" unless output_pname.is_a?(String)
238238

239239
# Create a new Excel workbook
240-
puts "UPDATE: Creating Excel workboook #{output_pname}"
240+
$logger.info "Creating Excel workboook #{output_pname}"
241241
workbook = WriteXLSX.new(output_pname)
242242

243243
# Convert arch to ext_table data structure
244-
puts "UPDATE: Creating extension table data structure"
244+
$logger.info "Creating extension table data structure"
245245
ext_table = arch2ext_table(arch)
246246

247247
# Add a worksheet
248248
ext_worksheet = workbook.add_worksheet("Extensions")
249249

250250
# Populate worksheet with ext_table
251-
puts "UPDATE: Adding extension table to worksheet #{ext_worksheet.name}"
251+
$logger.info "Adding extension table to worksheet #{ext_worksheet.name}"
252252
gen_xlsx_table(ext_table, workbook, ext_worksheet)
253253

254254
# Convert arch to inst_table data structure
255-
puts "UPDATE: Creating instruction table data structure"
255+
$logger.info "Creating instruction table data structure"
256256
inst_table = arch2inst_table(arch)
257257

258258
# Add a worksheet
259259
inst_worksheet = workbook.add_worksheet("Instructions")
260260

261261
# Populate worksheet with inst_table
262-
puts "UPDATE: Adding instruction table to worksheet #{inst_worksheet.name}"
262+
$logger.info "Adding instruction table to worksheet #{inst_worksheet.name}"
263263
gen_xlsx_table(inst_table, workbook, inst_worksheet)
264264

265265
# Convert arch to csr_table data structure
266-
puts "UPDATE: Creating CSR table data structure"
266+
$logger.info "Creating CSR table data structure"
267267
csr_table = arch2csr_table(arch)
268268

269269
# Add a worksheet
270270
csr_worksheet = workbook.add_worksheet("CSRs")
271271

272272
# Populate worksheet with csr
273-
puts "UPDATE: Adding CSR table to worksheet #{csr_worksheet.name}"
273+
$logger.info "Adding CSR table to worksheet #{csr_worksheet.name}"
274274
gen_xlsx_table(csr_table, workbook, csr_worksheet)
275275

276276
workbook.close
@@ -359,10 +359,10 @@ def gen_js_ext_table(arch, output_pname)
359359
raise ArgumentError, "output_pname is a #{output_pname.class} class but needs to be String" unless output_pname.is_a?(String)
360360

361361
# Convert arch to ext_table data structure
362-
puts "UPDATE: Creating extension table data structure"
362+
$logger.info "Creating extension table data structure"
363363
ext_table = arch2ext_table(arch)
364364

365-
puts "UPDATE: Converting extension table to #{output_pname}"
365+
$logger.info "Converting extension table to #{output_pname}"
366366
gen_js_table(ext_table, "ext_table", output_pname)
367367
end
368368

@@ -375,10 +375,10 @@ def gen_js_inst_table(arch, output_pname)
375375
raise ArgumentError, "output_pname is a #{output_pname.class} class but needs to be String" unless output_pname.is_a?(String)
376376

377377
# Convert arch to inst_table data structure
378-
puts "UPDATE: Creating instruction table data structure"
378+
$logger.info "Creating instruction table data structure"
379379
inst_table = arch2inst_table(arch)
380380

381-
puts "UPDATE: Converting instruction table to #{output_pname}"
381+
$logger.info "Converting instruction table to #{output_pname}"
382382
gen_js_table(inst_table, "inst_table", output_pname)
383383
end
384384

@@ -391,10 +391,10 @@ def gen_js_csr_table(arch, output_pname)
391391
raise ArgumentError, "output_pname is a #{output_pname.class} class but needs to be String" unless output_pname.is_a?(String)
392392

393393
# Convert arch to csr_table data structure
394-
puts "UPDATE: Creating CSR table data structure"
394+
$logger.info "Creating CSR table data structure"
395395
csr_table = arch2csr_table(arch)
396396

397-
puts "UPDATE: Converting CSR table to #{output_pname}"
397+
$logger.info "Converting CSR table to #{output_pname}"
398398
gen_js_table(csr_table, "csr_table", output_pname)
399399
end
400400

backends/manual/tasks.rake

+5-5
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,17 @@ namespace :gen do
410410
Rake::Task[antora_path / "antora.yml"].invoke
411411
Rake::Task[antora_path / "nav.adoc"].invoke
412412

413-
puts "UPDATE: Generating CSRs"
413+
$logger.info "Generating CSRs"
414414
version_obj.csrs.each do |csr|
415415
Rake::Task[antora_path / "modules" / "csrs" / "pages" / "#{csr.name}.adoc"].invoke
416416
end
417417

418-
puts "UPDATE: Generating Instructions"
418+
$logger.info "Generating Instructions"
419419
version_obj.instructions.each do |inst|
420420
Rake::Task[antora_path / "modules" / "insts" / "pages" / "#{inst.name}.adoc"].invoke
421421
end
422422

423-
puts "UPDATE: Generating Extensions"
423+
$logger.info "Generating Extensions"
424424
version_obj.extensions.each do |ext|
425425
Rake::Task[antora_path / "modules" / "exts" / "pages" / "#{ext.name}.adoc"].invoke
426426
end
@@ -436,7 +436,7 @@ namespace :gen do
436436
playbook_path = MANUAL_GEN_DIR / ENV["MANUAL_NAME"] / "top" / output_hash / "antora" / "playbook" / "playbook.yml"
437437
Rake::Task[playbook_path].invoke
438438

439-
puts "UPDATE: Using npm to execute Antora"
439+
$logger.info "Running Antora under npm for HTML site to create '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
440440

441441
sh [
442442
"npm exec -- antora",
@@ -449,7 +449,7 @@ namespace :gen do
449449
playbook_path.to_s
450450
].join(" ")
451451

452-
puts "SUCCESS: HTML site written to '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
452+
$logger.info "Done running Antora under npm for HTML site to create '#{MANUAL_GEN_DIR / ENV['MANUAL_NAME'] / output_hash / 'html'}'"
453453
end
454454
end
455455

backends/portfolio/tasks.rake

+12-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def pf_create_cfg_arch(portfolio_grp_with_arch)
2929
# otherwise there would be a circular dependency. To avoid this circular dependency, none of the routines
3030
# called in the PortfolioGroup object to satisfy the requests from the AbstractConfig API for the ConfiguredArchitecture
3131
# object can require that the PortfolioGroup DatabaseObjects contain a ConfiguredArchitecture.
32-
cfg_arch_with_portfolio_grp_with_arch = ConfiguredArchitecture.new(
32+
ConfiguredArchitecture.new(
3333
portfolio_grp_with_arch.name,
3434
PortfolioGroupConfig.new(portfolio_grp_with_arch),
3535
$root / "gen" / "resolved_arch" / "_"
@@ -68,6 +68,7 @@ end
6868
# @param target_pname [String] Full pathname of adoc file being generated
6969
# @param portfolio_design [PortfolioDesign] PortfolioDesign being generated
7070
def pf_create_adoc(erb_template_pname, erb_binding, target_pname, portfolio_design)
71+
$logger.info "Reading ERB adoc template for #{portfolio_design.name}"
7172
template_path = Pathname.new(erb_template_pname)
7273
erb = ERB.new(File.read(template_path), trim_mode: "-")
7374
erb.filename = template_path.to_s
@@ -77,21 +78,22 @@ def pf_create_adoc(erb_template_pname, erb_binding, target_pname, portfolio_desi
7778

7879
# Convert ERB to final ASCIIDOC. Note that this code is broken up into separate function calls
7980
# each with a variable name to aid in running a command-line debugger on this code.
80-
puts "UPDATE: Converting ERB template to adoc for #{portfolio_design.name}"
81+
$logger.info "Starting ERB adoc template evaluation for #{portfolio_design.name}"
8182
erb_result = erb.result(erb_binding)
83+
$logger.info "Converting monospace formatting to internal link format"
8284
erb_result_monospace_converted_to_links = portfolio_design.convert_monospace_to_links(erb_result)
85+
$logger.info "Converting internal link format to adoc links"
8386
erb_result_with_links_resolved = AsciidocUtils.resolve_links(erb_result_monospace_converted_to_links)
84-
87+
$logger.info "Writing adoc to #{target_pname}"
8588
File.write(target_pname, erb_result_with_links_resolved)
86-
puts "UPDATE: Generated adoc in #{target_pname}"
8789
end
8890

8991
# @param adoc_file [String] Full name of source adoc file
9092
# @param target_pname [String] Full name of PDF file being generated
9193
def pf_adoc2pdf(adoc_file, target_pname)
9294
FileUtils.mkdir_p File.dirname(target_pname)
9395

94-
puts "UPDATE: Generating PDF in #{target_pname}"
96+
$logger.info "Generating PDF in #{target_pname}"
9597
cmd = [
9698
"asciidoctor-pdf",
9799
"-w",
@@ -107,7 +109,7 @@ def pf_adoc2pdf(adoc_file, target_pname)
107109
adoc_file
108110
].join(" ")
109111

110-
puts "UPDATE: bundle exec #{cmd}"
112+
$logger.info "bundle exec #{cmd}"
111113

112114
# Write out command used to convert adoc to PDF to allow running this
113115
# manually during development.
@@ -121,15 +123,15 @@ def pf_adoc2pdf(adoc_file, target_pname)
121123
# Now run the actual command.
122124
sh cmd
123125

124-
puts "UPDATE: Generated PDF in #{target_pname}"
126+
$logger.info "Generated PDF in #{target_pname}"
125127
end
126128

127129
# @param adoc_file [String] Full name of source adoc file
128130
# @param target_pname [String] Full name of HTML file being generated
129131
def pf_adoc2html(adoc_file, target_pname)
130132
FileUtils.mkdir_p File.dirname(target_pname)
131133

132-
puts "UPDATE: Generating HTML in #{target_pname}"
134+
$logger.info "Generating HTML in #{target_pname}"
133135
cmd = [
134136
"asciidoctor",
135137
"-w",
@@ -142,7 +144,7 @@ def pf_adoc2html(adoc_file, target_pname)
142144
adoc_file
143145
].join(" ")
144146

145-
puts "UPDATE: bundle exec #{cmd}"
147+
$logger.info "bundle exec #{cmd}"
146148

147149
# Write out command used to convert adoc to HTML to allow running this
148150
# manually during development.
@@ -156,5 +158,5 @@ def pf_adoc2html(adoc_file, target_pname)
156158
# Now run the actual command.
157159
sh cmd
158160

159-
puts "UPDATE: Generated HTML in #{target_pname}"
161+
$logger.info "Generated HTML in #{target_pname}"
160162
end

backends/proc_cert/tasks.rake

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@ require "asciidoctor-diagram"
1111
# @param model_name [String] Name of the processor certificate model
1212
def proc_cert_create_adoc(erb_template_pname, target_pname, model_name)
1313
# Create Architecture object without any knowledge of certificate model.
14+
$logger.info "Creating Architecture object for #{model_name}"
1415
arch = pf_create_arch
1516

1617
# Create ProcCertModel for specific processor certificate model as specified in its arch YAML file.
1718
# The Architecture object also creates all other portfolio-related class instances from their arch YAML files.
1819
# None of these objects are provided with a AbstractConfig or Design object when created.
19-
puts "UPDATE: Creating ProcCertModel with only an Architecture object for #{model_name}"
20+
$logger.info "Creating ProcCertModel with only an Architecture object for #{model_name}"
2021
proc_cert_model_with_arch = arch.proc_cert_model(model_name)
2122

2223
# Create the ConfiguredArchitecture object with knowledge of the ProcCertModel.
2324
# Needs a PortfolioGroup object so just create one with just one ProcCertModel (which is a child of Portfolio).
2425
cfg_arch = pf_create_cfg_arch(PortfolioGroup.new(model_name, [proc_cert_model_with_arch]))
2526

26-
puts "UPDATE: Creating ProcCertModel with a ConfiguredArchitecture object for #{model_name}"
27+
$logger.info "Creating ProcCertModel with a ConfiguredArchitecture object for #{model_name}"
2728
proc_cert_model_with_cfg_arch = cfg_arch.proc_cert_model(model_name)
2829

2930
# Create the one ProcCertDesign object required for the ERB evaluation using the cfg_arch.
30-
puts "UPDATE: Creating ProcCertDesign object using processor certificate model #{model_name}"
31+
$logger.info "Creating ProcCertDesign object using processor certificate model #{model_name}"
3132
proc_cert_design = ProcCertDesign.new(model_name, cfg_arch, ProcCertDesign.proc_ctp_type, proc_cert_model_with_cfg_arch,
3233
proc_cert_model_with_cfg_arch.proc_cert_class)
3334

backends/proc_ctp/templates/proc_ctp.adoc.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ This document is generated by a database backend so all views of the information
177177
<%= portfolio_design.include_erb("idl_func_appendix.adoc.erb") %>
178178

179179
<<<
180-
<% puts "UPDATE: Including riscv-unprivileged.adoc" -%>
180+
<% $logger.info "Including riscv-unprivileged.adoc" -%>
181181
// Reset chapter numbering
182182
:!chapter-number:
183183
include::ext/riscv-isa-manual/src/riscv-unprivileged.adoc[]
184184

185185
<<<
186-
<% puts "UPDATE: Including riscv-privileged.adoc" -%>
186+
<% $logger.info "Including riscv-privileged.adoc" -%>
187187
// Reset chapter numbering
188188
:!chapter-number:
189189
include::ext/riscv-isa-manual/src/riscv-privileged.adoc[]

0 commit comments

Comments
 (0)