Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 84347e7

Browse files
author
Oleg Gurov
committed
added relative error calculation
1 parent e6ba1e7 commit 84347e7

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

pghrep/templates/K003.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ End: {{ (index (index (index .results .hosts.master) "data") "end_timestamptz")
88
Period seconds: {{ (index (index (index .results .hosts.master) "data") "period_seconds") }}
99
Period age: {{ (index (index (index .results .hosts.master) "data") "period_age") }}
1010

11-
Absolute error (calls): {{ (index (index (index .results .hosts.master) "data") "absolute_error_calls") }}
12-
Absolute error (total time): {{ (index (index (index .results .hosts.master) "data") "absolute_error_total_time") }}
11+
Error (calls): {{ NumFormat (index (index (index .results .hosts.master) "data") "absolute_error_calls") 2 }} ({{ NumFormat (index (index (index .results .hosts.master) "data") "relative_error_calls") 2 }}%)
12+
Error (total time): {{ NumFormat (index (index (index .results .hosts.master) "data") "absolute_error_total_time") 2 }} ({{ NumFormat (index (index (index .results .hosts.master) "data") "relative_error_total_time") 2 }}%)
1313

1414
\# | Calls | Total time | Rows | shared_blks_hit | shared_blks_read | shared_blks_dirtied | shared_blks_written | blk_read_time | blk_write_time | kcache_reads | kcache_writes | kcache_user_time_ms | kcache_system_time | Query
1515
----|-------|------------|------|-----------------|------------------|---------------------|---------------------|---------------|----------------|--------------|---------------|---------------------|--------------------|-------

resources/checks/K003_top_total_time.sh

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,25 @@ sql="
285285
key
286286
from sum_s2
287287
join sum_si_s2 using (key)
288-
), absolute_error as ( -- absolute error with respect to calls metric is calculated as: (diff1(calls) + diff2(calls)) / 2
289-
select
290-
(diff1.sum_calls + diff2.sum_calls)::numeric / 2 as sum_calls,
291-
(diff1.sum_total_time + diff2.sum_total_time)::numeric / 2 as sum_total_time
292-
from diff1
293-
join diff2 using (key)
288+
), diff_calc_rel_err as (
289+
select
290+
abs(sum_si_s2.sum_calls - sum_si_s1.sum_calls) as sum_calls,
291+
abs(sum_si_s2.sum_total_time - sum_si_s1.sum_total_time) as sum_total_time,
292+
key
293+
from sum_si_s2
294+
join sum_si_s1 using (key)
295+
), calc_error as ( -- absolute error with respect to calls metric is calculated as: (diff1(calls) + diff2(calls)) / 2
296+
select
297+
(diff1.sum_calls + diff2.sum_calls)::numeric / 2 as absolute_error_calls,
298+
(diff1.sum_total_time + diff2.sum_total_time)::numeric / 2 as absolute_error_total_time,
299+
case when (select sum_calls from diff_calc_rel_err) = 0 then 0 else
300+
(((diff1.sum_calls + diff2.sum_calls) / 2) * 100) / (select sum_calls from diff_calc_rel_err)
301+
end as relative_error_calls,
302+
case when (select sum_total_time from diff_calc_rel_err) = 0 then 0 else
303+
(((diff1.sum_total_time + diff2.sum_total_time) / 2) * 100) / (select sum_total_time from diff_calc_rel_err)
304+
end as relative_error_total_time
305+
from diff1
306+
join diff2 using (key)
294307
), sum_delta as (
295308
select
296309
${sub_sql_sum_delta}
@@ -316,8 +329,10 @@ sql="
316329
'end_timestamptz'::text, (select j->'snapshot_timestamptz' from snap2),
317330
'period_seconds'::text, ( select (snap2.j->>'snapshot_timestamptz_s')::numeric - (snap1.j->>'snapshot_timestamptz_s')::numeric from snap1, snap2 ),
318331
'period_age'::text, ( select (snap2.j->>'snapshot_timestamptz')::timestamptz - (snap1.j->>'snapshot_timestamptz')::timestamptz from snap1, snap2 ),
319-
'absolute_error_calls'::text, (select sum_calls from absolute_error),
320-
'absolute_error_total_time'::text, (select sum_total_time from absolute_error),
332+
'absolute_error_calls'::text, (select absolute_error_calls from calc_error),
333+
'absolute_error_total_time'::text, (select absolute_error_total_time from calc_error),
334+
'relative_error_calls'::text, (select relative_error_calls from calc_error),
335+
'relative_error_total_time'::text, (select relative_error_total_time from calc_error),
321336
'queries', json_object_agg(queries.rownum, queries.*)
322337
)
323338
from queries

0 commit comments

Comments
 (0)