#!/usr/bin/env ruby require 'pathname' $LOAD_PATH << Pathname(__dir__) + "../lib" require 'steep' require "fileutils" require "optparse" puts <> Loading RBS files..." env = command.load_signatures() puts ">> Type checking files with #{profile_mode}..." typings = nil GC.start(immediate_sweep: true, immediate_mark: true, full_mark: true) # GC.config[:rgengc_allow_major_gc] = false case profile_mode when :vernier require "vernier" out = Pathname.pwd + "tmp/typecheck-#{Process.pid}.vernier.json" puts ">> Profiling with vernier: #{out}" Vernier.profile(out: out.to_s) do typings = command.type_check_files(command_line_args, env) end when :memory require 'memory_profiler' out = Pathname.pwd + "tmp/typecheck-#{Process.pid}.memory.txt" puts ">> Profiling with memory_profiler: #{out}" classes = nil report = MemoryProfiler.report(trace: classes) do typings = command.type_check_files(command_line_args, env) end report.pretty_print(to_file: out, detailed_report: true, scale_bytes: true, retained_strings: false, allocated_strings: false) when :memory2 require_relative 'mem_prof' out = Pathname.pwd + "tmp/typecheck-#{Process.pid}.memory2.csv" puts ">> Profiling with mem_prof: #{out}" generation = nil out.open("w") do |io| MemProf.trace(io: io) do generation = GC.count typings = command.type_check_files(command_line_args, env) end end require_relative 'mem_graph' graph = MemGraph.new(generation) ObjectSpace.each_object do |obj| if ObjectSpace.allocation_generation(obj) == generation graph.traverse(obj) end end (Pathname.pwd + "objects-#{Process.pid}.dot").write(graph.dot) when :stackprof require "stackprof" out = Pathname.pwd + "tmp/typecheck-#{Process.pid}.stackprof" puts ">> Profiling with stackprof: #{out}" StackProf.run(out: out, raw: true, interval: 1000) do typings = command.type_check_files(command_line_args, env) end when :majo require "majo" out = Pathname.pwd + "tmp/typecheck-#{Process.pid}.majo.csv" puts ">> Profiling with majo: #{out}" result = Majo.run do typings = command.type_check_files(command_line_args, env) end out.open("w") do |io| result.report(out: io, formatter: :csv) end when :dumpall require "objspace" out = Pathname.pwd + "tmp/dumpall-#{Process.pid}.json" puts ">> Profiling with dumpall: #{out}" ObjectSpace.trace_object_allocations_start typings = command.type_check_files(command_line_args, env) out.open('w+') do |io| ObjectSpace.dump_all(output: io) end when :none pp rbs_method_types: ObjectSpace.each_object(RBS::MethodType).count GC.start(immediate_sweep: true, immediate_mark: true, full_mark: true) pp defs: ObjectSpace.each_object(RBS::AST::Members::MethodDefinition).count pp aliases: ObjectSpace.each_object(RBS::AST::Members::Alias).count pp attr_reader: ObjectSpace.each_object(RBS::AST::Members::AttrReader).count pp attr_writer: ObjectSpace.each_object(RBS::AST::Members::AttrWriter).count pp attr_accessor: ObjectSpace.each_object(RBS::AST::Members::AttrAccessor).count Steep.measure("type check", level: :fatal) do GC.disable typings = command.type_check_files(command_line_args, env) pp steep_method_types: ObjectSpace.each_object(Steep::Interface::MethodType).count, rbs_method_types: ObjectSpace.each_object(RBS::MethodType).count pp any: ObjectSpace.each_object(Steep::AST::Types::Any).count, void: ObjectSpace.each_object(Steep::AST::Types::Void).count, self: ObjectSpace.each_object(Steep::AST::Types::Self).count end end typings.size