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

prof_thread.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 "../shared/groupThread.h"
00037 #include "../prof/synchronized.h"
00038 
00039 int Prof::findParent( Thread* t, void** inout) {
00040 
00041         if( t->active && t->threadName == reinterpret_cast<const char*>( *inout)) {
00042         
00043                 *inout = t;
00044                 return 1;
00045         }
00046 
00047         return 0;
00048 }
00049 
00050 int Prof::findGroup( GroupThread* g, void** inout) {
00051         
00052         if( g->groupName == reinterpret_cast<const char*> ( *inout)) {
00053         
00054                 *inout = g;
00055                 return 1;
00056         }
00057 
00058         return 0;
00059 }
00060 
00061 void Prof::event_threadStart( JVMPI_Event* event) {
00062 
00063         Synchronized sync( dataLock, 0);
00064         if( !(event->event_type & JVMPI_REQUESTED_EVENT)) sync.enter();
00065 
00066         JNIEnv* envId = event->u.thread_start.thread_env_id;
00067         char* name = event->u.thread_start.thread_name;
00068 
00069         if (!envId) return;
00070         if (strcmp(name, COMMUN_THREAD) == 0) return;
00071         if (strcmp(name, SAMPLING_THREAD) == 0) return;
00072 
00073         static int firstTime = 1;
00074         if( firstTime) {
00075         
00076                 jvmpiInterface->EnableEvent( JVMPI_EVENT_THREAD_END, NULL);
00077                 firstTime = 0;
00078         }
00079 
00080         Thread* t = new Thread;
00081 
00082         t->threadName  = event->u.thread_start.thread_name;
00083         t->threadId    = event->u.thread_start.thread_id;
00084         t->threadEnvId    = envId;
00085 
00086         threads.add(t);
00087         activeThreads.add(t);
00088         sampledThreads.add(t);
00089 
00090         void* inout = event->u.thread_start.group_name;
00091         if( !groupsOfThreads.forEach( findGroup, &inout)) {
00092         
00093                 GroupThread* g = new GroupThread;
00094 
00095                 g->groupName = event->u.thread_start.group_name;
00096                 g->threads.add( t);
00097 
00098                 t->group = g;
00099 
00100                 groupsOfThreads.add( g);
00101         }
00102         else {
00103                 
00104                 t->group = reinterpret_cast<GroupThread*> ( inout);
00105                 t->group->threads.add( t);
00106         }
00107 
00108         inout = event->u.thread_start.parent_name;
00109         if( !threads.forEach( findParent, &inout)) t->parent = NULL;
00110         else t->parent = reinterpret_cast<Thread*> ( inout);
00111 
00112         if( t->parent) t->parent->children.add( t);
00113 }
00114 
00115 void Prof::event_threadEnd( JVMPI_Event* event) {
00116 
00117         Synchronized sync( dataLock);
00118 
00119         Thread* t = getThread(event->env_id, 0);
00120         if (t) t->deactivate();
00121 }

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