Skip to content

Commit 9992d2c

Browse files
committed
Add simple tracer
1 parent 13ab747 commit 9992d2c

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Gemfile.lock

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ GEM
2525
csv (3.3.0)
2626
drb (2.2.1)
2727
ffi (1.17.1)
28-
ffi (1.17.1-aarch64-linux-gnu)
29-
ffi (1.17.1-aarch64-linux-musl)
30-
ffi (1.17.1-arm-linux-gnu)
31-
ffi (1.17.1-arm-linux-musl)
32-
ffi (1.17.1-arm64-darwin)
33-
ffi (1.17.1-x86-linux-gnu)
34-
ffi (1.17.1-x86-linux-musl)
35-
ffi (1.17.1-x86_64-darwin)
36-
ffi (1.17.1-x86_64-linux-gnu)
37-
ffi (1.17.1-x86_64-linux-musl)
3828
fileutils (1.7.2)
3929
i18n (1.14.6)
4030
concurrent-ruby (~> 1.0)

lib/wardite.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,19 @@ def invoke_internal(wasm_function)
362362
return nil
363363
end
364364

365+
$GLOBAL_EXTERNAL_ELAP = 0.0 #: Float
366+
$GLOBAL_EXTERNAL_TIMES = 0 #: Integer
367+
END {
368+
if ENV["WARDITE_TRACE"] == "1"
369+
$stderr.puts "external call count: #{$GLOBAL_EXTERNAL_TIMES}"
370+
$stderr.puts "external call elapsed: #{$GLOBAL_EXTERNAL_ELAP}(s)"
371+
end
372+
}
373+
365374
# @rbs external_function: ExternalFunction
366375
# @rbs return: wasmValue|nil
367376
def invoke_external(external_function)
377+
start = Time.now.to_f
368378
$stderr.puts "[trace] call external function: #{external_function.name}" if ENV["WARDITE_TRACE"]
369379
local_start = stack.size - external_function.callsig.size
370380
args = stack[local_start..]
@@ -399,6 +409,9 @@ def invoke_external(external_function)
399409
end
400410

401411
raise "invalid type of value returned in proc. val: #{val.inspect}"
412+
ensure
413+
$GLOBAL_EXTERNAL_TIMES += 1
414+
$GLOBAL_EXTERNAL_ELAP += (Time.now.to_f - start)
402415
end
403416

404417
# @rbs return: void

lib/wardite/load.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ module BinaryLoader
254254
# @rbs enable_wasi: boolish
255255
# @rbs return: Instance
256256
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true)
257+
start = Time.now.to_f #: Float
257258
@buf = buf
258259

259260
version = preamble
@@ -273,6 +274,8 @@ def self.load_from_buffer(buf, import_object: {}, enable_wasi: true)
273274
i.wasi = wasi_env
274275
end
275276
end
277+
ensure
278+
$stderr.puts "load_from_buffer: #{Time.now.to_f - start}" if ENV['WARITE_TRACE']
276279
end
277280

278281
# @rbs return: Integer

0 commit comments

Comments
 (0)