VistualCall 一个生成调用图谱的 gem

2023-04-24 23:04:23 +08:00
 Mark24

做一个可视化追踪调用的 gem ,比较粗糙,分享下。

项目地址: https://github.com/Mark24Code/vistual_call


VistualCall

VistualCall is a gem to help you trace your code and export beautiful vistual call graph.

Introduction

Dependency

  1. Graphviz

You need to install Graphviz by yourself.

Go to install graphviz.

Usage

1. Install gem

gem install vistual_call

2. Only the method needs to be wrapped.

require 'vistual_call'

def call_c
end

def call_b
  call_c
end

def call_a
  call_b
end

VistualCall.trace do
  call_a # enter call
end

The method after each node is call order number. This will help your understand the order of the function call.

Sinatra

3. More information

configuration

# you can pass options
VistualCall.trace(options) do
  # run your code here...
end

Options:

name type required explain example
label String true 标题 Hello
labelloc Symbol false 标题位置: :top :bottom :center :top
labeljust Symbol false 标题对齐位置 :left, :center, :right :center
direction Symbol false 绘制方向,依次是 :TB(从上到下),:LR(从左到右,默认方式),:BT(从下到上),:RL(从右到左) :LR
format String false 输出图片格式,查看 graphviz 支持输出格式 'png'、'svg' 默认 'png'
output String false 导出图片绝对路径 默认家目录下 vistual_call_result.png
theme Symbol false 配色主题 :sky, :lemon 默认 :sky
show_dot boolean false 展示 dot 内容 默认 false
show_order_number boolean false 输出调用序号 默认 true
jump_list Array(String) false 跳过节点,默认 ["Kernel#class", "Kernel#frozen?"] -
heightlight_match Regex false 默认高亮匹配 label , 默认 /method_missing/ /method_missing/

LICENSE

The gem is available as open source under the terms of the MIT License.

510 次点击
所在节点    分享发现
1 条回复
Mark24
2023-04-25 14:01:31 +08:00
用 vistual_call 分析 vistual_call 自己

```ruby
require_relative "vistual_call"

def call_a
end

VistualCall.trace(title: "Outer", show_dot: true) do
VistualCall.trace(title: "Inner", show_dot: true) do
call_a # whatever
end
end
```

![]( https://l.ruby-china.com/photo/Mark24/8456f872-039b-49bf-87a5-b3e43e874e27.jpg!large)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/935189

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX