Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.maxifier.mxcache.jconsoleplugin;

import javax.management.openmbean.CompositeData;
import java.util.Comparator;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -81,9 +82,13 @@ public Object transform(Object o) {
public Object transform(Object o) {
return new Rate((Double) o);
}
};
},
MEMORY("Total memory, parrots", "totalMemory", false, false),
PROFIT("Total profit, seconds", "totalProfit", false, false);

private static final Pattern SHORTCUT_PATTERN = Pattern.compile("([\\w_$][\\w\\d_$]*\\.)*([\\w_$][\\w\\d_$]*)([^\\.])");
private static final int NS_IN_SECOND = 1000000000;
private static final int MAX_GET_FROM_CACHE_TIME_NS = 2000;

public static String shortcutClassNames(Object s) {
return s == null ? "" : SHORTCUT_PATTERN.matcher(s.toString()).replaceAll("$2$3");
Expand Down Expand Up @@ -124,19 +129,29 @@ public String getName() {
return name;
}

public String getKey() {
return key;
}

public boolean isSearchable() {
return searchable;
}

public boolean isShortcutable() {
return shortcutable;
}

public Comparator getComparator() {
return comparator;
}

public Object getValueFromCache(CompositeData cache) {
if (this == PROFIT) {
Integer totalHits = (Integer) TOTAL_HITS.getValueFromCache(cache);
double perHintProfitNs = ((Time) AVERAGE_CALCULATION.getValueFromCache(cache)).getValue() - MAX_GET_FROM_CACHE_TIME_NS;
return Math.round(totalHits * perHintProfitNs / NS_IN_SECOND);
} else if (this == MEMORY) {
Integer instanceCount = (Integer) INSTANCES.getValueFromCache(cache);
Integer elementCount = (Integer) ELEMENTS.getValueFromCache(cache);
return instanceCount * 2 + elementCount; // in parrots!
} else {
Object value = cache.get(key);
value = value == null ? "" : transform(value);
// todo add posibility to switch shortcutting off
return shortcutable ? shortcutClassNames(value) : value;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ protected Object doInBackground() throws Exception {
private void fillRow(CompositeData cache, Object[] row) {
for (com.maxifier.mxcache.jconsoleplugin.Attribute attr : com.maxifier.mxcache.jconsoleplugin.Attribute.values()) {
try {
Object v = cache.get(attr.getKey());
Object s = v == null ? "" : attr.transform(v);
// todo add posibility to switch shortcutting off
row[attr.ordinal()] = attr.isShortcutable() ? com.maxifier.mxcache.jconsoleplugin.Attribute.shortcutClassNames(s) : s;
row[attr.ordinal()] = attr.getValueFromCache(cache);
} catch (InvalidKeyException e) {
// some attributes were added lately, so they may be missing
row[attr.ordinal()] = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public String toString() {
}
return (int)(value/1000000) + "ms";
}

public double getValue() {
return value;
}
}