English 中文(简体)
java heap analysis with oql: 2. 无数独特之处
原标题:java heap analysis with oql: Count unique strings

对现有java软件进行记忆分析。 是否在 o克液中存在一个等效组,以看到具有相同价值但不同情况的物体。

select count(*) from java.lang.String s group by s.toString()

因此,我要提出一个重复铺设的插座清单以及复制件数。 这样做的目的是看到大量案件,以便利用Sting.intern()优化这些案件。

例:

"foo"    100
"bar"    99
"lazy fox"    50

......

最佳回答
问题回答

令人痛心的是,在荷兰,有相当于“按组别”的吨位。 我假定你再谈一下在 j子和视力仪中使用的低价竞标。

但有选择。 如果你使用纯粹的Java syntax而不是“slectx from y” syntax,那么你就完全有能力与Javagust公司合作。

即便如此,获得你所寻求的信息的另一种方式也不简单。 例如,这里有一个将履行与你的询问相同任务的联络处“主席团”:

var set={};
sum(map(heap.objects("java.lang.String"),function(heapString){
  if(set[heapString.toString()]){
    return 0;
  }
  else{
    set[heapString.toString()]=true;
    return 1;
  }
}));

In this example a regular JavaScript object mimics a set (collection with no duplicates). As the the map function goes through each string, the set is used to determine if the string has already been seen. Duplicates don t count toward the total (return 0) but new strings do (return 1).

提高效率:

var countByValue = {};

// Scroll the strings
heap.forEachObject(
  function(strObject) {
    var key = strObject.toString();
    var count = countByValue[key];
    countByValue[key] = count ? count + 1 : 1;
  },
  "java.lang.String",
  false
);

// Transform the map into array
var mapEntries = [];
for (var i = 0, keys = Object.keys(countByValue), total = keys.length; i < total; i++) {
  mapEntries.push({
    count : countByValue[keys[i]],
    string : keys[i]
  });
}

// Sort the counts
sort(mapEntries,  rhs.count - lhs.count );

Just post my solution and experience when doing similar issue for other references.

var counts = {};
var alreadyReturned = {};
top(
filter(
    sort(
        map(heap.objects("java.lang.ref.Finalizer"),
            function (fobject) {
                var className = classof(fobject.referent)
                if (!counts[className]) {
                    counts[className] = 1;
                } else {
                    counts[className] = counts[className] + 1;
                }
                return {string: className, count: counts[className]};
            }),
         rhs.count-lhs.count ),
    function (countObject) {
        if (!alreadyReturned[countObject.string]) {
            alreadyReturned[countObject.string] = true;
            return true;
        } else {
            return false;
        }
    }),
    "rhs.count > lhs.count", 10);

The previous code will output the top 10 classes used by java.lang.ref.Finalizer.
Tips:
1. The sort function by using function XXX is NOT working on my Mac OS.
2. The classof function can return the class of the referent. (I tried to use fobject.referent.toString() -> this returned a lot of org.netbeans.lib.profiler.heap.InstanceDump. This also wasted a lot of my time).

Method 1

你们可以选择所有的护卫,然后利用终点站将其集中起来。

  1. Increase the oql limit in the visual vm config files
  2. restart visual vm
  3. oql to get all the strings
  4. copy and paste them into vim
  5. clean the data with vim macros so there s
  6. sort | uniq -c to get the counts.

Method 2

  1. Use a tool to dump all the fields object the class you re interested in ( https://github.com/josephmate/DumpHprofFields can do it )
  2. Use bash to select the strings you re interested in
  3. Use bash to aggregate




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签