Skip to content

Commit

Permalink
feature(compiler tracers): Add tracing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoch-cars committed Aug 10, 2022
1 parent 010f1ee commit b6541cf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
21 changes: 21 additions & 0 deletions lib/ex_factor/server.ex
@@ -0,0 +1,21 @@
defmodule ExFactor.Server do
use Agent

def start_link(_module) do
Agent.start_link(fn -> %{module: __MODULE__, entries: %{}} end, name: __MODULE__)
end

def record(type, file, line, column, module, name, arity, _context_modules, caller_module) do
Agent.update(__MODULE__, fn state ->
entry = {type, line, column, module, name, arity}

Map.update!(state, :entries, fn entries ->
Map.update(entries, {file, caller_module}, [entry], &[entry | &1])
end)
end)
end

def entries() do
Agent.get(__MODULE__, & &1.entries)
end
end
30 changes: 15 additions & 15 deletions mix.exs
@@ -1,22 +1,22 @@
defmodule ExFactor.Tracer do
@trace_types ~w(import imported_function alias alias_expansion alias_reference require struct_expansion remote_function local_function)a
def trace({type, meta, module, name, arity}, env) when type in @trace_types do
content = """
ExFactor.Tracer mix.exs
type: #{type}
meta: #{inspect(meta)}
traced_module: #{module}
name: #{name}
arity: #{arity}
filepath: #{env.file}
context_modules: #{inspect(env.context_modules)}
caller_module: #{env.module}
>>>>>>>>>>>>>>>>>>>>VVVVVVVVV<<<<<<<<<<<<<<<<<<<<<
ExFactor.Server.record(type, env.file, meta[:line], meta[:column], module, name, arity, env.context_modules, env.module)
# content = """
# ExFactor.Tracer mix.exs
# type: #{type}
# meta: #{inspect(meta)}
# traced_module: #{module}
# name: #{name}
# arity: #{inspect(arity)}
# filepath: #{env.file}
# context_modules: #{inspect(env.context_modules)}
# caller_module: #{env.module}

"""
File.mkdir_p!("./tmp")
File.touch!("./tmp/traces")
File.write!("./tmp/traces", content, [:append])
# """
# File.mkdir_p!("./tmp")
# File.touch!("./tmp/traces")
# File.write!("./tmp/traces", content, [:append])
:ok
end

Expand Down

0 comments on commit b6541cf

Please sign in to comment.