性能堆分析思路

1、通過top找到對應的耗費資源比較大的進程ID,

2、ps p 進程ID -L -o pcpu,pid,tid,time,tname,cmd

3、然后利用上面面命令來找到對應的線程

4、利用Listthread方法 列出所有線程,與找到對應資源比較大的匹配

5、利用stack查找到對應的堆棧調用代碼,來分析到具體什么位置導致的

public void ListThread()
?? ?{?
?? ?String pid=?? ?querytopCPU();?
?? ? ?String cmd2="jstack -l "+pid;
?? ??? ?Map<String,String> mssrg=nid(cmd2);
?? ??? ?ThreadGroup group = Thread.currentThread().getThreadGroup(); ?
?? ??? ?ThreadGroup topGroup = group; ?
?? ??? ?// 遍歷線程組樹,獲取根線程組 ?
?? ??? ?while (group != null) { ?
?? ??? ? ? ?topGroup = group; ?
?? ??? ? ? ?group = group.getParent(); ?
?? ??? ?} ?
?? ??? ?// 激活的線程數加倍 ?
?? ??? ?int estimatedSize = topGroup.activeCount() * 2; ?
?? ??? ?Thread[] slackList = new Thread[estimatedSize]; ?
?? ??? ?// 獲取根線程組的所有線程 ?
?? ??? ?int actualSize = topGroup.enumerate(slackList); ?
?? ??? ?// copy into a list that is the exact size ?
?? ??? ?Thread[] list = new Thread[actualSize]; ??
?? ??? ?java.lang.System.arraycopy(slackList, 0, list, 0, actualSize); ?
?? ??? ?java.lang.System.out.println("Thread list size == " + list.length); ?
?? ??? ?for (Thread thread : list) { ?
?? ??? ??? ?java.lang.System.out.println(thread.getName()); ?
?? ??? ?} ??
?? ??? ?
?? ??? ?int i=0;?
?? ??? ?List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>(); ?
?? ??? ?for(Thread t :?? ? list){
?? ??? ?Map<String, Object>?? ?imap = new HashMap<String, Object>();
?? ??? ? ? ?imap.put("id", t.getId());
?? ??? ??? ?imap.put("name", t.getName());
?? ??? ??? ?imap.put("state", t.getState());
?? ??? ??? ?imap.put("whofirst",t.getPriority());
?? ??? ??? ?imap.put("groupname",t.getThreadGroup().getName());
?? ??? ??? ?imap.put("pid",pid);
?? ??? ??? ?String tid="";
?? ??? ??? ?
?? ? ? ? ?? ?for (Entry<String, String> entry : mssrg.entrySet()) {
?? ? ? ? ??? ??? ?
? ? ?? ??? ??? ?String key = (String) entry.getKey();
? ? ?? ??? ??? ?String value = (String) entry.getValue();
? ? ?? ??? ??? ?if(value.indexOf(t.getName())>-1)
? ? ?? ??? ??? ?{?
? ? ?? ??? ??? ??? ?tid=key;
? ? ?? ??? ??? ?}
? ? ?? ??? ??
? ? ? ?? ?}
?? ??? ??? ?//
?? ??? ??? ?
?? ??? ??? ?imap.put("tid",tid);
?? ??? ??? ?String stname="";
?? ??? ??? ?if(t.getStackTrace().length>0)
?? ??? ??? ?{
? ? ? ? ? ? ? ? stname+="ClassName:"+ste.getClassName()+",FileName:"+ste.getFileName()+",Method:"+ste.getMethodName()+",LineNum:"+ste.getLineNumber();
//?? ??? ??? ??? ?}
?? ??? ??? ??? ?stname=t.getStackTrace()[t.getStackTrace().length-1].getFileName()+",LineNum:"+t.getStackTrace()[t.getStackTrace().length-1].getLineNumber();
?? ??? ??? ?}
?? ??? ??? ?imap.put("stack",stname);
?? ??? ??? ?list2.add(imap);
?? ??
?? ??? ?}?
?? ??? ?// 將查詢的數據返回到前臺
?? ??? ?sendMsg(JSONTool.convertCollection2Json(list2));?? ?
?? ?}

?

?

