OOM内存溢出分析

Mat内存溢出dump文件分析工具http://www.eclipse.org/mat/downloads.php

模拟OOM Java 程序

package org.cj.oom;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 创建内存分析
 * java启动参数指定内存 -Xms1m -Xmx1m
 * @author chenjian
 * @date 2022/11/18
 * @version 1.0
 */
public class OomAnalysis {
    public static void main(String[] args) throws InterruptedException {

        new Thread(new Runnable() {
            @Override
            public void run() {
                List<OomAnalysis> list = new ArrayList<>();
                while (true) {
                    list.add(new OomAnalysis());
                }
            }
        }).start();

        while (true) {
            TimeUnit.SECONDS.sleep(3);
        }
    }
}

程序运行后会出现异常

获取Dump文件方式

1.主动方式获取dump文件

使用 jps命令查询堆出现异常的进程名

jps

使用命令获取dump文件到指定目录

jmap -dump:format=b,file=E:/test/headdump.hprof 14380

2.通过制定Java vm 参数方式获取(推荐使用

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=E:/test/heapdump1.hprof

3.获得的文件如下图所示

DUMP 文件分析

1.打开Mat工具 MemoryAnalyzer.exe

2.点击File -> Open Heap Dump ,点击 Finish

3.点击切换视图

4.发现大部分内存占用的是这个线程,占用了92.66%

5.点开发现,内存空间是被一个 36万长度的数组给占据了,数组的元素是 OomAnalysis

6.接下来要寻找出现这个问题的代码在哪里。再返回到最初的大饼图,点击最下面的details。然后点击See stacktrace 堆叠追踪。

7.继续点击 Probblem Suspect 1详情中的 See stacktrace

8.这里可以看到完整的堆栈信息,里面可以发现我们增加模拟溢出代码的那个Java文件,并且爆发内存溢出的代码行也可以对上,至此溢出分析结束。

本文的内存分析针对性较强,实际情况 会有很多的干扰因素,我们需要从这些因素中找出真正的元凶。

可以配合 Jstat 命令来一起分析OOM的原因,缩小排查的范围。

jstat命令博客icon-default.png?t=M85Bhttps://blog.csdn.net/maosijunzi/article/details/46049117?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-3-46049117-blog-124800644.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-3-46049117-blog-124800644.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=4

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python3.6标准库 It contains data types that would normally be considered part of the “core” of a language, such as numbers and lists. For these types, the Python language core defines the form of literals and places some constraints on their semantics, but does not fully define the semantics. The library also contains built-in functions and exceptions — objects that can be used by all Python code without the need of an import statement. Some of these are defined by the core language, but many are not essential for the core semantics and are only described here. The bulk of the library, however, consists of a collection of modules. There are many ways to dissect this collection. Some modules are written in C and built in to the Python interpreter; others are written in Python and imported in source form. Some modules provide interfaces that are highly specific to Python, like printing a stack trace; some provide interfaces that are specific to particular operating systems, such as access to specific hardware; others provide interfaces that are specific to a particular application domain, like the World Wide Web. Some modules are available in all versions and ports of Python; others are only available when the underlying system supports or requires them; yet others are available only when a particular configuration option was chosen at the time when Python was compiled and installed. This manual is organized “from the inside out:” it first describes the built-in functions, data types and exceptions, and finally the modules, grouped in chapters of related modules. This means that if you start reading this manual from the start, and skip to the next chapter when you get bored, you will get a reasonable overview of the available modules and application areas that are supported by the Python library. Of course, you don’t have to read it like a novel — you can also browse the table of contents (in front of the manual), or look for a specific function, module or term in the index (in the back). And finally, if you enjoy learning about random subjects, you choose a random page number (see module random) and read a section or two. Regardless of the order in which you read the sections of this manual, it helps to start with chapter Built-in Functions, as the remainder of the manual assumes familiarity with this material.
paxscriptnet2.7(价值187美金)C#代码解释执行器 About paxScript.NET 18 December 2013. Support of MS Visual Studio 2013. The Microsoft NET version of the paxScript scripting engine (paxScript.NET) includes interpreters of C# and VB.NET languages. The key features of paxScript.NET are: paxScript.NET is written in C#. Source code of paxScript.NET is CLS compilant. Support of Silverlight and Windows Phone platforms of Microsoft .NET Framework. Support of Mono. paxScript.NET compiles programs into byte-code. It does not use CodeDOM and it does not generate a dynamic assembly. Separate compilation of modules is allowed. You can combine source code modules and compiled (binary) modules in your paxScript.NET script project. Cross-language scripting is allowed. You can combine modules written in C# and VB.NET in your paxScript.NET script project. C# interpreter is based on the ECMA-334 standard. It supports all C# language features with exception for the unsafe code, attributes and generic types. The interpreter extends standard of C# language with extra features which simplify the use of C# for scripting needs (more...). paxScript.NET is implemented as a .NET component ( paxscript-net.dll) which can be used with Microsoft Visual Studio .NET and Mono. The component allows you to embed paxScript.NET interpreter into your WinForms, Mobile or ASP.NET application so you can customize and extend the application without having to recompile it. Any classes, structures, enumerations, arrays, delegates, events and interfaces of host application can be used in a script. (See demo...). You call script-defined methods from host application. (See demo...). Debug capabilities: breakpoints, call stack, watch/evaluate, trace into, step over etc. (See demo...).
SimpleBrowser是专门为自动化任务而设计的一个灵活而直观的浏览器引擎,内置.Net 4 framework。示例代码:class Program {     static void Main(string[] args)     {         var browser = new Browser();         try         {             // log the browser request/response data to files so we can interrogate them in case of an issue with our scraping             browser.RequestLogged  = OnBrowserRequestLogged;             browser.MessageLogged  = new Action<Browser, string>(OnBrowserMessageLogged);             // we'll fake the user agent for websites that alter their content for unrecognised browsers             browser.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";             // browse to GitHub             browser.Navigate("http://github.com/");             if(LastRequestFailed(browser)) return; // always check the last request in case the page failed to load             // click the login link and click it             browser.Log("First we need to log in, so browse to the login page, fill in the login details and submit the form.");             var loginLink = browser.Find("a", FindBy.Text, "Login");             if(!loginLink.Exists)                 browser.Log("Can't find the login link! Perhaps the site is down for maintenance?");             else             {                 loginLink.Click();                 if(LastRequestFailed(browser)) return;                 // fill in the form and click the login button - the fields are easy to locate because they have ID attributes                 browser.Find("login_field").Value = "[email protected]";                 browser.Find("password").Value = "yourpassword";                 browser.Find(ElementType.Button, "name", "commit").Click();                 if(LastRequestFailed(browser)) return;                 // see if the login succeeded - ContainsText() is very forgiving, so don't worry about whitespace, casing, html tags separating the text, etc.                 if(browser.ContainsText("Incorrect login or password"))                 {                     browser.Log("Login failed!", LogMessageType.Error);                 }                 else                 {                     // After logging in, we should check that the page contains elements that we recognise                     if(!browser.ContainsText("Your Repositories"))                         browser.Log("There wasn't the usual login failure message, but the text we normally expect isn't present on the page");                     else                     {                         browser.Log("Your News Feed:");                         // we can use simple jquery selectors, though advanced selectors are yet to be implemented                         foreach(var item in browser.Select("div.news .title"))                             browser.Log("* "   item.Value);                     }                 }             }         }         catch(Exception ex)         {             browser.Log(ex.Message, LogMessageType.Error);             browser.Log(ex.StackTrace, LogMessageType.StackTrace);         }         finally         {             var path = WriteFile("log-"   DateTime.UtcNow.Ticks   ".html", browser.RenderHtmlLogFile("SimpleBrowser Sample - Request Log"));             Process.Start(path);         }     }     static bool LastRequestFailed(Browser browser)     {         if(browser.LastWebException != null)         {             browser.Log("There was an error loading the page: "   browser.LastWebException.Message);             return true;         }         return false;     }     static void OnBrowserMessageLogged(Browser browser, string log)     {         Console.WriteLine(log);     }     static void OnBrowserRequestLogged(Browser req, HttpRequestLog log)     {         Console.WriteLine(" -> "   log.Method   " request to "   log.Url);         Console.WriteLine(" <- Response status code: "   log.ResponseCode);     }     static string WriteFile(string filename, string text)     {         var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"));         if(!dir.Exists) dir.Create();         var path = Path.Combine(dir.FullName, filename);         File.WriteAllText(path, text);         return path;     } }
package com.hexiang.utils; import java.awt.Component; import javax.swing.JOptionPane; /** * This class ExceptionManager and its subclasses are a form of * Exception. It is used to wrap all the Throwable instances * and handle them in a unified way. It will show the information which consists of * StackTraces and Messages by using JOptionPanel. * * @author Estelle * @version 1.0 * @see java.lang.Exception * @since jdk 1.5 */ public class ExceptionManager extends RuntimeException { private static final long serialVersionUID = -6963187366089365790L; /** * This field alerter is used to show the information the Class offered. * * @see javax.swing.JOptionPane */ private JOptionPane alerter; /** * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(String msg). * * @param msg The message will pass the specified constructor * @return An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(String msg). */ public static ExceptionManager wrap(String msg){ return new ExceptionManager(msg); } /** * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(Throwable throwable). * * @param throwable The cause will pass the specified constructor * @return An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(Throwable throwable). */ public static ExceptionManager wrap(Throwable throwable){ return new ExceptionManager(throwable); } /** * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(String msg,Throwable throwable). * * @param msg The message will pass the specified constructor * @param throwable The cause will pass the specified c

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值