Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

prof_method.cpp

00001 /*
00002  *                         Sun Public License Notice
00003  *
00004  * The contents of this file are subject to the Sun Public License
00005  * Version 1.0 (the "License"); you may not use this file except
00006  * in compliance with the License. A copy of the License is available
00007  * at http://www.sun.com/
00008  *
00009  * The Original Code is the Java Profiler module.  The Initial Developers
00010  * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00011  * Lukas Petru and Marek Przeczek.
00012  *
00013  * Portions created by Jan Stola are Copyright (C) 2000-2001.
00014  * All Rights Reserved.
00015  *
00016  * Portions created by Pavel Vacha are Copyright (C) 2000-2001.
00017  * All Rights Reserved.
00018  *
00019  * Portions created by Michal Pise are Copyright (C) 2000-2001.
00020  * All Rights Reserved.
00021  *
00022  * Portions created by Petr Luner are Copyright (C) 2000-2001.
00023  * All Rights Reserved.
00024  *
00025  * Portions created by Lukas Petru are Copyright (C) 2000-2001.
00026  * All Rights Reserved.
00027  *
00028  * Portions created by Marek Przeczek are Copyright (C) 2000-2001.
00029  * All Rights Reserved.
00030  *
00031  * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
00032  *               Lukas Petru and Marek Przeczek.
00033  */
00034 
00035 #include "../prof/prof.h"
00036 #include "../prof/synchronized.h"
00037 #include "../cpu/cpuThreadMethod.h"
00038 #include "../cpu/cpuThreadTrace.h"
00039 #include "../cpu/cpuTrace.h"
00040 
00041 void Prof::event_methodEntry( JVMPI_Event* event) {
00042 
00043         Synchronized sync(dataLock);
00044 
00045         jlong entryTime;
00046         JVMPI_CallFrame callFrame;
00047         JVMPI_CallTrace callTrace;
00048         Thread* thread;
00049 
00050         callTrace.env_id     = event->env_id;
00051         callTrace.num_frames = (jint)1;
00052         callTrace.frames     = &callFrame;
00053 
00054         jvmpiInterface->GetCallTrace(&callTrace, (jint)1);
00055 
00056         if (callTrace.num_frames != (jint)1) {
00057                 PROF_ERROR("METHOD ENTRY", "GetCallTrace failed");
00058                 return;
00059         }
00060         if (callFrame.method_id != event->u.method.method_id) {
00061                 PROF_ERROR("METHOD ENTRY", "callFrame.method_id != event->method.method_id");
00062                 return;
00063         }
00064 
00065         if (!(thread = getThread(event->env_id))) {
00066                 PROF_ERROR("METHOD ENTRY", "Thread not found");
00067                 return;
00068         }
00069 
00070         entryTime = jvmpiInterface->GetCurrentThreadCpuTime();
00071         thread->stack.push(callFrame, entryTime); 
00072 
00073         static int firstTime = 1;
00074         if( firstTime) {
00075 
00076                 jvmpiInterface->EnableEvent( JVMPI_EVENT_METHOD_EXIT, NULL);
00077                 firstTime = 0;
00078         }
00079 }
00080 
00081 void Prof::event_methodExit( JVMPI_Event* event) {
00082 
00083         Synchronized sync(dataLock);
00084 
00085         Thread* thread;
00086         JVMPI_CallFrame callFrames[MAX_TRACE];
00087         int numFrames;
00088         jlong exitTime;
00089         jlong totalTime;
00090         jlong pureTime;
00091         CpuStatData* stat;
00092         
00093         if (!(thread = getThread(event->env_id))) {
00094                 PROF_ERROR("METHOD EXIT", "Thread not found");
00095                 return;
00096         }
00097 
00098         if (setup.cpu.level == Setup::LEVEL_METHOD) {
00099                 numFrames = 1;
00100         }
00101         else numFrames = setup.cpu.traceDepth;
00102 
00103         numFrames = thread->stack.getTopCallTrace(numFrames, callFrames);
00104         if (numFrames == 0) {
00105                 PROF_ERROR("METHOD EXIT", "Empty stack");
00106                 return;
00107         }
00108 
00109         if (callFrames[0].method_id != event->u.method.method_id) {
00110                 PROF_ERROR("METHOD EXIT", "top method != event->method.method_id");
00111                 return;
00112         }
00113 
00114         exitTime = jvmpiInterface->GetCurrentThreadCpuTime();
00115         thread->stack.pop(exitTime, totalTime, pureTime);
00116 
00117         if (setup.cpu.threadsEnabled) {
00118 
00119                 if (setup.cpu.level == Setup::LEVEL_METHOD) {
00120 
00121                         if (!(stat = getCpuThreadMethod(event->env_id, callFrames[0].method_id))) {
00122                                 PROF_ERROR("METHOD EXIT", "Cannot get CpuThreadMethod");
00123                                 return;
00124                         }
00125                 }
00126                 else {
00127 
00128                         if (!(stat = getCpuThreadTrace(event->env_id, numFrames, callFrames))) {
00129                                 PROF_ERROR("METHOD EXIT", "Cannot get CpuThreadTrace");
00130                                 return;
00131                         }
00132                 }
00133         }
00134         else {
00135                 if (setup.cpu.level == Setup::LEVEL_METHOD) {
00136 
00137                         if (!(stat = getMethod(callFrames[0].method_id))) {
00138                                 PROF_ERROR("METHOD EXIT", "Method not found");
00139                                 return;
00140                         }
00141                 }
00142                 else {
00143 
00144                         if (!(stat = getCpuTrace(numFrames, callFrames))) {
00145                                 PROF_ERROR("METHOD EXIT", "Cannot get CPU trace");
00146                                 return;
00147                         }
00148                 }
00149         } 
00150 
00151         stat->addCpuStat((jlong)1, pureTime);
00152 }

Generated on Mon Jan 28 14:53:27 2002 for Java Profiler Dynamic Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001