JBoss Native SVN: r1080 - in trunk/sight/native: share and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-03 12:07:16 -0400 (Wed, 03 Oct 2007)
New Revision: 1080
Modified:
trunk/sight/native/include/sight_local.h
trunk/sight/native/share/no.c
Log:
Fix paralel GC
Modified: trunk/sight/native/include/sight_local.h
===================================================================
--- trunk/sight/native/include/sight_local.h 2007-10-03 08:03:29 UTC (rev 1079)
+++ trunk/sight/native/include/sight_local.h 2007-10-03 16:07:16 UTC (rev 1080)
@@ -383,7 +383,7 @@
#define SIGHT_LOCAL_TRY(N) { apr_uint32_t _SGATOM = apr_atomic_inc32(sight_global_atomic); \
if ((N)) apr_atomic_inc32(&(N)->refcount); \
- if ((N))
+ if ((N) && _SGATOM)
#define SIGHT_LOCAL_END(N) apr_atomic_dec32(&(N)->refcount); } apr_atomic_dec32(sight_global_atomic)
#define SIGHT_LOCAL_BRK(N) apr_atomic_dec32(&(N)->refcount); apr_atomic_dec32(sight_global_atomic)
Modified: trunk/sight/native/share/no.c
===================================================================
--- trunk/sight/native/share/no.c 2007-10-03 08:03:29 UTC (rev 1079)
+++ trunk/sight/native/share/no.c 2007-10-03 16:07:16 UTC (rev 1080)
@@ -114,7 +114,7 @@
{
sight_object_t *no;
- UNREFERENCED_STDARGS;
+ UNREFERENCED_O;
if (!(no = (sight_object_t *)sight_calloc(_E,
sizeof(sight_object_t),
THROW_FMARK))) {
@@ -179,7 +179,7 @@
if (!no)
return;
- SIGHT_GLOBAL_TRY {
+ SIGHT_LOCAL_TRY(no) {
if (no->cb.object) {
(*_E)->DeleteGlobalRef(_E, no->cb.object);
no->cb.object = NULL;
@@ -191,7 +191,7 @@
no->cb.method = (*_E)->GetMethodID(_E, c, no->cb.name, no->cb.msig);
DBPRINTF("NativeObject_cbset0: %s/%s", no->cb.name, no->cb.msig);
}
- } SIGHT_GLOBAL_END();
+ } SIGHT_LOCAL_END(no);
}
SIGHT_EXPORT_DECLARE(void, NativeObject, free0)(SIGHT_STDARGS,
@@ -208,13 +208,12 @@
#endif
if (!no)
return;
- if (no->object) {
- object = (*_E)->NewLocalRef(_E, no->object);
- (*_E)->DeleteWeakGlobalRef(_E, no->object);
- no->object = object;
- }
-
SIGHT_GLOBAL_TRY {
+ if (no->object) {
+ object = (*_E)->NewLocalRef(_E, no->object);
+ (*_E)->DeleteWeakGlobalRef(_E, no->object);
+ no->object = object;
+ }
refcount = apr_atomic_read32(&no->refcount);
while (refcount) {
apr_thread_yield();
@@ -233,14 +232,12 @@
(*no->clean)(POOL_DESTROY, no);
if (no->pool)
apr_pool_destroy(no->pool);
+ if (object)
+ (*_E)->DeleteLocalRef(_E, object);
+ if (no->cb.object)
+ (*_E)->DeleteGlobalRef(_E, no->cb.object);
+ free(no);
} SIGHT_GLOBAL_END();
- if (object) {
- (*_E)->DeleteLocalRef(_E, object);
- }
- if (no->cb.object) {
- (*_E)->DeleteGlobalRef(_E, no->cb.object);
- }
- free(no);
}
SIGHT_EXPORT_DECLARE(void, NativeObject, clear0)(SIGHT_STDARGS,
17 years, 3 months
JBoss Native SVN: r1079 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-03 04:03:29 -0400 (Wed, 03 Oct 2007)
New Revision: 1079
Modified:
trunk/sight/native/os/solaris/memory.c
Log:
Add missing field.
Modified: trunk/sight/native/os/solaris/memory.c
===================================================================
--- trunk/sight/native/os/solaris/memory.c 2007-10-03 07:28:01 UTC (rev 1078)
+++ trunk/sight/native/os/solaris/memory.c 2007-10-03 08:03:29 UTC (rev 1079)
@@ -204,6 +204,7 @@
SET_IFIELD_J(0000, thiz, psinfo.pr_size * 1024);
SET_IFIELD_J(0008, thiz, psinfo.pr_rssize * 1024);
/* XXX: shared mem size ??? SET_IFIELD_J(0009, thiz, vals[2] * pgsz); */
+ SET_IFIELD_I(0007, thiz, pgsz);
}
return APR_SUCCESS;
17 years, 3 months
JBoss Native SVN: r1078 - trunk/sight/examples/org/jboss/sight.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-03 03:28:01 -0400 (Wed, 03 Oct 2007)
New Revision: 1078
Modified:
trunk/sight/examples/org/jboss/sight/Load.java
Log:
Add println to make output readable.
Modified: trunk/sight/examples/org/jboss/sight/Load.java
===================================================================
--- trunk/sight/examples/org/jboss/sight/Load.java 2007-10-03 07:14:45 UTC (rev 1077)
+++ trunk/sight/examples/org/jboss/sight/Load.java 2007-10-03 07:28:01 UTC (rev 1078)
@@ -106,6 +106,7 @@
Process proc = Process.self();
System.out.println("Process ID : " + proc.Id);
+ System.out.println("************ PROCESS environment ************");
String[] env = proc.Environment;
if (env != null) {
System.out.println("Process ENV lenght : " + env.length);
@@ -127,6 +128,7 @@
Thread.sleep(1000);
+ System.out.println("************ PROCESS arguments ************");
String[] cmd = proc.Arguments;
System.out.println("Process CMD lenght : " + cmd.length);
for (int i = 0; i < cmd.length; i++) {
@@ -134,12 +136,14 @@
}
+ System.out.println("************ PROCESS loaded modules ************");
for (Module mod : proc.getModules()) {
System.out.println("Module: " + mod.Size + "\t\t" + mod.Name);
}
mem.refresh();
+ System.out.println("************ SYSTEM ************");
System.out.println("Total RAM : " + mem.Physical);
System.out.println("Avail RAM : " + mem.AvailPhysical);
System.out.println("Total Swap : " + mem.Swap);
@@ -152,6 +156,7 @@
Memory mself = proc.getMemory();
+ System.out.println("************ PROCESS ************");
System.out.println("Total RAM : " + mself.Physical);
System.out.println("Avail RAM : " + mself.AvailPhysical);
System.out.println("Total Swap : " + mself.Swap);
17 years, 3 months
JBoss Native SVN: r1077 - trunk/sight/test/org/jboss/sight.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-03 03:14:45 -0400 (Wed, 03 Oct 2007)
New Revision: 1077
Modified:
trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
Log:
Revert test size length
Modified: trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-03 07:03:41 UTC (rev 1076)
+++ trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-03 07:14:45 UTC (rev 1077)
@@ -76,7 +76,7 @@
throws Exception
{
- for (int i = 0; i < 100000; i++) {
+ for (int i = 0; i < 1000000; i++) {
new NativeObjectTestClass();
}
// Library.clear() will force that all native objects
17 years, 3 months
JBoss Native SVN: r1076 - in trunk/sight: test/org/jboss/sight and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-03 03:03:41 -0400 (Wed, 03 Oct 2007)
New Revision: 1076
Modified:
trunk/sight/native/share/dir.c
trunk/sight/test/org/jboss/sight/DirectoryTest.java
trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
Log:
Fix Directory JNI call reference counter
Modified: trunk/sight/native/share/dir.c
===================================================================
--- trunk/sight/native/share/dir.c 2007-10-03 06:32:40 UTC (rev 1075)
+++ trunk/sight/native/share/dir.c 2007-10-03 07:03:41 UTC (rev 1076)
@@ -284,7 +284,7 @@
SIGHT_GLOBAL_TRY {
rv = apr_dir_remove(J2S(name), NULL);
- }
+ } SIGHT_GLOBAL_END();
SIGHT_FREE_CSTRING(name);
return rv;
}
Modified: trunk/sight/test/org/jboss/sight/DirectoryTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/DirectoryTest.java 2007-10-03 06:32:40 UTC (rev 1075)
+++ trunk/sight/test/org/jboss/sight/DirectoryTest.java 2007-10-03 07:03:41 UTC (rev 1076)
@@ -43,7 +43,7 @@
protected void setUp()
throws Exception
{
- Library.initialize(null);
+ Library.initialize("");
}
protected void tearDown()
Modified: trunk/sight/test/org/jboss/sight/MemoryLeakTest.java
===================================================================
--- trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-03 06:32:40 UTC (rev 1075)
+++ trunk/sight/test/org/jboss/sight/MemoryLeakTest.java 2007-10-03 07:03:41 UTC (rev 1076)
@@ -63,7 +63,7 @@
protected void setUp()
throws Exception
{
- Library.initialize(null);
+ Library.initialize("");
}
protected void tearDown()
@@ -76,7 +76,7 @@
throws Exception
{
- for (int i = 0; i < 1000000; i++) {
+ for (int i = 0; i < 100000; i++) {
new NativeObjectTestClass();
}
// Library.clear() will force that all native objects
17 years, 3 months
JBoss Native SVN: r1075 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-03 02:32:40 -0400 (Wed, 03 Oct 2007)
New Revision: 1075
Modified:
trunk/sight/native/os/linux/scm.c
Log:
Seal Linux service JNI calls
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-10-03 06:19:24 UTC (rev 1074)
+++ trunk/sight/native/os/linux/scm.c 2007-10-03 06:32:40 UTC (rev 1075)
@@ -56,7 +56,7 @@
NULL,
0
}
-};
+};
static void scm_cleanup(int mode, sight_object_t *no)
{
@@ -79,6 +79,7 @@
DIR *sd = NULL;
scm_instance_t *si;
sight_object_t *no = J2P(instance, sight_object_t *);
+ apr_status_t rv;
UNREFERENCED_O;
UNREFERENCED(database);
@@ -87,65 +88,69 @@
if (!no || !no->pool) {
return APR_EINVAL;
}
- if (no->native)
- scm_cleanup(0, no);
- if (!(si = (scm_instance_t *)sight_calloc(_E,
- sizeof(scm_instance_t),
- THROW_FMARK))) {
- return apr_get_os_error();
- }
- no->native = si;
- while (scm_paths[i].flavor) {
- char sname[PATH_MAX];
- struct stat sb;
- if ((sd = opendir(scm_paths[i].idpath))) {
- sprintf(sname, scm_paths[i].rlpath, scm_paths[i].rlevel);
- /* Check default run level path */
- if (stat(sname, &sb) < 0) {
- closedir(sd);
- sd = NULL;
- continue;
- }
- si->flavor = scm_paths[i].flavor;
- si->idpath = scm_paths[i].idpath;
- si->rlpath = scm_paths[i].rlpath;
- si->what = scm_paths[i].rlevel;
- if (!(si->services = sight_arr_new(16))) {
- apr_status_t rv = apr_get_os_error();
- closedir(sd);
- scm_cleanup(0, no);
- return rv;
- }
- break;
+ SIGHT_LOCAL_TRY(no) {
+ if (no->native)
+ scm_cleanup(0, no);
+ if (!(si = (scm_instance_t *)sight_calloc(_E,
+ sizeof(scm_instance_t),
+ THROW_FMARK))) {
+ SIGHT_LOCAL_BRK(no);
+ return apr_get_os_error();
}
- i++;
- }
- if (sd) {
- struct dirent *sent, sbuf;
- while (!readdir_r(sd, &sbuf, &sent)) {
+ no->native = si;
+ while (scm_paths[i].flavor) {
char sname[PATH_MAX];
struct stat sb;
- if (!sent)
+ if ((sd = opendir(scm_paths[i].idpath))) {
+ sprintf(sname, scm_paths[i].rlpath, scm_paths[i].rlevel);
+ /* Check default run level path */
+ if (stat(sname, &sb) < 0) {
+ closedir(sd);
+ sd = NULL;
+ continue;
+ }
+ si->flavor = scm_paths[i].flavor;
+ si->idpath = scm_paths[i].idpath;
+ si->rlpath = scm_paths[i].rlpath;
+ si->what = scm_paths[i].rlevel;
+ if (!(si->services = sight_arr_new(16))) {
+ rv = apr_get_os_error();
+ closedir(sd);
+ scm_cleanup(0, no);
+ SIGHT_LOCAL_BRK(no);
+ return rv;
+ }
break;
- strcpy(sname, si->idpath);
- strcat(sname, sent->d_name);
- if (stat(sname, &sb) < 0)
- continue;
- if (!S_ISREG(sb.st_mode))
- continue;
- if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
- continue;
- sight_arr_add(si->services, sent->d_name);
+ }
+ i++;
}
- closedir(sd);
- no->clean = scm_cleanup;
- return APR_SUCCESS;
- }
- else {
- apr_status_t rv = apr_get_os_error();
- scm_cleanup(0, no);
- return rv;
- }
+ if (sd) {
+ struct dirent *sent, sbuf;
+ while (!readdir_r(sd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, si->idpath);
+ strcat(sname, sent->d_name);
+ if (stat(sname, &sb) < 0)
+ continue;
+ if (!S_ISREG(sb.st_mode))
+ continue;
+ if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+ continue;
+ sight_arr_add(si->services, sent->d_name);
+ }
+ closedir(sd);
+ no->clean = scm_cleanup;
+ rv = APR_SUCCESS;
+ }
+ else {
+ rv = apr_get_os_error();
+ scm_cleanup(0, no);
+ }
+ } SIGHT_LOCAL_END(no);
+ return rv;
}
SIGHT_EXPORT_DECLARE(void, ServiceControlManager, close0)(SIGHT_STDARGS,
@@ -175,37 +180,39 @@
if (!no || !no->pool || !no->native) {
return NULL;
}
- if (drivers) {
- /* There are no drivers on linux ?
- * Perhaps we should have here the kernel modules
- */
- return NULL;
- }
- si = (scm_instance_t *)no->native;
- if (what > 0)
- si->what = what;
- if (si->services && si->services->siz) {
- jint i;
- /* TODO: Calculate size according to the flags */
- cnt = si->services->siz;
- ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
- if (!ea || (*_E)->ExceptionCheck(_E)) {
- ea = NULL;
- goto cleanup;
+ SIGHT_LOCAL_TRY(no) {
+ if (drivers) {
+ /* There are no drivers on linux ?
+ * Perhaps we should have here the kernel modules
+ */
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
}
- for (i = 0; i < cnt; i++) {
- jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
- if (s)
- (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
- else
- break;
- if ((*_E)->ExceptionCheck(_E)) {
- ea = NULL;
- break;
+ si = (scm_instance_t *)no->native;
+ if (what > 0)
+ si->what = what;
+ if (si->services && si->services->siz) {
+ jint i;
+ /* TODO: Calculate size according to the flags */
+ cnt = si->services->siz;
+ ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
+ if (!ea || (*_E)->ExceptionCheck(_E)) {
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
}
- (*_E)->DeleteLocalRef(_E, s);
- }
- }
-cleanup:
+ for (i = 0; i < cnt; i++) {
+ jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ if (s)
+ (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
+ else
+ break;
+ if ((*_E)->ExceptionCheck(_E)) {
+ ea = NULL;
+ break;
+ }
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ }
+ } SIGHT_LOCAL_END(no);
return ea;
}
17 years, 3 months
JBoss Native SVN: r1074 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-03 02:19:24 -0400 (Wed, 03 Oct 2007)
New Revision: 1074
Modified:
trunk/sight/native/os/linux/process.c
Log:
Seal Linux process JNI calls
Modified: trunk/sight/native/os/linux/process.c
===================================================================
--- trunk/sight/native/os/linux/process.c 2007-10-02 20:29:19 UTC (rev 1073)
+++ trunk/sight/native/os/linux/process.c 2007-10-03 06:19:24 UTC (rev 1074)
@@ -249,27 +249,27 @@
UNREFERENCED_O;
- if ((rc = sight_create_pool(&pool, sight_temp_pool)) != APR_SUCCESS) {
- throwAprMemoryException(_E, THROW_FMARK, rc);
- return NULL;
+ SIGHT_GLOBAL_TRY {
+ if ((rc = sight_create_pool(&pool, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ SIGHT_GLOBAL_BRK();
+ return NULL;
- }
- if (!(parr = (jint *)apr_palloc(pool, siz))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
- return NULL;
- }
- if ((rc = enum_pids(pool, parr, SIGHT_MAX_PROCESSES, &pnum)) != APR_SUCCESS) {
- throwAprException(_E, rc);
- goto cleanup;
- }
-
- if (!(rv = (*_E)->NewIntArray(_E, pnum)))
- goto cleanup;
- (*_E)->SetIntArrayRegion(_E, rv, 0, pnum, parr);
-cleanup:
- apr_pool_destroy(pool);
-
+ }
+ if (!(parr = (jint *)apr_palloc(pool, siz))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ SIGHT_GLOBAL_BRK();
+ return NULL;
+ }
+ if ((rc = enum_pids(pool, parr, SIGHT_MAX_PROCESSES, &pnum)) == APR_SUCCESS) {
+ if ((rv = (*_E)->NewIntArray(_E, pnum)))
+ (*_E)->SetIntArrayRegion(_E, rv, 0, pnum, parr);
+ }
+ else
+ throwAprException(_E, rc);
+ apr_pool_destroy(pool);
+ } SIGHT_GLOBAL_END();
return rv;
}
@@ -453,99 +453,101 @@
return APR_EINVAL;
sprintf(pname, "/proc/%d", pid);
- if ((rv = apr_stat(&i, pname,
- APR_FINFO_MIN | APR_FINFO_OWNER,
- no->pool)) != APR_SUCCESS)
- return rv;
+ SIGHT_LOCAL_TRY(no) {
+ if ((rv = apr_stat(&i, pname,
+ APR_FINFO_MIN | APR_FINFO_OWNER,
+ no->pool)) != APR_SUCCESS) {
+ SIGHT_LOCAL_BRK(no);
+ return rv;
+ }
+ sprintf(pname, "/proc/%d/cmdline", pid);
+ if ((s = sight_fread(pname))) {
+ SET_IFIELD_S(0001, thiz, s);
+ SET_IFIELD_O(0003, thiz, sight_mc_to_sa(_E, s));
+ free(s);
+ }
- sprintf(pname, "/proc/%d/cmdline", pid);
- if ((s = sight_fread(pname))) {
- SET_IFIELD_S(0001, thiz, s);
- SET_IFIELD_O(0003, thiz, sight_mc_to_sa(_E, s));
- free(s);
- }
+ sprintf(pname, "/proc/%d/environ", pid);
+ if ((s = sight_fread(pname))) {
+ SET_IFIELD_O(0004, thiz, sight_mc_to_sa(_E, s));
+ free(s);
+ }
+ sprintf(pname, "/proc/%d/cwd", pid);
+ if ((rc = readlink(pname, psname, SIGHT_HBUFFER_LEN)) > 0 ) {
+ psname[rc] = '\0';
+ SET_IFIELD_S(0018, thiz, psname);
+ }
+ sprintf(pname, "/proc/%d/stat", pid);
+ if ((s = sight_fread(pname))) {
+ int pspid, psppid, pspgid, nthreads;
+ char psstate;
+ unsigned long utime, stime;
+ unsigned long long starttime;
+ sight_procstate_e pstate;
- sprintf(pname, "/proc/%d/environ", pid);
- if ((s = sight_fread(pname))) {
- SET_IFIELD_O(0004, thiz, sight_mc_to_sa(_E, s));
- free(s);
- }
- sprintf(pname, "/proc/%d/cwd", pid);
- if ((rc = readlink(pname, psname, SIGHT_HBUFFER_LEN)) > 0 ) {
- psname[rc] = '\0';
- SET_IFIELD_S(0018, thiz, psname);
- }
- sprintf(pname, "/proc/%d/stat", pid);
- if ((s = sight_fread(pname))) {
- int pspid, psppid, pspgid, nthreads;
- char psstate;
- unsigned long utime, stime;
- unsigned long long starttime;
- sight_procstate_e pstate;
-
- /* fs/proc/array.c for 2.6 kernel (42 fields)
- rc = sscanf(s,
- "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
- "%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu "
- "%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu",
- fs/proc/array.c for 2.4 kernel (39 fields)
- rc = sscanf(s,
- "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
- "%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu "
- "%lu %lu %lu %lu %lu %lu %lu %lu %d %d",
- */
- rc = sscanf(s,
- "%d (%[^)]) %c %d %d %*d %*d %*d %*u %*u "
- "%*u %*u %*u %lu %lu %*d %*d %*d %*d %d "
- "%*d %llu",
- &pspid,
- psname,
- &psstate,
- &psppid,
- &pspgid,
- &utime,
- &stime,
- &nthreads,
- &starttime
- );
- SET_IFIELD_I(0000, thiz, psppid);
- SET_IFIELD_S(0002, thiz, psname);
- switch(psstate) {
- case 'R':
- pstate = SIGHT_PROC_R;
- break;
- case 'S':
- pstate = SIGHT_PROC_S;
- break;
- case 'D':
- pstate = SIGHT_PROC_D;
- break;
- case 'Z':
- pstate = SIGHT_PROC_Z;
- break;
- case 'T':
- pstate = SIGHT_PROC_T;
- break;
- case 'W':
- pstate = SIGHT_PROC_W;
- break;
- case 'X':
- pstate = SIGHT_PROC_X;
- break;
- default:
- pstate = SIGHT_PROC_U;
- break;
+ /* fs/proc/array.c for 2.6 kernel (42 fields)
+ rc = sscanf(s,
+ "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
+ "%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu %llu",
+ fs/proc/array.c for 2.4 kernel (39 fields)
+ rc = sscanf(s,
+ "%d (%[^)]) %c %d %d %d %d %d %lu %lu "
+ "%lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld %lu %lu %ld %lu %lu %lu %lu %lu "
+ "%lu %lu %lu %lu %lu %lu %lu %lu %d %d",
+ */
+ rc = sscanf(s,
+ "%d (%[^)]) %c %d %d %*d %*d %*d %*u %*u "
+ "%*u %*u %*u %lu %lu %*d %*d %*d %*d %d "
+ "%*d %llu",
+ &pspid,
+ psname,
+ &psstate,
+ &psppid,
+ &pspgid,
+ &utime,
+ &stime,
+ &nthreads,
+ &starttime
+ );
+ SET_IFIELD_I(0000, thiz, psppid);
+ SET_IFIELD_S(0002, thiz, psname);
+ switch(psstate) {
+ case 'R':
+ pstate = SIGHT_PROC_R;
+ break;
+ case 'S':
+ pstate = SIGHT_PROC_S;
+ break;
+ case 'D':
+ pstate = SIGHT_PROC_D;
+ break;
+ case 'Z':
+ pstate = SIGHT_PROC_Z;
+ break;
+ case 'T':
+ pstate = SIGHT_PROC_T;
+ break;
+ case 'W':
+ pstate = SIGHT_PROC_W;
+ break;
+ case 'X':
+ pstate = SIGHT_PROC_X;
+ break;
+ default:
+ pstate = SIGHT_PROC_U;
+ break;
+ }
+ SET_IFIELD_I(0005, thiz, nthreads);
+ SET_IFIELD_J(0012, thiz, apr_time_as_msec(i.ctime));
+ SET_IFIELD_J(0014, thiz, TCK2MS(stime));
+ SET_IFIELD_J(0015, thiz, TCK2MS(utime));
+ SET_IFIELD_J(0016, thiz, P2J(i.user));
+ SET_IFIELD_J(0017, thiz, P2J(i.group));
+ CALL_METHOD1(0000, thiz, pstate);
+ free(s);
}
- SET_IFIELD_I(0005, thiz, nthreads);
- SET_IFIELD_J(0012, thiz, apr_time_as_msec(i.ctime));
- SET_IFIELD_J(0014, thiz, TCK2MS(stime));
- SET_IFIELD_J(0015, thiz, TCK2MS(utime));
- SET_IFIELD_J(0016, thiz, P2J(i.user));
- SET_IFIELD_J(0017, thiz, P2J(i.group));
- CALL_METHOD1(0000, thiz, pstate);
- free(s);
- }
-
+ } SIGHT_LOCAL_END(no);
return APR_SUCCESS;
}
17 years, 3 months
JBoss Native SVN: r1073 - trunk/sight/native/os/solaris.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2007-10-02 16:29:19 -0400 (Tue, 02 Oct 2007)
New Revision: 1073
Modified:
trunk/sight/native/os/solaris/tcpstat.c
Log:
Port to Solaris.
Modified: trunk/sight/native/os/solaris/tcpstat.c
===================================================================
--- trunk/sight/native/os/solaris/tcpstat.c 2007-10-01 11:37:03 UTC (rev 1072)
+++ trunk/sight/native/os/solaris/tcpstat.c 2007-10-02 20:29:19 UTC (rev 1073)
@@ -38,14 +38,6 @@
#include <inet/mib2.h>
#include <inet/tcp.h>
-typedef struct mib_item_s {
- struct mib_item_s *next_item;
- long group;
- long mib_id;
- long length;
- char *valp;
-} mib_item_t;
-
/*
* TCP statistics implementation
*/
@@ -169,11 +161,19 @@
static const char *eiftype = "Unsupported NetworkAddressFamily type";
-/* Initialize volume enumeration */
-SIGHT_EXPORT_DECLARE(void, TcpStatistics, info0)(SIGHT_STDARGS,
- jobject thiz,
- jint iftype,
- jlong pool)
+extern apr_pool_t *sight_temp_pool;
+
+typedef struct tcpconn_enum_t {
+ int type;
+ int idx;
+ int numcons;
+ void *conn; /* mib2_tcp6ConnEntry_t / mib2_tcpConnEntry_t */
+ void *stat; /* mib2_tcp_t */
+ apr_pool_t *pool;
+} tcpconn_enum_t;
+
+/* Read the mib2 object and fill the structures */
+static void read_mib2(JNIEnv *_E, tcpconn_enum_t *e)
{
apr_status_t rc = APR_ENOTIMPL;
int sd;
@@ -181,17 +181,23 @@
int flags;
int i, j, getcode;
struct strbuf ctlbuf, databuf;
+
struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf;
struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf;
struct T_error_ack *tea = (struct T_error_ack *)buf;
+
struct opthdr *req;
- mib_item_t *last_item = NULL;
+ int numcons = 0;
- UNREFERENCED_O;
-
- if ((sd = open("/dev/tcp", O_RDWR)) < 0) {
+ if ((sd = open("/dev/arp", O_RDWR)) < 0) {
throwAprException(_E, apr_get_os_error());
+ return;
}
+ if (ioctl(sd, I_PUSH, "tcp") <0) {
+ close(sd);
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
tor->PRIM_type = T_SVR4_OPTMGMT_REQ;
tor->OPT_offset = sizeof (struct T_optmgmt_req);
@@ -208,52 +214,103 @@
if (putmsg(sd, &ctlbuf, (struct strbuf *)0, flags) == -1) {
close(sd);
throwAprException(_E, apr_get_os_error());
+ return;
}
- req = (struct opthdr *)&toa[1];
- ctlbuf.maxlen = sizeof (buf);
- flags = 0;
- if (getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags) == -1) {
- close(sd);
- throwAprException(_E, apr_get_os_error());
- }
+ for(;;) {
+ req = (struct opthdr *)&toa[1];
+ ctlbuf.buf = (char *) buf;
+ ctlbuf.maxlen = sizeof (buf);
+ flags = 0;
+ if (getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags) == -1) {
+ close(sd);
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
+ if (toa->PRIM_type == T_OPTMGMT_ACK &&
+ toa->MGMT_flags == T_SUCCESS &&
+ req->len == 0)
+ break; /* done */
- last_item = (mib_item_t *)malloc(sizeof (mib_item_t));;
- last_item->next_item = NULL;
- last_item->group = req->level;
- last_item->mib_id = req->name;
- last_item->length = req->len;
- last_item->valp = malloc((int)req->len);
+ /* read the data */
+ databuf.maxlen = req->len;
+ databuf.buf = malloc((int)req->len);
+ databuf.len = 0;
+ flags = 0;
+ if (getmsg(sd, (struct strbuf *)0, &databuf, &flags) == -1) {
+ close(sd);
+ throwAprException(_E, apr_get_os_error());
+ return;
+ }
- databuf.maxlen = last_item->length;
- databuf.buf = (char *)last_item->valp;
- databuf.len = 0;
- flags = 0;
- if (getmsg(sd, (struct strbuf *)0, &databuf, &flags) == -1) {
- close(sd);
- throwAprException(_E, apr_get_os_error());
+ /* Process the TPC statics */
+ if ((req->level == MIB2_TCP && req->name == 0 && e->type == 1) ||
+ (req->level == MIB2_TCP6 && req->name == 0 && e->type == 2)) {
+ e->stat = (void *) databuf.buf;
+ } else if (req->level == MIB2_TCP && req->name == MIB2_TCP_CONN && e->type == 1) {
+ /* Process the TPC4 statics */
+ mib2_tcpConnEntry_t *tcp = (mib2_tcpConnEntry_t *)databuf.buf;
+ char *end;
+ int numcons = 0;
+ end = (char*) tcp + databuf.len;
+ while ((char*) tcp < end) {
+ numcons++;
+ tcp++;
+ }
+ e->conn = (void *) databuf.buf;
+ e->numcons = numcons;
+ } else if (req->level == MIB2_TCP6 && req->name == MIB2_TCP6_CONN && e->type == 2) {
+ /* Process the TPC6 statics */
+ mib2_tcp6ConnEntry_t *tcp = (mib2_tcp6ConnEntry_t *)databuf.buf;
+ char *end;
+ int numcons = 0;
+ end = (char*) tcp + databuf.len;
+ while ((char*) tcp < end) {
+ numcons++;
+ tcp++;
+ }
+ e->conn = (void *) databuf.buf;
+ e->numcons = numcons;
+ } /* else {
+ printf("Missing logic info0: level %d name %d\n", req->level, req->name);
+ } */
}
close(sd);
+}
- for (; last_item; last_item = last_item->next_item) {
- if (last_item->group == MIB2_TCP) {
- mib2_tcp_t *tcp = (mib2_tcp_t *)last_item->valp;
- SET_IFIELD_I(0000, thiz, tcp->tcpRtoMin);
- SET_IFIELD_I(0001, thiz, tcp->tcpRtoMax);
- SET_IFIELD_I(0002, thiz, tcp->tcpMaxConn);
- SET_IFIELD_I(0003, thiz, tcp->tcpActiveOpens);
- SET_IFIELD_I(0004, thiz, tcp->tcpPassiveOpens);
- SET_IFIELD_I(0005, thiz, tcp->tcpAttemptFails);
- SET_IFIELD_I(0006, thiz, tcp->tcpEstabResets);
- SET_IFIELD_I(0007, thiz, tcp->tcpCurrEstab);
- SET_IFIELD_I(0008, thiz, tcp->tcpInSegs);
- SET_IFIELD_I(0009, thiz, tcp->tcpOutSegs);
- SET_IFIELD_I(0010, thiz, tcp->tcpRetransSegs);
+/* Initialize volume enumeration */
+SIGHT_EXPORT_DECLARE(void, TcpStatistics, info0)(SIGHT_STDARGS,
+ jobject thiz,
+ jint iftype,
+ jlong pool)
+{
+ tcpconn_enum_t *e;
+ if (!(e = (tcpconn_enum_t *)sight_calloc(_E,
+ sizeof(tcpconn_enum_t),
+ THROW_FMARK))) {
+ return;
+ }
+ e->type = iftype;
+ read_mib2(_E, e);
- SET_IFIELD_I(0012, thiz, tcp->tcpOutRsts);
+ if (e->stat != NULL) {
+ mib2_tcp_t *tcp = (mib2_tcp_t *)e->stat;
+ SET_IFIELD_I(0000, thiz, tcp->tcpRtoMin);
+ SET_IFIELD_I(0001, thiz, tcp->tcpRtoMax);
+ SET_IFIELD_I(0002, thiz, tcp->tcpMaxConn);
+ SET_IFIELD_I(0003, thiz, tcp->tcpActiveOpens);
+ SET_IFIELD_I(0004, thiz, tcp->tcpPassiveOpens);
+ SET_IFIELD_I(0005, thiz, tcp->tcpAttemptFails);
+ SET_IFIELD_I(0006, thiz, tcp->tcpEstabResets);
+ SET_IFIELD_I(0007, thiz, tcp->tcpCurrEstab);
+ SET_IFIELD_I(0008, thiz, tcp->tcpInSegs);
+ SET_IFIELD_I(0009, thiz, tcp->tcpOutSegs);
+ SET_IFIELD_I(0010, thiz, tcp->tcpRetransSegs);
- }
+ SET_IFIELD_I(0012, thiz, tcp->tcpOutRsts);
}
+
+ SET_IFIELD_I(0013, thiz, e->numcons);
}
/* Initialize TCP conn enumeration */
@@ -261,14 +318,43 @@
jint iftype,
jlong pool)
{
- return 0;
+ tcpconn_enum_t *e;
+ apr_status_t rc;
+
+ UNREFERENCED_O;
+ if (iftype < 1 || iftype > 2) {
+ throwOSException(_E, eiftype);
+ return 0;
+ }
+
+ if (!(e = (tcpconn_enum_t *)sight_calloc(_E,
+ sizeof(tcpconn_enum_t),
+ THROW_FMARK))) {
+ return 0;
+ }
+
+ if ((rc = sight_create_pool(&e->pool, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ return 0;
+ }
+ e->type = iftype;
+ read_mib2(_E, e);
+
+ return P2J(e);
}
/* Get the number of entries */
SIGHT_EXPORT_DECLARE(jint, TcpStatistics, enum1)(SIGHT_STDARGS,
jlong handle)
{
- return 0;
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
+ UNREFERENCED_STDARGS;
+ if (e) {
+ e->idx = 1;
+ return e->numcons;
+ } else {
+ return 0;
+ }
}
SIGHT_EXPORT_DECLARE(void, TcpStatistics, enum2)(SIGHT_STDARGS,
@@ -276,12 +362,63 @@
jint index,
jlong handle)
{
+ tcpconn_enum_t *e = J2P(handle, tcpconn_enum_t *);
+ char las[128] = "";
+ char ras[128] = "";
+ jobject la, ra;
+ jint lp = 0, rp = 0;
+ jint st;
+ if (!e)
+ return;
+ if (e->idx > e->numcons) {
+ return;
+ }
+ if (e->type == 1) {
+ mib2_tcpConnEntry_t *tcp = (mib2_tcpConnEntry_t *) e->conn;
+ int i;
+ for (i=1; i<e->idx; i++)
+ tcp++;
+ inet_ntop(AF_INET, &tcp->tcpConnLocalAddress, las, 64);
+ inet_ntop(AF_INET, &tcp->tcpConnRemAddress, ras, 64);
+ lp = tcp->tcpConnLocalPort;
+ rp = tcp->tcpConnRemPort;
+ st = tcp->tcpConnState;
+ } else {
+ mib2_tcp6ConnEntry_t *tcp = (mib2_tcp6ConnEntry_t *) e->conn;
+ int i;
+ for (i=1; i<e->idx; i++)
+ tcp++;
+ sight_inet_ntop6(tcp->tcp6ConnLocalAddress.s6_addr, las, 64);
+ sight_inet_ntop6(tcp->tcp6ConnRemAddress.s6_addr, ras, 64);
+ lp = tcp->tcp6ConnLocalPort;
+ rp = tcp->tcp6ConnRemPort;
+ st = tcp->tcp6ConnState;
+ }
+ sight_tcpconn_set_tmo(_E, conn, 0);
+ sight_tcpconn_set_cts(_E, conn, 0);
+ sight_tcpconn_set_pid(_E, conn, 0);
+
+ sight_tcpconn_set_state(_E, conn, st);
+
+ la = sight_new_netaddr_class(_E, _O);
+ sight_netaddr_set_addr(_E, la, las);
+ sight_netaddr_set_port(_E, la, lp);
+ sight_tcpconn_set_local(_E, conn, la);
+ (*_E)->DeleteLocalRef(_E, la);
+
+ ra = sight_new_netaddr_class(_E, _O);
+ sight_netaddr_set_addr(_E, ra, ras);
+ sight_netaddr_set_port(_E, ra, rp);
+ sight_tcpconn_set_remote(_E, conn, ra);
+ (*_E)->DeleteLocalRef(_E, ra);
+
+ e->idx++;
}
/* Close TCP conn enumeration */
SIGHT_EXPORT_DECLARE(void, TcpStatistics, enum3)(SIGHT_STDARGS,
jlong handle)
{
-
+ /* XXX: Add cleanup */
}
17 years, 3 months
JBoss Native SVN: r1072 - in trunk/sight/native: share and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 07:37:03 -0400 (Mon, 01 Oct 2007)
New Revision: 1072
Modified:
trunk/sight/native/os/windows/console.c
trunk/sight/native/os/windows/process.c
trunk/sight/native/share/library.c
trunk/sight/native/share/proc.c
Log:
Add progresive use detection
Modified: trunk/sight/native/os/windows/console.c
===================================================================
--- trunk/sight/native/os/windows/console.c 2007-10-01 10:29:06 UTC (rev 1071)
+++ trunk/sight/native/os/windows/console.c 2007-10-01 11:37:03 UTC (rev 1072)
@@ -59,9 +59,8 @@
sight_nt_console_t *con;
UNREFERENCED_O;
- if (!(con = (sight_nt_console_t *)calloc(1, sizeof(sight_nt_console_t)))) {
- throwAprMemoryException(_E, THROW_FMARK,
- apr_get_os_error());
+ if (!(con = (sight_nt_console_t *)sight_calloc(_E, sizeof(sight_nt_console_t),
+ THROW_FMARK))) {
return 0;
}
return P2J(con);
Modified: trunk/sight/native/os/windows/process.c
===================================================================
--- trunk/sight/native/os/windows/process.c 2007-10-01 10:29:06 UTC (rev 1071)
+++ trunk/sight/native/os/windows/process.c 2007-10-01 11:37:03 UTC (rev 1072)
@@ -386,128 +386,133 @@
#ifdef SIGHT_DO_STATS
no->clean = proc_cleanup;
#endif
- if (!find_pe32(pid, &pe32)) {
- /* System pids have low values */
- if (pid > 10)
- return APR_ENOENT;
- // Check if this is needed at all.
- lstrcpyW(pe32.szExeFile, L"Unknown");
- }
- else {
- ppid = pe32.th32ParentProcessID;
- tcnt = pe32.cntThreads;
- }
- if (pid == (jint)GetCurrentProcessId())
- hProcess = GetCurrentProcess();
- else {
- if (!(hProcess = OpenProcess(READ_CONTROL | PROCESS_VM_READ |
- PROCESS_QUERY_INFORMATION,
- FALSE, pid))) {
+ SIGHT_LOCAL_TRY(no) {
+ if (!find_pe32(pid, &pe32)) {
+ /* System pids have low values */
+ if (pid > 10) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_ENOENT;
+ }
+ // Check if this is needed at all.
+ lstrcpyW(pe32.szExeFile, L"Unknown");
+ }
+ else {
+ ppid = pe32.th32ParentProcessID;
+ tcnt = pe32.cntThreads;
+ }
+ if (pid == (jint)GetCurrentProcessId())
+ hProcess = GetCurrentProcess();
+ else {
+ if (!(hProcess = OpenProcess(READ_CONTROL | PROCESS_VM_READ |
+ PROCESS_QUERY_INFORMATION,
+ FALSE, pid))) {
+ SET_IFIELD_W(0002, thiz, pe32.szExeFile);
+ SET_IFIELD_J(0000, thiz, ppid);
+ SET_IFIELD_J(0005, thiz, tcnt);
+ CALL_METHOD1(0000, thiz, SIGHT_PROC_R);
+ SIGHT_LOCAL_BRK(no);
+ return APR_SUCCESS;
+ }
+ }
+ if (GetModuleFileNameExW(hProcess, NULL, buf, SIGHT_STYPE_LEN)) {
+ SET_IFIELD_W(0001, thiz, buf);
+ }
+ if (GetModuleBaseNameW(hProcess, NULL, buf, SIGHT_STYPE_LEN)) {
+ SET_IFIELD_W(0002, thiz, buf);
+ }
+ else {
SET_IFIELD_W(0002, thiz, pe32.szExeFile);
- SET_IFIELD_J(0000, thiz, ppid);
- SET_IFIELD_J(0005, thiz, tcnt);
+ }
+ if (GetProcessIoCounters(hProcess, &ioc)) {
+ SET_IFIELD_J(0006, thiz, ioc.ReadOperationCount);
+ SET_IFIELD_J(0007, thiz, ioc.WriteOperationCount);
+ SET_IFIELD_J(0008, thiz, ioc.OtherOperationCount);
+ SET_IFIELD_J(0009, thiz, ioc.ReadTransferCount);
+ SET_IFIELD_J(0010, thiz, ioc.WriteTransferCount);
+ SET_IFIELD_J(0011, thiz, ioc.OtherTransferCount);
+ }
+ if (GetProcessTimes(hProcess, &ft[0], &ft[1], &ft[2], &ft[3])) {
+ et = winftime_to_ms(&ft[1]);
+ SET_IFIELD_J(0012, thiz, winftime_to_ms(&ft[0]));
+ SET_IFIELD_J(0013, thiz, et);
+ SET_IFIELD_J(0014, thiz, filetime_to_ms(&ft[2]));
+ SET_IFIELD_J(0015, thiz, filetime_to_ms(&ft[3]));
+ }
+ if (et) {
+ CALL_METHOD1(0000, thiz, SIGHT_PROC_T);
+ }
+ else {
CALL_METHOD1(0000, thiz, SIGHT_PROC_R);
- return APR_SUCCESS;
}
- }
- if (GetModuleFileNameExW(hProcess, NULL, buf, SIGHT_STYPE_LEN)) {
- SET_IFIELD_W(0001, thiz, buf);
- }
- if (GetModuleBaseNameW(hProcess, NULL, buf, SIGHT_STYPE_LEN)) {
- SET_IFIELD_W(0002, thiz, buf);
- }
- else {
- SET_IFIELD_W(0002, thiz, pe32.szExeFile);
- }
- if (GetProcessIoCounters(hProcess, &ioc)) {
- SET_IFIELD_J(0006, thiz, ioc.ReadOperationCount);
- SET_IFIELD_J(0007, thiz, ioc.WriteOperationCount);
- SET_IFIELD_J(0008, thiz, ioc.OtherOperationCount);
- SET_IFIELD_J(0009, thiz, ioc.ReadTransferCount);
- SET_IFIELD_J(0010, thiz, ioc.WriteTransferCount);
- SET_IFIELD_J(0011, thiz, ioc.OtherTransferCount);
- }
- if (GetProcessTimes(hProcess, &ft[0], &ft[1], &ft[2], &ft[3])) {
- et = winftime_to_ms(&ft[1]);
- SET_IFIELD_J(0012, thiz, winftime_to_ms(&ft[0]));
- SET_IFIELD_J(0013, thiz, et);
- SET_IFIELD_J(0014, thiz, filetime_to_ms(&ft[2]));
- SET_IFIELD_J(0015, thiz, filetime_to_ms(&ft[3]));
- }
- if (et) {
- CALL_METHOD1(0000, thiz, SIGHT_PROC_T);
- }
- else {
- CALL_METHOD1(0000, thiz, SIGHT_PROC_R);
- }
- /* XXX: Reading process memory is a hack.
- */
- if (pid != (jint)GetCurrentProcessId()) {
- read_proc_pages(pid, hProcess, &ppages[0], no->pool);
- if (ppages[0].str.w && (*ppages[0].str.w > 0x003C && *ppages[0].str.w < 0x007F)) {
- SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, ppages[0].str.w));
- }
- if (ppages[1].str.w) {
- mproc = ppages[spage+1].str.w;
- mpnrd = ppages[spage+1].len;
- }
- if (mproc && mpnrd) {
- SIZE_T pO = NT32_CWDOFF;
- LPWSTR p1, p2, e1;
- int l1, l2;
- if ((p1 = (LPWSTR)get_procc_base(mproc, mpnrd, &pO))) {
- SET_IFIELD_W(0018, thiz, p1);
+ /* XXX: Reading process memory is a hack.
+ */
+ if (pid != (jint)GetCurrentProcessId()) {
+ read_proc_pages(pid, hProcess, &ppages[0], no->pool);
+ if (ppages[0].str.w && (*ppages[0].str.w > 0x003C && *ppages[0].str.w < 0x007F)) {
+ SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, ppages[0].str.w));
}
- /* XXX Might not work on all Windows platforms */
- if ((p1 = (LPWSTR)get_procd_base(mproc, mpnrd, pO))) {
- LPWSTR *args;
- /* p1 Process PATH */
- l1 = lstrlenW(p1) + 1;
- p2 = (LPWSTR)ALIGN_TO_DWORD(p1 + l1);
- /* p2 Process Executable */
- l2 = lstrlenW(p2) + 1;
- e1 = (LPWSTR)ALIGN_TO_DWORD(p2 + l2);
- /* e1 Process Cmdline */
- args = (LPWSTR *)CommandLineToArgvW(e1, &l1);
- if (args) {
- SET_IFIELD_O(0003, thiz, sight_aw_to_sa(_E, args, l1));
- LocalFree(args);
+ if (ppages[1].str.w) {
+ mproc = ppages[spage+1].str.w;
+ mpnrd = ppages[spage+1].len;
+ }
+ if (mproc && mpnrd) {
+ SIZE_T pO = NT32_CWDOFF;
+ LPWSTR p1, p2, e1;
+ int l1, l2;
+ if ((p1 = (LPWSTR)get_procc_base(mproc, mpnrd, &pO))) {
+ SET_IFIELD_W(0018, thiz, p1);
}
+ /* XXX Might not work on all Windows platforms */
+ if ((p1 = (LPWSTR)get_procd_base(mproc, mpnrd, pO))) {
+ LPWSTR *args;
+ /* p1 Process PATH */
+ l1 = lstrlenW(p1) + 1;
+ p2 = (LPWSTR)ALIGN_TO_DWORD(p1 + l1);
+ /* p2 Process Executable */
+ l2 = lstrlenW(p2) + 1;
+ e1 = (LPWSTR)ALIGN_TO_DWORD(p2 + l2);
+ /* e1 Process Cmdline */
+ args = (LPWSTR *)CommandLineToArgvW(e1, &l1);
+ if (args) {
+ SET_IFIELD_O(0003, thiz, sight_aw_to_sa(_E, args, l1));
+ LocalFree(args);
+ }
+ }
}
}
- }
- else {
- LPVOID env;
- LPWSTR cmdl;
- int pargc;
- LPWSTR *pargs;
+ else {
+ LPVOID env;
+ LPWSTR cmdl;
+ int pargc;
+ LPWSTR *pargs;
- if ((env = GetEnvironmentStringsW())) {
- SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, env));
- FreeEnvironmentStrings(env);
- }
+ if ((env = GetEnvironmentStringsW())) {
+ SET_IFIELD_O(0004, thiz, sight_mw_to_sa(_E, env));
+ FreeEnvironmentStrings(env);
+ }
- if ((cmdl = GetCommandLineW())) {
- pargs = (LPWSTR *)CommandLineToArgvW(cmdl, &pargc);
- if (pargs) {
- SET_IFIELD_O(0003, thiz, sight_aw_to_sa(_E, pargs, pargc));
- LocalFree(pargs);
+ if ((cmdl = GetCommandLineW())) {
+ pargs = (LPWSTR *)CommandLineToArgvW(cmdl, &pargc);
+ if (pargs) {
+ SET_IFIELD_O(0003, thiz, sight_aw_to_sa(_E, pargs, pargc));
+ LocalFree(pargs);
+ }
}
+ buf[0] = L'\0';
+ if (GetCurrentDirectoryW(SIGHT_STYPE_LEN, buf)) {
+ SET_IFIELD_W(0018, thiz, buf);
+ }
}
- buf[0] = L'\0';
- if (GetCurrentDirectoryW(SIGHT_STYPE_LEN, buf)) {
- SET_IFIELD_W(0018, thiz, buf);
+ if (sight_uid_get(hProcess, &uid, &gid, no->pool) == APR_SUCCESS) {
+ SET_IFIELD_J(0016, thiz, P2J(uid));
+ SET_IFIELD_J(0017, thiz, P2J(gid));
}
- }
- if (sight_uid_get(hProcess, &uid, &gid, no->pool) == APR_SUCCESS) {
- SET_IFIELD_J(0016, thiz, P2J(uid));
- SET_IFIELD_J(0017, thiz, P2J(gid));
- }
- CloseHandle(hProcess);
- SET_IFIELD_J(0000, thiz, ppid);
- SET_IFIELD_J(0005, thiz, tcnt);
+ CloseHandle(hProcess);
+ SET_IFIELD_J(0000, thiz, ppid);
+ SET_IFIELD_J(0005, thiz, tcnt);
+ } SIGHT_LOCAL_END(no);
return APR_SUCCESS;
}
Modified: trunk/sight/native/share/library.c
===================================================================
--- trunk/sight/native/share/library.c 2007-10-01 10:29:06 UTC (rev 1071)
+++ trunk/sight/native/share/library.c 2007-10-01 11:37:03 UTC (rev 1072)
@@ -228,8 +228,12 @@
fflush(stderr);
}
+#define OPTIMISTIC_LOCK_CNT 10000
+#define OPTIMISTIC_LOCK_MAX OPTIMISTIC_LOCK_CNT + 60000
+
SIGHT_EXPORT_DECLARE(void, Library, terminate0)(SIGHT_STDARGS)
{
+ apr_uint32_t ioc = 0;
UNREFERENCED_STDARGS;
/* TODO Add reference count */
@@ -242,6 +246,21 @@
while (in_object_count) {
apr_thread_yield();
in_object_count = apr_atomic_read32(sight_global_atomic);
+ if (ioc++ > OPTIMISTIC_LOCK_CNT) {
+ /* Sleep one millisecond */
+ apr_sleep(1000L);
+ }
+ if (ioc > OPTIMISTIC_LOCK_MAX) {
+ /* TODO: We have a zombie or a lengthy JNI op.
+ * Find a way to bail out without crushing JVM
+ */
+#ifdef SIGHT_DO_STATS
+ fprintf(stderr, "Library.terminate() call is locked ...\n");
+ fprintf(stderr, "Bailing out !\n");
+ fflush(stderr);
+ exit(-1);
+#endif
+ }
}
apr_pool_destroy(sight_temp_pool);
apr_pool_destroy(sight_global_pool);
Modified: trunk/sight/native/share/proc.c
===================================================================
--- trunk/sight/native/share/proc.c 2007-10-01 10:29:06 UTC (rev 1071)
+++ trunk/sight/native/share/proc.c 2007-10-01 11:37:03 UTC (rev 1072)
@@ -391,6 +391,7 @@
sight_callback_t cb;
UNREFERENCED_O;
+
if (!no || !no->native || !progress)
return APR_EINVAL;
SIGHT_LOCAL_TRY(no) {
17 years, 3 months
JBoss Native SVN: r1071 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-10-01 06:29:06 -0400 (Mon, 01 Oct 2007)
New Revision: 1071
Modified:
trunk/sight/native/os/windows/cpustat.c
Log:
Seal Windows cpustat JNI calls
Modified: trunk/sight/native/os/windows/cpustat.c
===================================================================
--- trunk/sight/native/os/windows/cpustat.c 2007-10-01 10:24:15 UTC (rev 1070)
+++ trunk/sight/native/os/windows/cpustat.c 2007-10-01 10:29:06 UTC (rev 1071)
@@ -153,78 +153,82 @@
return APR_EINVAL;
if ((DWORD)cpuid > sight_osinf->dwNumberOfProcessors)
return APR_EINVAL;
+ SIGHT_LOCAL_TRY(no) {
+ if (GetSystemTimes(&ft[0], &ft[1], &ft[2])) {
+ jt[0] = filetime_to_ms(&ft[2]);
+ jt[1] = filetime_to_ms(&ft[1]);
+ jt[2] = filetime_to_ms(&ft[0]);
+ has_aggregate = 1;
+ }
+ if (!cpuid && !has_aggregate) {
+ DWORD i;
+ for (i = 0; i < sight_osinf->dwNumberOfProcessors; i++) {
+ if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
+ (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
+ PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi =
+ (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&b[0];
- if (GetSystemTimes(&ft[0], &ft[1], &ft[2])) {
- jt[0] = filetime_to_ms(&ft[2]);
- jt[1] = filetime_to_ms(&ft[1]);
- jt[2] = filetime_to_ms(&ft[0]);
- has_aggregate = 1;
- }
- if (!cpuid && !has_aggregate) {
- DWORD i;
- for (i = 0; i < sight_osinf->dwNumberOfProcessors; i++) {
+ jt[0] += largeint_to_ms(&(pspi[i].UserTime));
+ jt[1] += largeint_to_ms(&(pspi[i].KernelTime));
+ jt[2] += largeint_to_ms(&(pspi[i].IdleTime));
+ }
+ }
+ }
+ if (cpuid) {
if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
- (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
+ (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi =
(PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&b[0];
- jt[0] += largeint_to_ms(&(pspi[i].UserTime));
- jt[1] += largeint_to_ms(&(pspi[i].KernelTime));
- jt[2] += largeint_to_ms(&(pspi[i].IdleTime));
+ jt[0] = largeint_to_ms(&(pspi[cpuid - 1].UserTime));
+ jt[1] = largeint_to_ms(&(pspi[cpuid - 1].KernelTime));
+ jt[2] = largeint_to_ms(&(pspi[cpuid - 1].IdleTime));
}
}
- }
- if (cpuid) {
- if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
- (LPVOID)&b[0], SIGHT_HBUFFER_SIZ, NULL) == 0) {
- PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi =
- (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&b[0];
-
- jt[0] = largeint_to_ms(&(pspi[cpuid - 1].UserTime));
- jt[1] = largeint_to_ms(&(pspi[cpuid - 1].KernelTime));
- jt[2] = largeint_to_ms(&(pspi[cpuid - 1].IdleTime));
- }
- }
- else {
- HANDLE hProcessSnap;
- PROCESSENTRY32 pe32;
- hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (!IS_INVALID_HANDLE(hProcessSnap)) {
- DWORD pc = 0, tc = 0;
- pe32.dwSize = sizeof(PROCESSENTRY32);
- if (Process32First(hProcessSnap, &pe32)) {
- do {
- pc += 1;
- tc += pe32.cntThreads;
- if (!cached_boot_time && (apr_strnatcasecmp(pe32.szExeFile, "smss.exe") == 0)) {
- HANDLE wp = OpenProcess(PROCESS_QUERY_INFORMATION,
- FALSE,
- pe32.th32ProcessID);
- if (!IS_INVALID_HANDLE(wp)) {
- if (GetProcessTimes(wp, &ft[0], &ft[1],
- &ft[2], &ft[3])) {
- cached_boot_time = winftime_to_ms(&ft[0]);
+ else {
+ HANDLE hProcessSnap;
+ PROCESSENTRY32 pe32;
+ hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (!IS_INVALID_HANDLE(hProcessSnap)) {
+ DWORD pc = 0, tc = 0;
+ pe32.dwSize = sizeof(PROCESSENTRY32);
+ if (Process32First(hProcessSnap, &pe32)) {
+ do {
+ if (SIGHT_LOCAL_IRQ(no)) {
+ SIGHT_LOCAL_BRK(no);
+ return APR_EINTR;
+ }
+ pc += 1;
+ tc += pe32.cntThreads;
+ if (!cached_boot_time && (apr_strnatcasecmp(pe32.szExeFile, "smss.exe") == 0)) {
+ HANDLE wp = OpenProcess(PROCESS_QUERY_INFORMATION,
+ FALSE,
+ pe32.th32ProcessID);
+ if (!IS_INVALID_HANDLE(wp)) {
+ if (GetProcessTimes(wp, &ft[0], &ft[1],
+ &ft[2], &ft[3])) {
+ cached_boot_time = winftime_to_ms(&ft[0]);
+ }
+ CloseHandle(wp);
}
- CloseHandle(wp);
}
- }
- } while(Process32Next(hProcessSnap, &pe32));
+ } while(Process32Next(hProcessSnap, &pe32));
+ }
+ CloseHandle(hProcessSnap);
+ SET_IFIELD_I(0009, thiz, pc + tc);
+ SET_IFIELD_I(0010, thiz, pc);
}
- CloseHandle(hProcessSnap);
- SET_IFIELD_I(0009, thiz, pc + tc);
- SET_IFIELD_I(0010, thiz, pc);
+ if (!cached_boot_time) {
+ GetSystemTimeAsFileTime(&ft[0]);
+ /* XXX: Using GetTickCount will give 49.7 days resolution */
+ cached_boot_time = winftime_to_ms(&ft[0]) - GetTickCount();
+ }
+ SET_IFIELD_J(0008, thiz, cached_boot_time);
+
}
- if (!cached_boot_time) {
- GetSystemTimeAsFileTime(&ft[0]);
- /* XXX: Using GetTickCount will give 49.7 days resolution */
- cached_boot_time = winftime_to_ms(&ft[0]) - GetTickCount();
- }
- SET_IFIELD_J(0008, thiz, cached_boot_time);
-
- }
- SET_IFIELD_J(0000, thiz, jt[0]);
- SET_IFIELD_J(0002, thiz, jt[1]);
- SET_IFIELD_J(0003, thiz, jt[2]);
-
+ SET_IFIELD_J(0000, thiz, jt[0]);
+ SET_IFIELD_J(0002, thiz, jt[1]);
+ SET_IFIELD_J(0003, thiz, jt[2]);
+ } SIGHT_LOCAL_END(no);
return APR_SUCCESS;
}
17 years, 3 months