mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-18 01:06:03 +10:00
[유치수] [NOBTS] add terminal nodes statics histogram.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-commons/trunk@952 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
package com.profiler.common.bo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class HistogramBo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4613517226343565010L;
|
||||
|
||||
public static final int DEFAULT_RESOLUTION = 100;
|
||||
|
||||
private final TreeMap<Integer, Integer> counts = new TreeMap<Integer, Integer>();
|
||||
private final int resolution;
|
||||
|
||||
private int min = 0;
|
||||
private int max = 0;
|
||||
private int sampleCount = 1;
|
||||
|
||||
public HistogramBo(int resolution) {
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
public void addSample(int value) {
|
||||
if (min > value) {
|
||||
min = value;
|
||||
}
|
||||
|
||||
if (max < value) {
|
||||
max = value;
|
||||
}
|
||||
|
||||
int slot = value / resolution;
|
||||
Integer org = counts.get(slot);
|
||||
|
||||
if (org == null) {
|
||||
counts.put(slot, 1);
|
||||
} else {
|
||||
counts.put(slot, ++org);
|
||||
}
|
||||
|
||||
sampleCount++;
|
||||
}
|
||||
|
||||
public HistogramBo mergeWith(HistogramBo histogram) {
|
||||
if (this.resolution != histogram.resolution) {
|
||||
throw new IllegalArgumentException("Can't merge Histogram. different resolution.");
|
||||
}
|
||||
|
||||
if (this.min > histogram.min) {
|
||||
this.min = histogram.min;
|
||||
}
|
||||
|
||||
if (this.max < histogram.max) {
|
||||
this.max = histogram.max;
|
||||
}
|
||||
|
||||
sampleCount += histogram.sampleCount;
|
||||
|
||||
for (Entry<Integer, Integer> entry : histogram.counts.entrySet()) {
|
||||
int slot = entry.getKey();
|
||||
Integer org = counts.get(slot);
|
||||
|
||||
if (org == null) {
|
||||
counts.put(slot, entry.getValue());
|
||||
} else {
|
||||
counts.put(slot, org + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public int getSampleCount() {
|
||||
return sampleCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Iterator<Entry<Integer, Integer>> iterator = counts.entrySet().iterator();
|
||||
|
||||
sb.append("[");
|
||||
while (iterator.hasNext()) {
|
||||
Entry<Integer, Integer> entry = iterator.next();
|
||||
sb.append("{ \"from\" : ").append(entry.getKey() * resolution).append(", ");
|
||||
sb.append("\"to\" : ").append(entry.getKey() * resolution + resolution).append(", ");
|
||||
sb.append("\"value\" : ").append(entry.getValue()).append(" }");
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.profiler.common.bo;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
public class TerminalStatisticsBo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2715236149783596830L;
|
||||
|
||||
private final int histogramResolution;
|
||||
private final Set<String> agentIds = new HashSet<String>();
|
||||
private final HistogramBo histogram;
|
||||
|
||||
public TerminalStatisticsBo() {
|
||||
histogramResolution = HistogramBo.DEFAULT_RESOLUTION;
|
||||
histogram = new HistogramBo(histogramResolution);
|
||||
}
|
||||
|
||||
public void sampleElapsedTime(int value) {
|
||||
histogram.addSample(value);
|
||||
}
|
||||
|
||||
public void addAgentId(String agentId) {
|
||||
agentIds.add(agentId);
|
||||
}
|
||||
|
||||
public Set<String> getAgentIds() {
|
||||
return agentIds;
|
||||
}
|
||||
|
||||
public HistogramBo getHistogram() {
|
||||
return histogram;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("AgentIds=").append(agentIds);
|
||||
sb.append(", Histogram=").append(histogram);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO SpanBo와 같이 readbytes, writebytes로 변경이 필요해보임.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public byte[] toBytes() {
|
||||
ByteArrayOutputStream bos = null;
|
||||
ObjectOutput out = null;
|
||||
try {
|
||||
bos = new ByteArrayOutputStream();
|
||||
out = new ObjectOutputStream(bos);
|
||||
out.writeObject(this);
|
||||
return bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
if (out != null)
|
||||
out.close();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (bos != null)
|
||||
bos.close();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TerminalStatisticsBo parse(byte[] bytes) {
|
||||
ByteArrayInputStream bis = null;
|
||||
ObjectInput in = null;
|
||||
try {
|
||||
bis = new ByteArrayInputStream(bytes);
|
||||
in = new ObjectInputStream(bis);
|
||||
return (TerminalStatisticsBo) in.readObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
try {
|
||||
if (in != null)
|
||||
in.close();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (bis != null)
|
||||
bis.close();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,4 +76,5 @@ public interface HbaseOperations2 extends HbaseOperations {
|
||||
|
||||
void incrementColumnValue(String tableName, final byte[] rowName, final byte[] familyName, final byte[] qualifier, final long amount, final boolean writeToWAL);
|
||||
|
||||
void doUserBatchJob(String tableName, final HBaseBatchJob job);
|
||||
}
|
||||
|
||||
@@ -408,4 +408,13 @@ public class HbaseTemplate2 implements HbaseOperations2, InitializingBean, Dispo
|
||||
});
|
||||
}
|
||||
|
||||
public void doUserBatchJob(String tableName, final HBaseBatchJob job) {
|
||||
execute(tableName, new TableCallback<Object>() {
|
||||
@Override
|
||||
public Object doInTable(HTable htable) throws Throwable {
|
||||
job.doBatch(htable);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user