-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
46 lines (34 loc) · 1.06 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$LOAD_PATH.unshift("#{File.expand_path(File.dirname(__FILE__))}/lib")
require 'sinatra'
require 'kefka'
require 'yajl'
require 'yajl/json_gem'
get '/' do
erb :index
end
get '/callgraph' do
content_type :json
file_path = "#{File.expand_path(File.dirname(__FILE__))}/examples/sample_a.rb"
@tracer = Kefka::Tracer.new(Logger::INFO)
@tracer.trace(file_path)
# input code
#input = CodeRay.scan(@tracer.code, :ruby).div(:line_numbers => :table)
method_graph = @tracer.method_graph
# output call graph using dot if graphviz is installed
#if is_graphviz_installed = system("which dot")
# method_graph.write_to_graphic_file("png", "#{File.expand_path(File.dirname(__FILE__))}/public/graph")
#end
# html code graph
method_graph.vertices.each { |method| method.format = :html }
# line graph
line_graph = @tracer.line_graph
# locals
locals = @tracer.local_values
{
#:input => input,
#:is_graphviz_installed => is_graphviz_installed,
:vertices => method_graph.vertices,
:edges => line_graph.edges,
:locals => locals
}.to_json
end