TopSQL,計算某條sql的CPU time.
select aa.*,
(select sql_text from perfstat.top_sql_monitor where aa.hash_value = perfstat.top_sql_monitor.hash_value and rownum =1 and
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
) sql_text
,(select b.username from perfstat.top_sql_monitor, dba_users b where aa.hash_value = perfstat.top_sql_monitor.hash_value and rownum =1 and
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
and perfstat.top_sql_monitor.parsing_user_id = b.user_id
) parsing_user_id
from (
select hash_value, round(sum(cpu_time)/1000000,0) "cpu_time(s)"
, round(sum(total_cpu_time)/1000000,0) "total_cpu_time(s)"
--, round(sum(total_cpu_time)/1000000/15/60,0) "cpu_time_ps(s)"
, round(sum(total_cpu_time)/1000000/60/60,0) "cpu_time_ps(s)"
, round(sum(cpu_time)/sum(total_cpu_time),3) "percent_cpu_time(s)"
, round(sum(elapsed_time)/1000000,1) "elapsed_time(s)", sum(executions) executions, sum(buffer_gets) buffer_gets, sum(disk_reads) disk_reads from (select
s.snap_time,
s.hash_value,
decode(sign(cpu_time - lag(cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
cpu_time,
cpu_time - lag(cpu_time, 1) over(partition by hash_value order by s.snap_time )) as cpu_time,
decode(sign(total_cpu_time - lag(total_cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
total_cpu_time,
total_cpu_time - lag(total_cpu_time, 1) over(partition by hash_value order by s.snap_time )) as total_cpu_time,
decode(sign(s.executions - lag(executions, 1)
over(partition by hash_value order by s.snap_time )),
-1,
executions,
s.executions - lag(executions, 1) over(partition by hash_value order by s.snap_time)) as executions,
decode(sign(s.elapsed_time - lag(elapsed_time, 1)
over(partition by hash_value order by s.snap_time)),
-1,
elapsed_time,
s.elapsed_time - lag(elapsed_time, 1) over(partition by hash_value order by s.snap_time)) as elapsed_time,
decode(sign(s.buffer_gets - lag(buffer_gets, 1)
over(partition by hash_value order by s.snap_time )),
-1,
buffer_gets,
s.buffer_gets - lag(buffer_gets, 1) over(partition by hash_value order by s.snap_time)) as buffer_gets,
decode(sign(s.disk_reads - lag(disk_reads, 1)
over(partition by hash_value order by s.snap_time )),
-1,
disk_reads,
s.disk_reads - lag(disk_reads, 1) over(partition by hash_value order by s.snap_time )) as disk_reads,
decode(sign(s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )),
-1,
fetches,
s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )) as fetches,
decode(sign(s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )),
-1,
sorts,
s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )) as sorts
from perfstat.top_sql_monitor s
where
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
--and parsing_user_id = 97
) where executions is not null
group by hash_value
order by 2 desc ) aa where rownum <1000
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
) sql_text
,(select b.username from perfstat.top_sql_monitor, dba_users b where aa.hash_value = perfstat.top_sql_monitor.hash_value and rownum =1 and
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
and perfstat.top_sql_monitor.parsing_user_id = b.user_id
) parsing_user_id
from (
select hash_value, round(sum(cpu_time)/1000000,0) "cpu_time(s)"
, round(sum(total_cpu_time)/1000000,0) "total_cpu_time(s)"
--, round(sum(total_cpu_time)/1000000/15/60,0) "cpu_time_ps(s)"
, round(sum(total_cpu_time)/1000000/60/60,0) "cpu_time_ps(s)"
, round(sum(cpu_time)/sum(total_cpu_time),3) "percent_cpu_time(s)"
, round(sum(elapsed_time)/1000000,1) "elapsed_time(s)", sum(executions) executions, sum(buffer_gets) buffer_gets, sum(disk_reads) disk_reads from (select
s.snap_time,
s.hash_value,
decode(sign(cpu_time - lag(cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
cpu_time,
cpu_time - lag(cpu_time, 1) over(partition by hash_value order by s.snap_time )) as cpu_time,
decode(sign(total_cpu_time - lag(total_cpu_time, 1) over( partition by hash_value order by s.snap_time )),
-1,
total_cpu_time,
total_cpu_time - lag(total_cpu_time, 1) over(partition by hash_value order by s.snap_time )) as total_cpu_time,
decode(sign(s.executions - lag(executions, 1)
over(partition by hash_value order by s.snap_time )),
-1,
executions,
s.executions - lag(executions, 1) over(partition by hash_value order by s.snap_time)) as executions,
decode(sign(s.elapsed_time - lag(elapsed_time, 1)
over(partition by hash_value order by s.snap_time)),
-1,
elapsed_time,
s.elapsed_time - lag(elapsed_time, 1) over(partition by hash_value order by s.snap_time)) as elapsed_time,
decode(sign(s.buffer_gets - lag(buffer_gets, 1)
over(partition by hash_value order by s.snap_time )),
-1,
buffer_gets,
s.buffer_gets - lag(buffer_gets, 1) over(partition by hash_value order by s.snap_time)) as buffer_gets,
decode(sign(s.disk_reads - lag(disk_reads, 1)
over(partition by hash_value order by s.snap_time )),
-1,
disk_reads,
s.disk_reads - lag(disk_reads, 1) over(partition by hash_value order by s.snap_time )) as disk_reads,
decode(sign(s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )),
-1,
fetches,
s.fetches - lag(fetches, 1) over(partition by hash_value order by s.snap_time )) as fetches,
decode(sign(s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )),
-1,
sorts,
s.sorts - lag(sorts, 1) over(partition by hash_value order by s.snap_time )) as sorts
from perfstat.top_sql_monitor s
where
snap_time between to_date('2012-04-20 10:35:00','yyyy-mm-dd hh24:mi:ss') and to_date('2012-04-20 11:36:00','yyyy-mm-dd hh24:mi:ss')
--and parsing_user_id = 97
) where executions is not null
group by hash_value
order by 2 desc ) aa where rownum <1000
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-745277/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 批次殺執行某條sql的sessionSQLSession
- 一條主鍵索引SQL導致的CPU被打滿索引SQL
- SQL 有序計算SQL
- 詳述一條SQL引發的高CPU故障處理過程SQL
- SQL 的後計算指令碼SQL指令碼
- SQL 轉置計算SQL
- [20190821]關於CPU成本計算.txt
- 【SQL】SQL中if條件的使用SQL
- 計算兩條直線的交點
- mac的cpu某段時間佔用很高Mac
- [20211009]使用bash計算sql語句的sql_id.txtSQL
- 什麼是計算機 cpu 的地址匯流排?計算機
- 一條 sql 瞭解 MYSQL 的架構設計MySql架構
- 一條sql瞭解MYSQL的架構設計MySql架構
- postgresql定位top cpu sqlSQL
- 檢視sqlserver的某程式的sql文字SQLServer
- [20191101]通過zsh計算sql語句的sql_id.txtSQL
- [20191011]通過bash計算sql語句的sql_id.txtSQL
- [20190823]關於CPU成本計算2.txt
- Windows 平臺計算 CPU 總利用率Windows
- MySQL 5.7定位消耗CPU高的SQLMySql
- 985計算機院倒數第一某廢物的自述計算機
- GaussDB(DWS)運維利刃:TopSQL工具解析運維SQL
- 查詢過去一段時間內某條sql使用的臨時表空間大小SQL
- 幽默:偏愛某種計算機語言的程式設計師簡稱計算機程式設計師
- SQL面試必考——計算留存率SQL面試
- SQL Server各種日期計算方法SQLServer
- 搭建異構 CPU 組成的邊緣計算 Kubernetes 叢集
- C#使用ManagementObjectSearcher獲取本計算機CPU,硬碟,記憶體條等相關裝置資訊C#Object計算機硬碟記憶體
- Flink流計算中SQL表的概念和原理SQL
- Oracle優化案例-緊急處理一條sql引起cpu使用率99%的問題(十六)Oracle優化SQL
- 查詢固定條數的某個值之和
- sql 判斷 某列中是否包含 某種符號SQL符號
- SQL-基礎語法 - 條件查詢 - 邏輯運算SQL
- 公司某資料子系統定期cpu過高的診斷
- PL/SQL 條件SQL
- 如何分析一條sql的效能SQL
- SQL2008查詢某資料庫中的某個值是否存在SQL資料庫
- CPU視覺化:開啟計算機智慧之源的新篇章視覺化計算機