CREATE EXTENSION pg_stat_monitor;
SET pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS
$$
BEGIN
	return (select $1 + $2);
END; $$ language plpgsql;
CREATE OR REPLACE FUNCTION add2(int, int) RETURNS INTEGER AS
$$
BEGIN
	return add($1,$2);
END;
$$ language plpgsql;
SELECT add2(1,2);
 add2 
------
    3
(1 row)

SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
                            query                             |     top_query     
--------------------------------------------------------------+-------------------
 CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS +| 
 $$                                                          +| 
 BEGIN                                                       +| 
         return (select $1 + $2);                            +| 
 END; $$ language plpgsql                                     | 
 CREATE OR REPLACE FUNCTION add2(int, int) RETURNS INTEGER AS+| 
 $$                                                          +| 
 BEGIN                                                       +| 
         return add($1,$2);                                  +| 
 END;                                                        +| 
 $$ language plpgsql                                          | 
 SELECT (select NULL + NULL)                                  | SELECT add2(1,2);
 SELECT add2(1,2)                                             | 
 SELECT pg_stat_monitor_reset()                               | 
(5 rows)

SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

DROP EXTENSION pg_stat_monitor;
