首页 \ 问答 \ 是否有工具可以在不加载完整hprof文件的情况下分析大型Java堆转储?(Are there tools to analyse large Java heap dumps without loading the complete hprof file?)

是否有工具可以在不加载完整hprof文件的情况下分析大型Java堆转储?(Are there tools to analyse large Java heap dumps without loading the complete hprof file?)

我使用Eclipse MAT来分析hprof文件。 这是非常好的,但如果你有2Gb堆转储,那么你需要运行带有2Gb +堆大小的MAT,以便能够加载完整的堆转储。

我想知道是否有人知道可以分析一个2Gb hprof文件而不使用那么多内存本身的工具(例如,它不会加载完整的文件,但以某种方式遍历它)? 如果在客户服务器上生成hprof文件,这将非常有用,因为我可以在服务器上运行一些分析,而不是试图通过VPN复制2Gb文件。


I use Eclipse MAT to analyse hprof files. It is very good but if you have a 2Gb heap dump then you need to run MAT with a 2Gb+ heap size itself to be able to load the complete heap dump.

I was wondering if anyone knows of a tool that could analyse a 2Gb hprof file without using that much memory itself (e.g. it doesn't load the complete file but somehow walks through it)? This would be useful if a hprof file gets generated on a customer server as I could then run some analysis on the server instead of trying to copy a 2Gb file over a VPN.


原文:https://stackoverflow.com/questions/1795778
更新时间:2022-01-07 10:01

最满意答案

问题是子线程上的异常需要报告回主线程。 除非您将读取器和编写器放在不同的线程中,否则这可能很棘手。

我这样做的方法是将两个部分包装在ExecutionCompletionService - 如下所示:

public void process(InputStream xmlStream) {
    ExecutorService threadPool = Executors.newFixedThreadPool(2);
    ExecutorCompletionService<Void> ecs = new ExecutorCompletionService<>(threadPool);

    final BufferedInputStream bufferedXmlStream = new BufferedInputStream(xmlStream);

    PipedInputStream pipedJsonInputStream = new PipedInputStream();
    final PipedOutputStream jsonStream = new PipedOutputStream(pipedJsonInputStream);

    ecs.submit( new Callable<Void>() {
       @Override
       public Void call() {
          // put your code that writes data to the outputstream here.
          try {
              XML.toJson(bufferedXmlStream, jsonStream, true);
          } catch (Exception e) {
              e.printStackTrace();
              throw e;
          }
          return null;
        }
    });

    ecs.submit( new Callable<Void>() {
       @Override
       public Void call() {
          try {
              // use reader to further process json in main thread...
              parseJsonStream(reader);
          } finally {
              reader.close();
              jsonStream.close();
          }
          return null;
      }
    });

    // Wait for all tasks to be done.
    // Kill the other thread if one hits an exception.
    try {
        for (int i = 0; i < 2; ++i) {
            ecs.take().get();
        }
    } finally {
        threadPool.shutdownNow();
    } 
}

The problem is that the exception on the child thread needs to get reported back to the main thread. This can be tricky to do unless you put both the reader and writer in separate threads.

The way I do this is to wrap both pieces in an ExecutionCompletionService - like this:

public void process(InputStream xmlStream) {
    ExecutorService threadPool = Executors.newFixedThreadPool(2);
    ExecutorCompletionService<Void> ecs = new ExecutorCompletionService<>(threadPool);

    final BufferedInputStream bufferedXmlStream = new BufferedInputStream(xmlStream);

    PipedInputStream pipedJsonInputStream = new PipedInputStream();
    final PipedOutputStream jsonStream = new PipedOutputStream(pipedJsonInputStream);

    ecs.submit( new Callable<Void>() {
       @Override
       public Void call() {
          // put your code that writes data to the outputstream here.
          try {
              XML.toJson(bufferedXmlStream, jsonStream, true);
          } catch (Exception e) {
              e.printStackTrace();
              throw e;
          }
          return null;
        }
    });

    ecs.submit( new Callable<Void>() {
       @Override
       public Void call() {
          try {
              // use reader to further process json in main thread...
              parseJsonStream(reader);
          } finally {
              reader.close();
              jsonStream.close();
          }
          return null;
      }
    });

    // Wait for all tasks to be done.
    // Kill the other thread if one hits an exception.
    try {
        for (int i = 0; i < 2; ++i) {
            ecs.take().get();
        }
    } finally {
        threadPool.shutdownNow();
    } 
}

相关问答

更多
  • 问题是子线程上的异常需要报告回主线程。 除非您将读取器和编写器放在不同的线程中,否则这可能很棘手。 我这样做的方法是将两个部分包装在ExecutionCompletionService - 如下所示: public void process(InputStream xmlStream) { ExecutorService threadPool = Executors.newFixedThreadPool(2); ExecutorCompletionService ecs = ne ...
  • JB Nizet的答案没问题,但它只使用map副作用,而不是地图操作,这有点奇怪。 有一种方法可以在你对某些事物的副作用感兴趣时使用,例如抛出异常: peek 。 List filtered = list.stream() .peek(Objects::requireNonNull) .filter(predicate) .collect(Collectors.toList()); 如果你想要你自己的异常,只需在其中放入一个lamb ...
  • 一个PipedInputStream只会在数据被连接到的输出流写入时使数据可用。 只要您从输入流中读取输入流的速度与从输出流接收数据一样快,就不会有太多的数据需要缓冲。 如果这没有帮助,您需要提供更多关于您使用管道输入流进行的操作的信息 - 连接到哪个输出流以及从中读取什么内容? 编辑:你还没有说什么是从你的PipedInputStream阅读。 一定是,否则PipedOutputStream会阻塞 - PipedInputStream只有一个相当小的缓冲区(默认情况下)。 A PipedInputStre ...
  • 您可以使用Throwable.addSuppressed(Throwable) ,它允许记录任意数量的throwables(以后可以通过getSuppressed()获取),并且在语义上比将其他throwables记录为“cause”更合适。 由于这是对其中一个throwables的一种修改,因此reduce不是正确的操作(并且它不会在并行操作中提供预期的结果)。 这看起来不像是需要对大量元素进行优化的操作,因此,最佳解决方案是直接将所有元素收集到List并使用 if(!listOfAllException ...
  • 您可以检查是否有任何元素通过了您的过滤器,并且如果没有:使用Optional的orElseThrow引发异常: Integer match = intList.stream() .filter(i -> i > 40) .findAny() .orElseThrow(...); 当然,这只会给你一个在不抛出异常时通过过滤器的元素,所以我不确定它是否正是你想要的。 You could check if there's any ele ...
  • 用这个: java -jar `find / -type f -name "R*.jar" -printf '%T@ %p\n' | sort -k 1nr | sed 's/^[^ ]* //' | head -n 1` -debug 这个 sort命令答案的功劳。 Use this: java -jar `find / -type f -name "R*.jar" -printf '%T@ %p\n' | sort -k 1nr | sed 's/^[^ ]* //' | head -n 1` -de ...
  • 我已经读过字节流不支持unicode字符。 要么你使用了糟糕的信息来源,要么你可能误解了一些东西。 字节流支持字节。 因此,字节流支持可以用字节表示的任何内容 。 视频,文本,图片,音乐......如果字节流不支持它,则根本不能在数字计算机中使用它。 在简单的1和0序列中表示那些东西的技巧是使用商定的规则。 您可以根据特定规则对文本进行编码,然后接收方可以使用相同的规则对其进行解码。 "Русский язык"可以表示为支持西里尔字符的任何编码中的字节。 在unicode的任何编码中:UTF-8,UTF- ...
  • var unzipStream = zlib.createUnzip() unzipStream.on('data', myDataHandler).on('end', myEndHandler) fs.createReadStream('log.gz').pipe(unzipStream) 这将为您提供data和end事件。 由于它是日志数据,您可能还会发现拆分对于逐行获取事件非常有用。 var unzipStream = zlib.createUnzip() unzipStream.on('data' ...
  • 使用setEmbeddedData()函数将selectedChoiceLower分配给新的或现有的嵌入数据变量( 请参阅文档 )。 然后,您可以在以后的问题中使用嵌入的字段变量。 javascript: setEmbeddedData('lower', selectedChoiceLower); 嵌入字段代码: ${e://Fields/lower} 警告:将用户生成的文本放入javascript非常危险! Qualtrics不会进行任何转义。 如果用户在其文本中放入“或”,它将直接放入javascrip ...
  • 问题是输出没有被刷新 请参阅http://docs.oracle.com/javase/7/docs/api/java/io/PipedOutputStream.html#flush() The issue is that the output is not being flushed see http://docs.oracle.com/javase/7/docs/api/java/io/PipedOutputStream.html#flush()

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)