/
calls_legacy.ex
34 lines (31 loc) · 1.06 KB
/
calls_legacy.ex
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
defmodule EctoPSQLExtras.CallsLegacy do
@behaviour EctoPSQLExtras
def info do
%{
title: "Queries that have the highest frequency of execution",
order_by: [calls: :desc],
default_args: [limit: 10],
columns: [
%{name: :query, type: :string},
%{name: :exec_time, type: :interval},
%{name: :prop_exec_time, type: :percent},
%{name: :calls, type: :integer},
%{name: :sync_io_time, type: :interval}
]
}
end
def query(args \\ []) do
"""
/* ECTO_PSQL_EXTRAS: Queries that have the highest frequency of execution */
SELECT query AS query,
interval '1 millisecond' * total_time AS exec_time,
(total_time/sum(total_time) OVER()) AS exec_time_ratio,
calls,
interval '1 millisecond' * (blk_read_time + blk_write_time) AS sync_io_time
FROM pg_stat_statements WHERE userid = (SELECT usesysid FROM pg_user WHERE usename = current_user LIMIT 1)
AND query NOT LIKE '/* ECTO_PSQL_EXTRAS:%'
ORDER BY calls DESC
LIMIT <%= limit %>;
""" |> EEx.eval_string(args)
end
end