Skip to content

Commit 282e6ea

Browse files
committed
Label DbConnection's own processes
1 parent f6d0916 commit 282e6ea

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

lib/db_connection/connection.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ defmodule DBConnection.Connection do
4848
@doc false
4949
@impl :gen_statem
5050
def init({mod, opts, pool, tag}) do
51+
pool_index = Keyword.get(opts, :pool_index)
52+
label = if pool_index, do: "db_conn_#{pool_index}", else: "db_conn"
53+
Util.set_label(label)
54+
5155
s = %{
5256
mod: mod,
5357
opts: opts,

lib/db_connection/ownership/proxy.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ defmodule DBConnection.Ownership.Proxy do
2222

2323
@impl true
2424
def init({caller, pool, pool_opts}) do
25+
Util.set_label("db_ownership_proxy")
26+
2527
pool_opts =
2628
pool_opts
2729
|> Keyword.put(:timeout, :infinity)

lib/db_connection/task.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ defmodule DBConnection.Task do
1313
end
1414

1515
def init(fun, parent, opts) do
16+
DBConnection.Util.set_label("db_after_connect_task")
17+
1618
try do
1719
Process.link(parent)
1820
catch

lib/db_connection/util.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ defmodule DBConnection.Util do
1313
end
1414
end
1515

16+
@doc """
17+
Set a process label if `Process.set_label/1` is available.
18+
"""
19+
def set_label(label) do
20+
if function_exported?(Process, :set_label, 1) do
21+
Process.set_label(label)
22+
else
23+
:ok
24+
end
25+
end
26+
27+
# Get a process label if `:proc_lib.get_label/1` is available.
1628
defp get_label(pid) do
1729
if function_exported?(:proc_lib, :get_label, 1) do
1830
# Avoid a compiler warning if the function isn't

0 commit comments

Comments
 (0)