"last_level_callee_num", "host", "phase_stack", "func", "phase_count"};
for(String head:headers){
newRecord.put(head, "");
}
if(!initialized){
TextArrayWritable newValue = new TextArrayWritable(newRecord.keySet().toArray(new String[0]));
output.collect(null, newValue);
initialized = true;
}
TreeSet <HiTuneRecord> arrays = new TreeSet<HiTuneRecord>(new RecordComparator());
TreeSet <HiTuneRecord> stackarrays = new TreeSet<HiTuneRecord>(new RecordComparator());
HiTuneRecord phase = null;
//log.debug("key: " + key.toString());
while(values.hasNext()){
try{
HiTuneRecord temp_proxyval = new HiTuneRecord(values.next());
V newvalue = (V) temp_proxyval.getObject().getClass().getConstructor().newInstance();
HiTuneRecord proxyval = new HiTuneRecord(newvalue);
for (String field: temp_proxyval.getFields()){
proxyval.add(field, temp_proxyval.getValue(field));
}
String function = proxyval.getValue("func");
log.debug(" val: " + proxyval.toString());
if (function.equals("_PHASE_")){
phase = proxyval;
continue;
}else{
if(function.indexOf("#")!=-1 ){
if(funcInStackFormat){
stackarrays.add(proxyval);
if(stackarrays.size()> limitNum){
stackarrays.remove(stackarrays.last());
}
}
}else{
//log.debug("add new val: " + val);
arrays.add(proxyval);
if(arrays.size()> limitNum){
arrays.remove(arrays.last());
}
}
}
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(funcInStackFormat){
int len = limitNum<stackarrays.size()?limitNum:stackarrays.size();
HiTuneRecord[] candidates = stackarrays.toArray(new HiTuneRecord[0]);
for (int i = 0; i <stackarrays.size(); i++ ){
HiTuneRecord val = candidates[i];
if(val!=null){
newRecord.clear();
for(String head : headers){
if(head.equals("phase_count")){
newRecord.put(head, phase.getValue("callee_num"));
}else{
newRecord.put(head, val.getValue(head));
}
}
String [] contents = new String[newRecord.keySet().size()];
int j = 0;
for (String index: newRecord.keySet() ){
contents[j] = newRecord.get(index);
log.debug("content: " + index + "," +contents[j] );
j++;
}
TextArrayWritable newValue = new TextArrayWritable(contents);
output.collect(null, newValue);
}
}
}else {
int len = limitNum<arrays.size()?limitNum:arrays.size();
HiTuneRecord[] candidates = arrays.toArray(new HiTuneRecord[0]);
for (int i = 0; i <len; i++ ){
HiTuneRecord val = candidates[i];
log.debug("dump val: " + val);
if(val!=null){
newRecord.clear();
for(String head : headers){
if(head.equals("phase_count")){
newRecord.put(head, phase.getValue("callee_num"));
}else{
newRecord.put(head, val.getValue(head));
}
}
String [] contents = new String[newRecord.keySet().size()];
int j = 0;
for (String index: newRecord.keySet() ){
contents[j] = newRecord.get(index);
log.debug("content: " + index + "," +contents[j] );
j++;
}
TextArrayWritable newValue = new TextArrayWritable(contents);
output.collect(null, newValue);
}
}