Update of /cvsroot/javaprofiler/library/src/cpu
In directory usw-pr-cvs1:/tmp/cvs-serv3458
Modified Files:
sampling.h sampling.cpp
Log Message:
no message
Index: sampling.h
===================================================================
RCS file: /cvsroot/javaprofiler/library/src/cpu/sampling.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** sampling.h 21 Nov 2001 22:31:43 -0000 1.9
--- sampling.h 18 Feb 2002 20:17:59 -0000 1.10
***************
*** 80,83 ****
--- 80,91 ----
#endif
+ private:
+
+ /// helper array of frames used in call tree building
+ JVMPI_CallFrame *ctFrames;
+
+ /// number of frames in 'ctFrames' array
+ long ctFramesCount;
+
public:
Index: sampling.cpp
===================================================================
RCS file: /cvsroot/javaprofiler/library/src/cpu/sampling.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** sampling.cpp 21 Nov 2001 22:31:42 -0000 1.10
--- sampling.cpp 18 Feb 2002 20:17:59 -0000 1.11
***************
*** 65,68 ****
--- 65,71 ----
samples = 0;
#endif
+
+ ctFrames = NULL;
+ ctFramesCount = 0;
}
***************
*** 78,81 ****
--- 81,86 ----
#endif
#endif
+
+ if (ctFrames) delete[] ctFrames;
}
***************
*** 267,270 ****
--- 272,338 ----
#endif // !USE_RAW_MONITORS
+ void RecordCallTreeBranch(CallTree *callTree, JVMPI_CallFrame *frames, long numFrames)
+ {
+ Prof* _prof = &Prof::prof();
+ jmethodID methodId;
+ Method *method;
+ CallTreeItem *p, *parent;
+ long i;
+
+ if (numFrames == 0)
+ return;
+
+ if (!callTree->root) {
+
+ methodId = frames[numFrames - 1].method_id;
+
+ if (!(method = _prof->getMethod(methodId)))
+ return;
+
+ p = new CallTreeItem;
+
+ p->method = method;
+ p->parent = NULL;
+ p->hits = 1;
+
+ callTree->root = p;
+ }
+ else callTree->root->hits++;
+
+ parent = callTree->root;
+ for (i = numFrames - 2; i >= 0; i--) {
+
+ methodId = frames[i].method_id;
+
+ p = parent->children.first();
+ while (p) {
+ if (p->method && p->method->isActive() && (*p->method == methodId))
+ break;
+ p = parent->children.next(p);
+ }
+
+ if (p) {
+
+ parent->children.add(parent->children.remove(p));
+ p->hits++;
+ }
+ else {
+
+ if (!(method = _prof->getMethod(methodId)))
+ return;
+
+ p = new CallTreeItem;
+
+ p->method = method;
+ p->parent = parent;
+ p->hits = 1;
+
+ parent->children.add(p);
+ }
+
+ parent = p;
+ }
+ }
+
void Sampling::doOneSample() {
***************
*** 279,282 ****
--- 347,351 ----
int numFrames;
CpuStatData* stat;
+ JVMPI_CallTrace ctTrace;
#ifdef _DEBUG
***************
*** 315,318 ****
--- 384,422 ----
_prof->jvmpiInterface->GetCallTrace(trace, traceDepth);
+
+ /////////////////////////////////////////////////
+ // call tree
+
+ if (_prof->setup.cpu.callTreeEnabled) {
+
+ if (!ctFrames) {
+
+ ctFramesCount = 100;
+ ctFrames = new JVMPI_CallFrame[ctFramesCount];
+ }
+
+ do {
+
+ ctTrace.env_id = envId;
+ ctTrace.frames = ctFrames;
+ ctTrace.num_frames = ctFramesCount;
+
+ _prof->jvmpiInterface->GetCallTrace(&ctTrace, ctFramesCount);
+
+ if (ctTrace.num_frames == ctFramesCount) {
+
+ delete[] ctFrames;
+
+ ctFramesCount *= 2;
+ ctFrames = new JVMPI_CallFrame[ctFramesCount];
+ }
+
+ } while (ctTrace.num_frames == ctFramesCount);
+
+ if (ctTrace.num_frames > 0)
+ RecordCallTreeBranch(&thread->callTree, ctFrames, ctTrace.num_frames);
+ }
+
+ /////////////////////////////////////////////////
}
}
|