public String querytopCPU()
?? ?{
?? ??? ?String name = java.lang.management.ManagementFactory.getRuntimeMXBean().getName(); ? ?
?? ??? ?java.lang.System.out.println(name); ? ?
?? ??? ?// 首先獲取本應用程序的PID
?? ??? ?String pid = name.split("@")[0]; ? ?
?? ??? ?java.lang.System.out.println("Pid is:" + pid); ??
?? ??? ? ?//windows ?
//?? ? ? ? ?String cmd = "F:\\apache-tomcat-6.0.20.exe"; ?
//?? ? ? ? ?String cmd = "D:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.EXE F:\\test.doc"; ?
//?? ? ? ? ?String cmd = "cmd.exe /c start F:\\test.doc"; ?
?? ? ? ? ? ?String cmd = "ping www.baidu.com"; ?
?? ? ? ? ? ?//linux ?
//?? ? ? ? ?String cmd = "./fork_wait"; ?
//?? ? ? ? ?String cmd = "ls -l"; ?
//?? ? ? ? ?String[] cmd=new String[3]; ?
//?? ? ? ? ?cmd[0]="/bin/sh"; ?
//?? ? ? ? ?cmd[1]="-c"; ?
//?? ? ? ? ?cmd[2]="ls -l ./"; ? ?
?? ? ? ? //獲取線程列表
?? ? ? ? String cmd1="ps p "+pid+" -L -o pcpu,pid,tid,time,tname,cmd";
?? ? ? ? String cmd2="jstack -l "+pid;
?? ? ? ? String cmd3="ps p "+pid+" -L -o tid,pcpu";
?
?? ? ? ? return pid;
?? ? ? ?}?

?

