Current section

8 Versions

Jump to

Compare versions

6 files changed
+39 additions
-34 deletions
  @@ -1,6 +1,8 @@
1 1 # OrionCollector
2 2
3 - **TODO: Add description**
3 + This is the library handling the tracing for Orion.
4 +
5 + May be rewritten in erlang in the future.
4 6
5 7 ## Installation
6 8
  @@ -10,7 +12,7 @@ by adding `orion_collector` to your list of dependencies in `mix.exs`:
10 12 ```elixir
11 13 def deps do
12 14 [
13 - {:orion_collector, "~> 0.1.0"}
15 + {:orion_collector, "~> 1.0.0"}
14 16 ]
15 17 end
16 18 ```
  @@ -19,3 +21,6 @@ Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_do
19 21 and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20 22 be found at [https://hexdocs.pm/orion_collector](https://hexdocs.pm/orion_collector).
21 23
24 + ## TODO
25 +
26 + * [ ] add tests
  @@ -22,4 +22,4 @@
22 22 {<<"optional">>,false},
23 23 {<<"repository">>,<<"hexpm">>},
24 24 {<<"requirement">>,<<"~> 1.6">>}]]}.
25 - {<<"version">>,<<"0.1.0">>}.
25 + {<<"version">>,<<"1.0.0">>}.
  @@ -1,18 +1,10 @@
1 1 defmodule OrionCollector do
2 2 @moduledoc """
3 - Documentation for `OrionCollector`.
3 + OrionCollector is a child of Orion.
4 +
5 + It only exist in order to separate collecting the traces in each nodes from
6 + Orion.
7 +
8 + All these API are considered private.
4 9 """
5 -
6 - @doc """
7 - Hello world.
8 -
9 - ## Examples
10 -
11 - iex> OrionCollector.hello()
12 - :world
13 -
14 - """
15 - def hello do
16 - :world
17 - end
18 10 end
  @@ -8,8 +8,7 @@ defmodule OrionCollector.Application do
8 8 @impl true
9 9 def start(_type, _args) do
10 10 children = [
11 - {DynamicSupervisor, strategy: :one_for_one, name: OrionCollector.TracerSupervisor},
12 - %{id: :pg, start: {:pg, :start_link, []}, type: :supervisor}
11 + {DynamicSupervisor, strategy: :one_for_one, name: OrionCollector.TracerSupervisor}
13 12
14 13 # Starts a worker by calling: OrionCollector.Worker.start_link(arg)
15 14 # {OrionCollector.Worker, arg}
  @@ -2,12 +2,19 @@ defmodule OrionCollector.Tracer do
2 2 use GenServer
3 3 import Ex2ms
4 4
5 - def start_all_node_tracers(mfa, self) do
5 + def start_all_node_tracers(mfa, self, start_status \\ :running) do
6 6 if self do
7 - OrionCollector.Tracer.start_tracer(mfa, self())
7 + OrionCollector.Tracer.start_tracer(mfa, self(), start_status)
8 8 end
9 9
10 - :erpc.multicall(list_nodes(), OrionCollector.Tracer, :start_tracer, [mfa, self()], 5_000)
10 + :erpc.multicall(
11 + list_nodes(),
12 + OrionCollector.Tracer,
13 + :start_tracer,
14 + [mfa, self(), start_status],
15 + 5_000
16 + )
17 +
11 18 :ok
12 19 end
13 20
  @@ -17,29 +24,29 @@ defmodule OrionCollector.Tracer do
17 24
18 25 def pause_trace(mfa, self) do
19 26 if self do
20 - :erlang.trace_pattern(mfa, false, [])
27 + :erlang.trace_pattern(mfa, false, [:local])
21 28 end
22 29
23 - :erpc.multicall(list_nodes(), :erlang, :trace_pattern, [mfa, false, []], 5_000)
30 + :erpc.multicall(list_nodes(), :erlang, :trace_pattern, [mfa, false, [:local]], 5_000)
24 31 end
25 32
26 33 def restart_trace(mfa, self) do
27 34 if self do
28 - :erlang.trace_pattern(mfa, [match_spec()], [:local])
35 + :erlang.trace_pattern(mfa, match_spec(), [:local])
29 36 end
30 37
31 38 :erpc.multicall(
32 39 list_nodes(),
33 40 :erlang,
34 41 :trace_pattern,
35 - [mfa, [match_spec()], [:local]],
42 + [mfa, match_spec(), [:local]],
36 43 5_000
37 44 )
38 45 end
39 46
40 - def start_tracer(mfa, pid) do
41 - spec = {OrionCollector.Tracer, [mfa, pid]}
42 - DynamicSupervisor.start_child(OrionCollector.TracerSupervisor, spec)
47 + def start_tracer(mfa, pid, start_status) do
48 + spec_args = {OrionCollector.Tracer, [mfa, pid, start_status]}
49 + DynamicSupervisor.start_child(OrionCollector.TracerSupervisor, spec_args)
43 50 end
44 51
45 52 def stop(pid) do
  @@ -58,13 +65,15 @@ defmodule OrionCollector.Tracer do
58 65 }
59 66 end
60 67
68 + # --PRIVATE--
61 69 @impl true
62 - def init([mfa, pid]) do
63 - :pg.join({Orion, mfa}, self())
64 -
70 + def init([mfa, pid, start_status]) do
65 71 mon_ref = Process.monitor(pid)
66 72
67 - :erlang.trace_pattern(mfa, match_spec(), [:local])
73 + if start_status == :running do
74 + :erlang.trace_pattern(mfa, match_spec(), [:local])
75 + end
76 +
68 77 :erlang.trace(:all, true, [:call, :arity, :timestamp])
69 78
70 79 Process.send_after(self(), :send_data, 500)
Loading more files…