#include "xdprof.h"
Include dependency graph for background.cpp:

Go to the source code of this file.
Functions | |
| void | DisableEvents () |
| void | InitializeBackgroundThread (string host, int port, string selfinfo, int refreshTime) |
| Initialize the background thread by setting the selfinfo and refreshtime. More... | |
| void | BackgroundThread (void *) |
| This is the background thread; it sends the self info once and then updates the server every RefreshTime milliseconds. More... | |
| void | CreateBackgroundThread () |
| Creates the background thread. More... | |
Variables | |
| int | RefreshTime = 2000 |
| How often to refresh (in milliseconds). More... | |
| string | SelfInfo |
| Information about this computer. More... | |
| volatile JVMPI_RawMonitor | BackgroundMonitor |
| The monitor used for background notification/shutdown. More... | |
| string | HostName |
| The hostname to connect to. More... | |
| int | PortNumber |
| The port number to connect to. More... | |
| volatile bool | ShutdownRequested |
| set to true by external thread when the thread should shutdown. More... | |
Definition in file background.cpp.
|
|
This is the background thread; it sends the self info once and then updates the server every RefreshTime milliseconds.
Definition at line 88 of file background.cpp. 00089 {
00090 // must be created by this function
00091 BackgroundMonitor = CALL(RawMonitorCreate)("_background");
00092 CALL(RawMonitorEnter)(BackgroundMonitor);
00093
00094 // now set up the communications
00095 bool ok = InitializeCommunications(HostName, PortNumber);
00096 if (!ok || ! IsConnected())
00097 {
00098 debug("couldn't connect, disabling events");
00099 // TODO: shut it down
00100 ShutdownCommunications();
00101 DisableEvents();
00102 return;
00103 }
00104
00105 // Once and only once, we send the SelfInfo
00106 //Send(SelfInfo + "\n");
00107 ShutdownRequested = false;
00108
00109 ThreadID me;
00110
00111 (*GlobalJVM).GetEnv((void **)&me, JNI_VERSION_1_2);
00112 jclass c = me->FindClass("java/lang/System");
00113 jmethodID m = me->GetStaticMethodID(c, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");
00114 vector<string> properties;
00115 properties.push_back("os.arch");
00116 properties.push_back("os.name");
00117 properties.push_back("os.version");
00118 properties.push_back("java.vm.name");
00119 properties.push_back("java.vm.info");
00120 properties.push_back("java.vm.version");
00121 properties.push_back("java.vm.vendor");
00122 properties.push_back("java.runtime.name");
00123 properties.push_back("java.runtime.version");
00124
00125 ostringstream oss;
00126 for (vector<string>::size_type i = 0; i < properties.size(); i++)
00127 {
00128 jstring str = (jstring)me->CallStaticObjectMethod(c, m, me->NewStringUTF(properties[i].c_str()));
00129 //cout << properties[i] << "\t" << me->GetStringUTFChars(str, 0) << endl;
00130 debug(i, properties[i], me->GetStringUTFChars(str, 0));
00131 oss << properties[i] << "=" << me->GetStringUTFChars(str, 0) << '!';
00132 }
00133 oss << ends;
00134 string ost(oss.str());
00135 SelfInfo += " !";
00136 SelfInfo += ost.substr(0, ost.size() - 2) ;
00137 SelfInfo += '\n';
00138 debug("selfinfo", SelfInfo);
00139 debug("background thread id", me);
00140
00141 while(! ShutdownRequested)
00142 {
00143 CALL(RawMonitorWait)(BackgroundMonitor, (jlong)RefreshTime);
00144 if (ShutdownRequested)
00145 break;
00146 if (IsConnected())
00147 ThreadDump(SelfInfo, me);
00148 else
00149 {
00150 debug("lost connection, shutting down.");
00151 DisableEvents();
00152 ShutdownCommunications();
00153 return;
00154 }
00155 }
00156 // debug("out of shutdown loop.");
00157 CALL(RawMonitorDestroy)(BackgroundMonitor);
00158 }
|
|
|
Creates the background thread.
Definition at line 163 of file background.cpp. Referenced by NotifyEvent().
|
|
|
Definition at line 57 of file background.cpp. Referenced by BackgroundThread().
00058 {
00059 CHECKEDCALL(DisableEvent(JVMPI_EVENT_JVM_INIT_DONE , NULL));
00060 CHECKEDCALL(DisableEvent(JVMPI_EVENT_JVM_SHUT_DOWN , NULL));
00061 CHECKEDCALL(DisableEvent(JVMPI_EVENT_THREAD_START, NULL));
00062 CHECKEDCALL(DisableEvent(JVMPI_EVENT_THREAD_END, NULL));
00063 CHECKEDCALL(DisableEvent(JVMPI_EVENT_CLASS_LOAD , NULL));
00064 CHECKEDCALL(DisableEvent(JVMPI_EVENT_CLASS_UNLOAD , NULL));
00065 CHECKEDCALL(DisableEvent(JVMPI_EVENT_OBJECT_ALLOC , NULL));
00066
00067 }
|
|
|
Initialize the background thread by setting the selfinfo and refreshtime.
Definition at line 76 of file background.cpp. 00077 {
00078 HostName = host;
00079 PortNumber = port;
00080 SelfInfo = selfinfo;
00081 RefreshTime = refreshTime;
00082 }
|
|
|
The monitor used for background notification/shutdown.
Definition at line 46 of file background.cpp. |
|
|
The hostname to connect to.
Definition at line 49 of file background.cpp. |
|
|
The port number to connect to.
Definition at line 52 of file background.cpp. |
|
|
How often to refresh (in milliseconds).
Definition at line 40 of file background.cpp. |
|
|
Information about this computer.
Definition at line 43 of file background.cpp. |
|
|
set to true by external thread when the thread should shutdown.
Definition at line 55 of file background.cpp. |
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001