public String stack(@RequestParam(value = "id", required = false) String id)
?? ?{?
String rtStr="";
?? ??? ?ThreadGroup group = Thread.currentThread().getThreadGroup(); ?
?? ??? ?ThreadGroup topGroup = group; ?
?? ??? ?// 遍歷線程組樹,獲取根線程組 ?
?? ??? ?while (group != null) { ?
?? ??? ? ? ?topGroup = group; ?
?? ??? ? ? ?group = group.getParent(); ?
?? ??? ?} ?
?? ??? ?// 激活的線程數加倍 ?
?? ??? ?int estimatedSize = topGroup.activeCount() * 2; ?
?? ??? ?Thread[] slackList = new Thread[estimatedSize]; ?
?? ??? ?// 獲取根線程組的所有線程 ?
?? ??? ?int actualSize = topGroup.enumerate(slackList); ?
?? ??? ?// copy into a list that is the exact size ?
?? ??? ?Thread[] list = new Thread[actualSize]; ??
?? ??? ?java.lang.System.arraycopy(slackList, 0, list, 0, actualSize); ?
?? ??? ?java.lang.System.out.println("Thread list size == " + list.length); ?
?? ??? ?for (Thread thread : list) { ?
?? ??? ??? ?java.lang.System.out.println(thread.getName()); ?
?? ??? ??? ?String tid=thread.getId()+"";
?? ??? ??? ?if(tid.equals(id) )
?? ??? ??? ?{
?? ??? ??? ??? ?for(StackTraceElement ste : thread.getStackTrace())
?? ??? ??? ??? ??? ?{?
?? ??? ??? ??? ??? ?rtStr+="ClassName:"+ste.getClassName()+",FileName:"+ste.getFileName()+",Method:"+ste.getMethodName()+",LineNum:"+ste.getLineNumber()+"\r\n";
?? ??? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?} ??
?? ??? ?return rtStr;
?? ?}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/387049.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/387049.shtml
英文地址,請注明出處:http://en.pswp.cn/news/387049.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

第十二屆湖南省賽 (B - 有向無環圖 )(拓撲排序+思維)好題

Bobo 有一個 n 個點&#xff0c;m 條邊的有向無環圖&#xff08;即對于任意點 v&#xff0c;不存在從點 v 開始、點 v 結束的路徑&#xff09;。為了方便&#xff0c;點用 1,2,…,n 編號。 設 count(x,y) 表示點 x 到點 y 不同的路徑數量&#xff08;規定 count(x,x)0&#xff…

GC 調優(實戰篇) - GC參考手冊

說明: Allocation Rate, 翻譯為分配速率, 而不是分配率; 因為不是百分比,而是單位時間內分配的量; 同理, Promotion Rate 翻譯為 提升速率; 您應該已經閱讀了前面的章節: 垃圾收集簡介 - GC參考手冊Java中的垃圾收集 - GC參考手冊GC 算法(基礎篇) - GC參考手冊GC 算法(實現篇)…

01 HTML

1.什么是HTML&#xff1f;(Hyper Text Markup Language:超文本標記語言)超文本&#xff1a;功能比普通文本更加強大標記語言&#xff1a;使用一組標簽對內容進行描述的一門語言(它不是編程語言)2.語法和規范&#xff1f;HTML文件都是以.html或者.htm結尾的&#xff0c;建議使用…

圖的四種最短路徑算法

本文總結了圖的幾種最短路徑算法的實現&#xff1a;深度或廣度優先搜索算法&#xff0c;弗洛伊德算法&#xff0c;迪杰斯特拉算法&#xff0c;Bellman-Ford算法 1&#xff09;&#xff0c;深度或廣度優先搜索算法&#xff08;解決單源最短路徑&#xff09; 從起始結點開始訪問所…

20101008 搬家

剛剛系統還原了&#xff0c;把軟件啥的都裝上了&#xff0c;忙完一切&#xff0c;該整理整理照片&#xff0c;寫寫博客了&#xff08;總是如果不及時寫&#xff0c;就幾乎永遠不會寫了&#xff09;。我一貫喜歡"工欲善其事&#xff0c;必先利其器"&#xff0c;裝個wi…

ZooKeeper集群與Leader選舉

說說你對ZooKeeper集群與Leader選舉的理解&#xff1f; ZooKeeper是一個開源分布式協調服務、分布式數據一致性解決方案。可基于ZooKeeper實現命名服務、集群管理、Master選舉、分布式鎖等功能。 高可用 為了保證ZooKeeper的可用性&#xff0c;在生產環境中我們使用ZooKeeper…

JVM初探:內存分配、GC原理與垃圾收集器

JVM內存的分配與回收大致可分為如下4個步驟: 何時分配 -> 怎樣分配 -> 何時回收 -> 怎樣回收. 除了在概念上可簡單認為new時分配外, 我們著重介紹后面的3個步驟: I. 怎樣分配- JVM內存分配策略 對象內存主要分配在新生代Eden區, 如果啟用了本地線程分配緩沖, 則優先在…

02 CSS

使用 table 進行布局存在缺陷&#xff0c;而一般的布局都會采用 DIVCSS 來進行布局。 Div 它是一個html 標簽&#xff0c;一個塊級元素(單獨顯示一行)。它單獨使用沒有任何意義&#xff0c;必須結合 CSS 來使用。它主要用于頁面的布局。 Span 它是一個 html 標簽&#xff0c;…

為什么要在密碼里加點“鹽”

鹽&#xff08;Salt&#xff09; 在密碼學中&#xff0c;是指通過在密碼任意固定位置插入特定的字符串&#xff0c;讓散列后的結果和使用原始密碼的散列結果不相符&#xff0c;這種過程稱之為“加鹽”。 以上這句話是維基百科上對于 Salt 的定義&#xff0c;但是僅憑這句話還是…

一致性哈希算法 應用

互聯網創業中大部分人都是草根創業&#xff0c;這個時候沒有強勁的服務器&#xff0c;也沒有錢去買很昂貴的海量數據庫。在這樣嚴峻的條件下&#xff0c;一批又一批的創業者從創業中獲得成 功&#xff0c;這個和當前的開源技術、海量數據架構有著必不可分的關系。比如我們使用m…

(9)How to take a picture of a black hole

https://www.ted.com/talks/katie_bouman_what_does_a_black_hole_look_like/transcript 00:13In the movie "Interstellar[??nt?r?stel?(r)]星際的," we get an up-close look at a supermassive black hole. Set against a backdrop of bright gas, the black…

單個節點的緩存容量達到上限 Hash算法一致性

場景 單個節點的緩存容量達到上限&#xff0c;無法繼續單點增加內存&#xff0c;如何解決&#xff1f; 單個節點支撐的QPS達到上限&#xff0c;如何解決&#xff1f; 初步方案 增加N個緩存節點&#xff0c;為了保證緩存數據的均勻&#xff0c;一般情況會采用對key值hash&…

java學習筆記11 (構造方法 this深探)

在開發中&#xff0c;經常需要在創建對象的同事明確對象對的屬性值&#xff0c;比如一個person對象創建的時候就應該有name和age 等屬性&#xff0c;那么如何做到在創建對象的同時給對象的屬性值初始化值呢&#xff1f; 這里介紹構造方法 1 構造方法沒有返回值類型&#xff0c;…

密碼中不能包含全角字符的正則表達式

String regex "^((?![^\\x00-\\xff]).)*$"; String str "aA"; System.out.println(str.matches(regex));

編程算法 - 將排序數組按絕對值大小排序 代碼(java)

一個含有多個元素的數組&#xff0c;有多種排序方式。它可以升序排列&#xff0c;可以降序排列&#xff0c;也可以像我們以前章節說過的&#xff0c;以波浪形方式排序&#xff0c;現在我們要看到的一種是絕對值排序。對于數組A,絕對值排序滿足以下條件&#xff1a;|A[i]| < …

QT Linux打包發布

Linux&#xff1a; 1、用Release編譯&#xff1b; 2、把可執行文件(如paike)放入新建目錄中; 3、當前目錄下編寫腳本copyDependency.sh&#xff0c;把動態鏈接庫導入當前目錄&#xff1b; #!/bin/shexe"paike" #發布的程序名稱destination"/home/paike"…

CRM公海自動回收規則

企微云CRM操作指南 – 道一云|企微https://wbg.do1.com.cn/xueyuan/2568.html 銷售云 - 美洽 - 連接客戶&#xff0c;親密無間https://meiqia.com/sales-cloud 轉載于:https://www.cnblogs.com/rgqancy/p/10695466.html

三分鐘看懂一致性哈希算法

一致性哈希算法&#xff0c;作為分布式計算的數據分配參考&#xff0c;比傳統的取模&#xff0c;劃段都好很多。 在電信計費中&#xff0c;可以作為多臺消息接口機和在線計費主機的分配算法&#xff0c;根據session_id來分配&#xff0c;這樣當計費主機動態伸縮的時候&#xf…