Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
494ed4ed3e | ||
|
|
f12b8e32d3 | ||
|
|
9c931654d7 | ||
|
|
797d8a9edf | ||
|
|
449de48cea | ||
|
|
a04f46a647 | ||
|
|
d83284613b | ||
|
|
012dcef75d | ||
|
|
f21897f93b | ||
|
|
710a3f791b | ||
|
|
510a4b5c89 | ||
|
|
0a3f546638 | ||
|
|
a693ebce90 | ||
|
|
2d2c4c996d | ||
|
|
639169e9cc | ||
|
|
8a4c9f6eb0 | ||
|
|
87f0aa7f6f | ||
|
|
692f5a43ea | ||
|
|
b8c6325123 | ||
|
|
d1a4f8e55e | ||
|
|
ef5317a2da | ||
|
|
e43244a6e9 | ||
|
|
4e0b8c02d0 |
No files matched your search
@@ -1,10 +1,29 @@
|
|||||||
|
Copyright (c) 2004-2011 VMware, Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
ADDITIONAL LICENSE INFORMATION:
|
||||||
|
|
||||||
Hyperic SIGAR includes some third-party open source components
|
Hyperic SIGAR includes some third-party open source components
|
||||||
in its distribution. The list below identifies the community or
|
in its distribution. The list below identifies the community or
|
||||||
organization and links to their appropriate license terms.
|
organization and links to their appropriate license terms.
|
||||||
|
|
||||||
The Hyperic team would like to thank all the communities
|
The Hyperic team would like to thank all the communities
|
||||||
of the projects listed below for their contributions.
|
of the projects listed below for their contributions.
|
||||||
---------------------------------------------------------------------
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
Components under the Apache License 2.0:
|
||||||
|
----------------------------------------------------------
|
||||||
|
|
||||||
The following components are included without modification:
|
The following components are included without modification:
|
||||||
|
|
||||||
@@ -16,20 +35,83 @@ The following components are included with modification:
|
|||||||
|
|
||||||
- cpptasks -
|
- cpptasks -
|
||||||
Information: http://ant-contrib.sourceforge.net/
|
Information: http://ant-contrib.sourceforge.net/
|
||||||
License: http://ant-contrib.sourceforge.net/LICENSE.txt
|
License: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
- (portions of) APR -
|
- (portions of) APR -
|
||||||
Information: http://apr.apache.org/
|
Information: http://apr.apache.org/
|
||||||
License: http://www.apache.org/licenses/LICENSE-2.0
|
License: http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
----------------------------------------------------------
|
||||||
|
Components under BSD/MIT Style Licenses:
|
||||||
|
----------------------------------------------------------
|
||||||
|
|
||||||
|
The following components are included with modification:
|
||||||
|
|
||||||
- solaris get_mib2 -
|
- solaris get_mib2 -
|
||||||
Information: ftp://vic.cc.purdue.edu/pub/tools/unix/solaris/get_mib2/
|
Information: ftp://vic.cc.purdue.edu/pub/tools/unix/solaris/get_mib2/
|
||||||
License: within src/os/solaris/get_mib2.[ch]
|
License: within src/os/solaris/get_mib2.[ch]
|
||||||
|
|
||||||
|
Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana
|
||||||
|
47907. All rights reserved.
|
||||||
|
|
||||||
|
Written by Victor A. Abell <abe@cc.purdue.edu>
|
||||||
|
|
||||||
|
This software is not subject to any license of the American Telephone
|
||||||
|
and Telegraph Company or the Regents of the University of California.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose on
|
||||||
|
any computer system, and to alter it and redistribute it freely, subject
|
||||||
|
to the following restrictions:
|
||||||
|
|
||||||
|
1. Neither Victor A Abell nor Purdue University are responsible for
|
||||||
|
any consequences of the use of this software.
|
||||||
|
|
||||||
|
2. The origin of this software must not be misrepresented, either by
|
||||||
|
explicit claim or by omission. Credit to Victor A. Abell and Purdue
|
||||||
|
University must appear in documentation and sources.
|
||||||
|
|
||||||
|
3. Altered versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
|
||||||
|
4. This notice may not be removed or altered.
|
||||||
|
|
||||||
- getline by Chris Thewalt -
|
- getline by Chris Thewalt -
|
||||||
Information: http://tinyurl.com/r438r
|
Information: http://tinyurl.com/r438r
|
||||||
License: within src/sigar_getline.c
|
License: within src/sigar_getline.c
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1992 by Chris Thewalt (thewalt@ce.berkeley.edu)
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software
|
||||||
|
for any purpose and without fee is hereby granted, provided
|
||||||
|
that the above copyright notices appear in all copies and that both the
|
||||||
|
copyright notice and this permission notice appear in supporting
|
||||||
|
documentation. This software is provided "as is" without express or
|
||||||
|
implied warranty.
|
||||||
|
|
||||||
- PrintfFormat.java -
|
- PrintfFormat.java -
|
||||||
Information: http://java.sun.com/developer/technicalArticles/Programming/sprintf/PrintfFormat.java
|
Information: http://java.sun.com/developer/technicalArticles/Programming/sprintf/PrintfFormat.java
|
||||||
License: within bindings/java/src/org/hyperic/sigar/util/PrintfFormat.java
|
License: within bindings/java/src/org/hyperic/sigar/util/PrintfFormat.java
|
||||||
|
|
||||||
|
(c) 2000 Sun Microsystems, Inc.
|
||||||
|
ALL RIGHTS RESERVED
|
||||||
|
|
||||||
|
License Grant-
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this Software and its
|
||||||
|
documentation for NON-COMMERCIAL or COMMERCIAL purposes and without fee is
|
||||||
|
hereby granted.
|
||||||
|
|
||||||
|
This Software is provided "AS IS". All express warranties, including any
|
||||||
|
implied warranty of merchantability, satisfactory quality, fitness for a
|
||||||
|
particular purpose, or non-infringement, are disclaimed, except to the extent
|
||||||
|
that such disclaimers are held to be legally invalid.
|
||||||
|
|
||||||
|
You acknowledge that Software is not designed, licensed or intended for use in
|
||||||
|
the design, construction, operation or maintenance of any nuclear facility
|
||||||
|
("High Risk Activities"). Sun disclaims any express or implied warranty of
|
||||||
|
fitness for such uses.
|
||||||
|
|
||||||
|
Please refer to the file http://www.sun.com/policies/trademarks/ for further
|
||||||
|
important trademark information and to
|
||||||
|
http://java.sun.com/nav/business/index.html for further important licensing
|
||||||
|
information for the Java Technology.
|
||||||
@@ -94,6 +94,7 @@ my %has_name_arg = map { $_, 1 } qw(FileSystemUsage DiskUsage
|
|||||||
FileAttrs DirStat DirUsage
|
FileAttrs DirStat DirUsage
|
||||||
NetInterfaceConfig NetInterfaceStat);
|
NetInterfaceConfig NetInterfaceStat);
|
||||||
|
|
||||||
|
|
||||||
my %proc_no_arg = map { $_, 1 } qw(stat);
|
my %proc_no_arg = map { $_, 1 } qw(stat);
|
||||||
|
|
||||||
my %get_not_impl = map { $_, 1 } qw(net_address net_route net_connection net_stat cpu_perc
|
my %get_not_impl = map { $_, 1 } qw(net_address net_route net_connection net_stat cpu_perc
|
||||||
@@ -568,6 +569,7 @@ use vars qw(%classes %cmds);
|
|||||||
plat => '*'
|
plat => '*'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
ProcMem => [
|
ProcMem => [
|
||||||
{
|
{
|
||||||
name => 'size', type => 'Long',
|
name => 'size', type => 'Long',
|
||||||
@@ -668,6 +670,59 @@ use vars qw(%classes %cmds);
|
|||||||
plat => '*'
|
plat => '*'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
ProcDiskIO => [
|
||||||
|
{
|
||||||
|
name => 'bytes_read', type => 'Long',
|
||||||
|
desc => 'Bytes Read',
|
||||||
|
plat => 'LW'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'bytes_written', type => 'Long',
|
||||||
|
desc => 'Bytes Written',
|
||||||
|
plat => 'LW'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'bytes_total', type => 'Long',
|
||||||
|
desc => 'Bytes Total',
|
||||||
|
plat => 'LWAHS'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
ProcCumulativeDiskIO => [
|
||||||
|
{
|
||||||
|
name => 'bytes_read', type => 'Long',
|
||||||
|
desc => 'Bytes Read from Start',
|
||||||
|
plat => 'LW'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'bytes_written', type => 'Long',
|
||||||
|
desc => 'Bytes Written from Start',
|
||||||
|
plat => 'LW'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name => 'bytes_total', type => 'Long',
|
||||||
|
desc => 'Bytes Total from Start',
|
||||||
|
plat => 'LWAHS'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
DumpPidCache => [
|
||||||
|
{
|
||||||
|
name => 'dummy', type => 'Long',
|
||||||
|
desc => 'Dummy',
|
||||||
|
plat => 'LWAHS'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
|
||||||
|
DumpPidCache => [
|
||||||
|
{
|
||||||
|
name => 'dummy', type => 'Long',
|
||||||
|
desc => 'Dummy',
|
||||||
|
plat => 'LWAHS'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
ProcState => [
|
ProcState => [
|
||||||
{
|
{
|
||||||
name => 'state', type => 'Char',
|
name => 'state', type => 'Char',
|
||||||
|
|||||||
@@ -505,6 +505,7 @@
|
|||||||
<include name="bindings/java/**/*.java"/>
|
<include name="bindings/java/**/*.java"/>
|
||||||
<include name="bindings/java/**/*.java.in"/>
|
<include name="bindings/java/**/*.java.in"/>
|
||||||
<include name="bindings/java/**/*.c"/>
|
<include name="bindings/java/**/*.c"/>
|
||||||
|
<include name="bindings/java/**/*.cpp"/>
|
||||||
<include name="bindings/java/**/*.h"/>
|
<include name="bindings/java/**/*.h"/>
|
||||||
<include name="bindings/java/**/*.pl"/>
|
<include name="bindings/java/**/*.pl"/>
|
||||||
<include name="bindings/java/**/build.xml"/>
|
<include name="bindings/java/**/build.xml"/>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.hyperic.jni;
|
package org.hyperic.jni;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
@@ -315,7 +316,16 @@ public class ArchLoader {
|
|||||||
if ((file != null) &&
|
if ((file != null) &&
|
||||||
((file = file.getParentFile()) != null))
|
((file = file.getParentFile()) != null))
|
||||||
{
|
{
|
||||||
String dir = URLDecoder.decode(file.toString());
|
String dir;
|
||||||
|
try {
|
||||||
|
// Passing UTF-8 according to the recommendation in the URLDecoder.decode JavaDoc.
|
||||||
|
dir = URLDecoder.decode(file.toString(), "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
String msg = "Unsupported encoding in file name: " + file.toString();
|
||||||
|
ArchLoaderException archLoaderException = new ArchLoaderException(msg);
|
||||||
|
archLoaderException.initCause(e);
|
||||||
|
throw archLoaderException;
|
||||||
|
}
|
||||||
if (findNativeLibrary(dir, libName)) {
|
if (findNativeLibrary(dir, libName)) {
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -665,6 +665,17 @@ JNIEXPORT jlongArray SIGAR_JNIx(getProcList)
|
|||||||
|
|
||||||
return procarray;
|
return procarray;
|
||||||
}
|
}
|
||||||
|
jstring getProcArgStr(char *arg, JNIEnv *env) {
|
||||||
|
jstring s;
|
||||||
|
#ifdef WIN32
|
||||||
|
WCHAR warg[3000];
|
||||||
|
SIGAR_A2W(arg, warg, sizeof(warg));
|
||||||
|
s = JENV->NewString(env, (const jchar *)warg, wcslen(warg));
|
||||||
|
#else
|
||||||
|
s = JENV->NewStringUTF(env, arg);
|
||||||
|
#endif
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jobjectArray SIGAR_JNIx(getProcArgs)
|
JNIEXPORT jobjectArray SIGAR_JNIx(getProcArgs)
|
||||||
(JNIEnv *env, jobject sigar_obj, jlong pid)
|
(JNIEnv *env, jobject sigar_obj, jlong pid)
|
||||||
@@ -684,8 +695,9 @@ JNIEXPORT jobjectArray SIGAR_JNIx(getProcArgs)
|
|||||||
argsarray = JENV->NewObjectArray(env, procargs.number, stringclass, 0);
|
argsarray = JENV->NewObjectArray(env, procargs.number, stringclass, 0);
|
||||||
SIGAR_CHEX;
|
SIGAR_CHEX;
|
||||||
|
|
||||||
for (i=0; i<procargs.number; i++) {
|
for (i=0; i<procargs.number; i++) {
|
||||||
jstring s = JENV->NewStringUTF(env, procargs.data[i]);
|
|
||||||
|
jstring s = getProcArgStr(procargs.data[i], env);
|
||||||
JENV->SetObjectArrayElement(env, argsarray, i, s);
|
JENV->SetObjectArrayElement(env, argsarray, i, s);
|
||||||
SIGAR_CHEX;
|
SIGAR_CHEX;
|
||||||
}
|
}
|
||||||
@@ -1296,18 +1308,28 @@ JNIEXPORT jboolean SIGAR_JNI(ptql_SigarProcessQuery_match)
|
|||||||
JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_create)
|
JNIEXPORT void SIGAR_JNI(ptql_SigarProcessQuery_create)
|
||||||
(JNIEnv *env, jobject obj, jstring jptql)
|
(JNIEnv *env, jobject obj, jstring jptql)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
jboolean is_copy;
|
jboolean is_copy;
|
||||||
const char *ptql;
|
|
||||||
sigar_ptql_query_t *query;
|
sigar_ptql_query_t *query;
|
||||||
sigar_ptql_error_t error;
|
sigar_ptql_error_t error;
|
||||||
|
#ifdef WIN32
|
||||||
ptql = JENV->GetStringUTFChars(env, jptql, &is_copy);
|
LPCTSTR ptql;
|
||||||
|
char ptql_ch[3000];
|
||||||
|
ptql = (LPCTSTR)JENV->GetStringChars(env, jptql, &is_copy);
|
||||||
|
|
||||||
|
SIGAR_W2A((LPCWSTR)ptql, ptql_ch, sizeof(ptql_ch));
|
||||||
|
status = sigar_ptql_query_create(&query, ptql_ch, &error);
|
||||||
|
if (is_copy) {
|
||||||
|
JENV->ReleaseStringChars(env, jptql, (const jchar *)ptql);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
const char *ptql;
|
||||||
|
ptql = JENV->GetStringUTFChars(env, jptql, &is_copy);
|
||||||
status = sigar_ptql_query_create(&query, (char *)ptql, &error);
|
status = sigar_ptql_query_create(&query, (char *)ptql, &error);
|
||||||
if (is_copy) {
|
if (is_copy) {
|
||||||
JENV->ReleaseStringUTFChars(env, jptql, ptql);
|
JENV->ReleaseStringUTFChars(env, jptql, ptql);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (status != SIGAR_OK) {
|
if (status != SIGAR_OK) {
|
||||||
sigar_throw_ptql_malformed(env, error.message);
|
sigar_throw_ptql_malformed(env, error.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,6 +172,34 @@ JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhRemoveCounter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhCollectQueryDataOverSecond)
|
||||||
|
(JNIEnv *env, jclass cur, jlong query)
|
||||||
|
{
|
||||||
|
HQUERY h_query = (HQUERY)query;
|
||||||
|
PdhCollectQueryData(h_query);
|
||||||
|
Sleep(1000);
|
||||||
|
PdhCollectQueryData(h_query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetFormattedValue)
|
||||||
|
(JNIEnv *env, jclass cur, jlong counter)
|
||||||
|
{
|
||||||
|
HCOUNTER h_counter = (HCOUNTER)counter;
|
||||||
|
PDH_STATUS status;
|
||||||
|
PDH_FMT_COUNTERVALUE fmt_value;
|
||||||
|
status = PdhGetFormattedCounterValue(h_counter,
|
||||||
|
PDH_FMT_DOUBLE,
|
||||||
|
(LPDWORD)NULL,
|
||||||
|
&fmt_value);
|
||||||
|
if (status != ERROR_SUCCESS) {
|
||||||
|
win32_throw_exception(env, get_error_message(status));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt_value.doubleValue;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue)
|
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue)
|
||||||
(JNIEnv *env, jclass cur, jlong query, jlong counter, jboolean fmt)
|
(JNIEnv *env, jclass cur, jlong query, jlong counter, jboolean fmt)
|
||||||
{
|
{
|
||||||
@@ -353,6 +381,7 @@ JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetInstances)
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetKeys)
|
JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetKeys)
|
||||||
(JNIEnv *env, jclass cur, jstring cp)
|
(JNIEnv *env, jclass cur, jstring cp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -292,74 +292,58 @@ public class FileInfo extends FileAttrs implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String diff(FileInfo info) {
|
public String diff(FileInfo info) {
|
||||||
ArrayList changes = new ArrayList();
|
ArrayList changes = new ArrayList();
|
||||||
|
|
||||||
if (this.getMtime() != info.getMtime()) {
|
if (this.getMtime() != info.getMtime()) {
|
||||||
changes.add(new Diff("Mtime",
|
changes.add(new Diff("Mtime", formatDate(info.getMtime()),
|
||||||
formatDate(info.getMtime()),
|
formatDate(this.getMtime())));
|
||||||
formatDate(this.getMtime())));
|
} else if (this.getCtime() != info.getCtime()) {
|
||||||
|
changes.add(new Diff("Ctime", formatDate(info.getCtime()),
|
||||||
|
formatDate(this.getCtime())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getPermissions() != info.getPermissions()) {
|
||||||
|
changes.add(new Diff("Perms", info.getPermissionsString(), this
|
||||||
|
.getPermissionsString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getType() != info.getType()) {
|
||||||
|
changes.add(new Diff("Type", info.getTypeString(), this
|
||||||
|
.getTypeString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getUid() != info.getUid()) {
|
||||||
|
changes.add(new Diff("Uid", info.getUid(), this.getUid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getGid() != info.getGid()) {
|
||||||
|
changes.add(new Diff("Gid", info.getGid(), this.getGid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getSize() != info.getSize()) {
|
||||||
|
changes.add(new Diff("Size", info.getSize(), this.getSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!OperatingSystem.IS_WIN32) {
|
||||||
|
if (this.getInode() != info.getInode()) {
|
||||||
|
changes.add(new Diff("Inode", info.getInode(), this.getInode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getDevice() != info.getDevice()) {
|
||||||
|
changes.add(new Diff("Device", info.getDevice(), this
|
||||||
|
.getDevice()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getNlink() != info.getNlink()) {
|
||||||
|
changes.add(new Diff("Nlink", info.getNlink(), this.getNlink()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (this.getCtime() != info.getCtime()) {
|
|
||||||
changes.add(new Diff("Ctime",
|
/* if changes were not detected then return empty String */
|
||||||
formatDate(info.getCtime()),
|
if (changes.isEmpty()){
|
||||||
formatDate(this.getCtime())));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//no point in checking the rest if all times are the same.
|
|
||||||
//or should we include atime in the diff?
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.getPermissions() != info.getPermissions()) {
|
|
||||||
changes.add(new Diff("Perms",
|
|
||||||
info.getPermissionsString(),
|
|
||||||
this.getPermissionsString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getType() != info.getType()) {
|
|
||||||
changes.add(new Diff("Type",
|
|
||||||
info.getTypeString(),
|
|
||||||
this.getTypeString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getUid() != info.getUid()) {
|
|
||||||
changes.add(new Diff("Uid",
|
|
||||||
info.getUid(),
|
|
||||||
this.getUid()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getGid() != info.getGid()) {
|
|
||||||
changes.add(new Diff("Gid",
|
|
||||||
info.getGid(),
|
|
||||||
this.getGid()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getSize() != info.getSize()) {
|
|
||||||
changes.add(new Diff("Size",
|
|
||||||
info.getSize(),
|
|
||||||
this.getSize()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!OperatingSystem.IS_WIN32) {
|
|
||||||
if (this.getInode() != info.getInode()) {
|
|
||||||
changes.add(new Diff("Inode",
|
|
||||||
info.getInode(),
|
|
||||||
this.getInode()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getDevice() != info.getDevice()) {
|
|
||||||
changes.add(new Diff("Device",
|
|
||||||
info.getDevice(),
|
|
||||||
this.getDevice()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getNlink() != info.getNlink()) {
|
|
||||||
changes.add(new Diff("Nlink",
|
|
||||||
info.getNlink(),
|
|
||||||
this.getNlink()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuffer sb = format(changes);
|
StringBuffer sb = format(changes);
|
||||||
if (this.dirStatEnabled) {
|
if (this.dirStatEnabled) {
|
||||||
sb.append(diff(info.stat));
|
sb.append(diff(info.stat));
|
||||||
@@ -389,7 +373,9 @@ public class FileInfo extends FileAttrs implements java.io.Serializable {
|
|||||||
|
|
||||||
stat();
|
stat();
|
||||||
|
|
||||||
return this.mtime != oldInfo.mtime;
|
boolean isModified = isModified(this.oldInfo);
|
||||||
|
|
||||||
|
return isModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean changed()
|
public boolean changed()
|
||||||
@@ -455,4 +441,49 @@ public class FileInfo extends FileAttrs implements java.io.Serializable {
|
|||||||
|
|
||||||
return fetchInfo(sigar, name, false);
|
return fetchInfo(sigar, name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isModified(FileInfo info){
|
||||||
|
/* Check modified time */
|
||||||
|
if (this.getMtime() != info.getMtime()) {
|
||||||
|
return true;
|
||||||
|
} else if (this.getCtime() != info.getCtime()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getPermissions() != info.getPermissions()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getType() != info.getType()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getUid() != info.getUid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getGid() != info.getGid()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getSize() != info.getSize()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!OperatingSystem.IS_WIN32) {
|
||||||
|
if (this.getInode() != info.getInode()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getDevice() != info.getDevice()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getNlink() != info.getNlink()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,8 @@ import java.util.HashSet;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
public abstract class FileWatcher {
|
public abstract class FileWatcher {
|
||||||
|
|
||||||
private Sigar sigar;
|
private Sigar sigar;
|
||||||
@@ -31,6 +33,9 @@ public abstract class FileWatcher {
|
|||||||
private Set files =
|
private Set files =
|
||||||
Collections.synchronizedSet(new HashSet());
|
Collections.synchronizedSet(new HashSet());
|
||||||
|
|
||||||
|
private static final Logger log =
|
||||||
|
SigarLog.getLogger(FileWatcher.class.getName());
|
||||||
|
|
||||||
public abstract void onChange(FileInfo info);
|
public abstract void onChange(FileInfo info);
|
||||||
|
|
||||||
public void onNotFound(FileInfo info) {
|
public void onNotFound(FileInfo info) {
|
||||||
@@ -66,14 +71,22 @@ public abstract class FileWatcher {
|
|||||||
public void add(File[] files)
|
public void add(File[] files)
|
||||||
throws SigarException {
|
throws SigarException {
|
||||||
for (int i=0; i<files.length; i++) {
|
for (int i=0; i<files.length; i++) {
|
||||||
add(files[i]);
|
try {
|
||||||
|
add(files[i]);
|
||||||
|
} catch (SigarFileNotFoundException e) {
|
||||||
|
log.error("Cannot add file: " + files[i].getAbsolutePath(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String[] files)
|
public void add(String[] files)
|
||||||
throws SigarException {
|
throws SigarException {
|
||||||
for (int i=0; i<files.length; i++) {
|
for (int i=0; i<files.length; i++) {
|
||||||
add(files[i]);
|
try {
|
||||||
|
add(files[i]);
|
||||||
|
} catch (SigarFileNotFoundException e) {
|
||||||
|
log.error("Cannot add file: " + files[i], e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ProcUtil {
|
|||||||
|
|
||||||
for (int i=0; i<len; i++) {
|
for (int i=0; i<len; i++) {
|
||||||
char c = name.charAt(i);
|
char c = name.charAt(i);
|
||||||
if (!((c == '.') || Character.isLetter(c))) {
|
if (!((c == '.') || Character.isJavaIdentifierPart(c))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public class Sigar implements SigarProxy {
|
|||||||
private static String loadError = null;
|
private static String loadError = null;
|
||||||
|
|
||||||
public static final long FIELD_NOTIMPL = -1;
|
public static final long FIELD_NOTIMPL = -1;
|
||||||
|
public static final int PID_PROC_CPU_CACHE = 1;
|
||||||
|
public static final int PID_PROC_IO_CACHE = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Sigar java version.
|
* The Sigar java version.
|
||||||
@@ -373,7 +375,7 @@ public class Sigar implements SigarProxy {
|
|||||||
CpuPerc[] perc =
|
CpuPerc[] perc =
|
||||||
new CpuPerc[curLen < oldLen ? curLen : oldLen];
|
new CpuPerc[curLen < oldLen ? curLen : oldLen];
|
||||||
|
|
||||||
for (int i=0; i<curLen; i++) {
|
for (int i=0; i<perc.length; i++) {
|
||||||
perc[i] =
|
perc[i] =
|
||||||
CpuPerc.fetch(this, oldCpuList[i],
|
CpuPerc.fetch(this, oldCpuList[i],
|
||||||
this.lastCpuList[i]);
|
this.lastCpuList[i]);
|
||||||
@@ -435,7 +437,7 @@ public class Sigar implements SigarProxy {
|
|||||||
return this.processFinder.findSingleProcess(pid);
|
return this.processFinder.findSingleProcess(pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get process memory info.
|
* Get process memory info.
|
||||||
* @param pid The process id.
|
* @param pid The process id.
|
||||||
@@ -633,6 +635,57 @@ public class Sigar implements SigarProxy {
|
|||||||
Integer.parseInt(port));
|
Integer.parseInt(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get process disk IO info.
|
||||||
|
* @param pid THe process id.
|
||||||
|
* @exception SigarException on failure.
|
||||||
|
*/
|
||||||
|
public ProcDiskIO getProcDiskIO(long pid) throws SigarException {
|
||||||
|
try {
|
||||||
|
return ProcDiskIO.fetch(this, pid);
|
||||||
|
} catch (UnsatisfiedLinkError linkErrorException) {
|
||||||
|
// We want to handle exceptions gracefully even if the linked
|
||||||
|
// shared library is older and isn't compiled with the ProcDiskIO APIs.
|
||||||
|
// The downside of this is that we throw SigarNotImplemented exception
|
||||||
|
// also when the shared library can't be loaded.
|
||||||
|
SigarException sigarException = new SigarNotImplementedException();
|
||||||
|
sigarException.initCause(linkErrorException);
|
||||||
|
throw sigarException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProcDiskIO getProcDiskIO(String pid) throws SigarException {
|
||||||
|
return getProcDiskIO(convertPid(pid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get process cumulative disk IO info.
|
||||||
|
* @param pid THe process id.
|
||||||
|
* @exception SigarException on failure.
|
||||||
|
*/
|
||||||
|
public ProcCumulativeDiskIO getProcCumulativeDiskIO(long pid) throws SigarException {
|
||||||
|
try {
|
||||||
|
return ProcCumulativeDiskIO.fetch(this, pid);
|
||||||
|
} catch (UnsatisfiedLinkError linkErrorException) {
|
||||||
|
// We want to handle exceptions gracefully even if the linked
|
||||||
|
// shared library is older and isn't compiled with the ProcDiskIO APIs.
|
||||||
|
// The downside of this is that we throw SigarNotImplemented exception
|
||||||
|
// also when the shared library can't be loaded.
|
||||||
|
SigarException sigarException = new SigarNotImplementedException();
|
||||||
|
sigarException.initCause(linkErrorException);
|
||||||
|
throw sigarException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProcCumulativeDiskIO getProcCumulativeDiskIO(String pid) throws SigarException {
|
||||||
|
return getProcCumulativeDiskIO(convertPid(pid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DumpPidCache dumpPidCache() throws SigarException {
|
||||||
|
return DumpPidCache.fetch(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cumulative cpu time for the calling thread.
|
* Get the cumulative cpu time for the calling thread.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class SigarLog {
|
|||||||
private static final int LOG_INFO = 3;
|
private static final int LOG_INFO = 3;
|
||||||
private static final int LOG_DEBUG = 4;
|
private static final int LOG_DEBUG = 4;
|
||||||
|
|
||||||
|
private static final boolean enableLogFallbackConf = ! Boolean.getBoolean("sigar.noLog4jDefaultConfig");
|
||||||
|
|
||||||
private static native void setLogger(Sigar sigar, Logger log);
|
private static native void setLogger(Sigar sigar, Logger log);
|
||||||
|
|
||||||
public static native void setLevel(Sigar sigar, int level);
|
public static native void setLevel(Sigar sigar, int level);
|
||||||
@@ -46,7 +48,7 @@ public class SigarLog {
|
|||||||
|
|
||||||
public static Logger getLogger(String name) {
|
public static Logger getLogger(String name) {
|
||||||
Logger log = Logger.getLogger(name);
|
Logger log = Logger.getLogger(name);
|
||||||
if (!isLogConfigured()) {
|
if (enableLogFallbackConf && !isLogConfigured()) {
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
}
|
}
|
||||||
return log;
|
return log;
|
||||||
|
|||||||
@@ -106,6 +106,16 @@ public interface SigarProxy {
|
|||||||
|
|
||||||
public long getProcPort(String protocol, String port) throws SigarException;
|
public long getProcPort(String protocol, String port) throws SigarException;
|
||||||
|
|
||||||
|
public ProcDiskIO getProcDiskIO(long pid) throws SigarException;
|
||||||
|
|
||||||
|
public ProcDiskIO getProcDiskIO(String pid) throws SigarException;
|
||||||
|
|
||||||
|
public ProcCumulativeDiskIO getProcCumulativeDiskIO(long pid) throws SigarException;
|
||||||
|
|
||||||
|
public ProcCumulativeDiskIO getProcCumulativeDiskIO(String pid) throws SigarException;
|
||||||
|
|
||||||
|
public DumpPidCache dumpPidCache() throws SigarException;
|
||||||
|
|
||||||
public FileSystem[] getFileSystemList() throws SigarException;
|
public FileSystem[] getFileSystemList() throws SigarException;
|
||||||
|
|
||||||
public FileSystemMap getFileSystemMap() throws SigarException;
|
public FileSystemMap getFileSystemMap() throws SigarException;
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2007 Hyperic, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.hyperic.sigar.cmd;
|
||||||
|
|
||||||
|
import org.hyperic.sigar.SigarException;
|
||||||
|
import org.hyperic.sigar.SigarPermissionDeniedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display all pid cache information.
|
||||||
|
*/
|
||||||
|
public class PidCacheInfo extends SigarCommandBase {
|
||||||
|
|
||||||
|
|
||||||
|
public PidCacheInfo(Shell shell) {
|
||||||
|
super(shell);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PidCacheInfo() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean validateArgs(String[] args) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsageShort() {
|
||||||
|
return "Display cache info for CPU cache and for IO cache";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPidCompleter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void output(String[] args) throws SigarException {
|
||||||
|
sigar.dumpPidCache();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,6 +100,14 @@ public class ProcInfo extends SigarCommandBase {
|
|||||||
try {
|
try {
|
||||||
println("credname=" + sigar.getProcCredName(pid));
|
println("credname=" + sigar.getProcCredName(pid));
|
||||||
} catch (SigarException e) {}
|
} catch (SigarException e) {}
|
||||||
|
try {
|
||||||
|
println("diskio=" + sigar.getProcDiskIO(pid));
|
||||||
|
} catch (SigarException e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
println("cumulative diskio=" + sigar.getProcCumulativeDiskIO(pid));
|
||||||
|
} catch (SigarException e) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ public class Shell extends ShellBase {
|
|||||||
registerCommandHandler("time", new Time(this));
|
registerCommandHandler("time", new Time(this));
|
||||||
registerCommandHandler("ulimit", new Ulimit(this));
|
registerCommandHandler("ulimit", new Ulimit(this));
|
||||||
registerCommandHandler("who", new Who(this));
|
registerCommandHandler("who", new Who(this));
|
||||||
|
registerCommandHandler("pid_cache_info", new PidCacheInfo(this));
|
||||||
|
|
||||||
if (SigarLoader.IS_WIN32) {
|
if (SigarLoader.IS_WIN32) {
|
||||||
registerCommandHandler("service", new Win32Service(this));
|
registerCommandHandler("service", new Win32Service(this));
|
||||||
registerCommandHandler("fversion", new FileVersionInfo(this));
|
registerCommandHandler("fversion", new FileVersionInfo(this));
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ package org.hyperic.sigar.jmx;
|
|||||||
import org.hyperic.sigar.ProcCpu;
|
import org.hyperic.sigar.ProcCpu;
|
||||||
import org.hyperic.sigar.ProcFd;
|
import org.hyperic.sigar.ProcFd;
|
||||||
import org.hyperic.sigar.ProcMem;
|
import org.hyperic.sigar.ProcMem;
|
||||||
|
import org.hyperic.sigar.ProcUtil;
|
||||||
|
import org.hyperic.sigar.ProcDiskIO;
|
||||||
import org.hyperic.sigar.Sigar;
|
import org.hyperic.sigar.Sigar;
|
||||||
import org.hyperic.sigar.SigarException;
|
import org.hyperic.sigar.SigarException;
|
||||||
import org.hyperic.sigar.SigarProxy;
|
import org.hyperic.sigar.SigarProxy;
|
||||||
@@ -31,20 +33,24 @@ import org.hyperic.sigar.SigarProxyCache;
|
|||||||
|
|
||||||
public class SigarProcess implements SigarProcessMBean {
|
public class SigarProcess implements SigarProcessMBean {
|
||||||
|
|
||||||
|
private static final Long NOTIMPL = new Long(Sigar.FIELD_NOTIMPL);
|
||||||
private Sigar sigarImpl;
|
private Sigar sigarImpl;
|
||||||
private SigarProxy sigar;
|
private SigarProxy sigar;
|
||||||
|
private long pid = -1;
|
||||||
|
|
||||||
public SigarProcess() {
|
public SigarProcess() {
|
||||||
this(new Sigar());
|
this.sigarImpl = new Sigar();
|
||||||
}
|
|
||||||
|
|
||||||
public SigarProcess(Sigar sigar) {
|
|
||||||
this.sigarImpl = sigar;
|
|
||||||
this.sigar = SigarProxyCache.newInstance(sigarImpl);
|
this.sigar = SigarProxyCache.newInstance(sigarImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SigarProcess(SigarProxy sigar) {
|
||||||
|
this.sigar = sigar;
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
this.sigarImpl.close();
|
if (this.sigarImpl != null) {
|
||||||
|
this.sigarImpl.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RuntimeException unexpectedError(String type,
|
private RuntimeException unexpectedError(String type,
|
||||||
@@ -57,8 +63,7 @@ public class SigarProcess implements SigarProcessMBean {
|
|||||||
|
|
||||||
private synchronized ProcMem getMem() {
|
private synchronized ProcMem getMem() {
|
||||||
try {
|
try {
|
||||||
long pid = this.sigar.getPid();
|
return this.sigar.getProcMem(getPid());
|
||||||
return this.sigar.getProcMem(pid);
|
|
||||||
} catch (SigarException e) {
|
} catch (SigarException e) {
|
||||||
throw unexpectedError("Mem", e);
|
throw unexpectedError("Mem", e);
|
||||||
}
|
}
|
||||||
@@ -66,22 +71,40 @@ public class SigarProcess implements SigarProcessMBean {
|
|||||||
|
|
||||||
private synchronized ProcCpu getCpu() {
|
private synchronized ProcCpu getCpu() {
|
||||||
try {
|
try {
|
||||||
long pid = this.sigar.getPid();
|
return this.sigar.getProcCpu(getPid());
|
||||||
return this.sigar.getProcCpu(pid);
|
|
||||||
} catch (SigarException e) {
|
} catch (SigarException e) {
|
||||||
throw unexpectedError("Cpu", e);
|
throw unexpectedError("Cpu", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized ProcFd getFd() {
|
|
||||||
try {
|
private synchronized ProcDiskIO getDiskIO() {
|
||||||
long pid = this.sigar.getPid();
|
try {
|
||||||
return this.sigar.getProcFd(pid);
|
return this.sigar.getProcDiskIO(getPid());
|
||||||
} catch (SigarException e) {
|
} catch (SigarException e) {
|
||||||
throw unexpectedError("Fd", e);
|
throw unexpectedError("DiskIO", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private synchronized ProcFd getFd() throws SigarException {
|
||||||
|
return this.sigar.getProcFd(getPid());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public long getPid() {
|
||||||
|
if (this.pid < 0) {
|
||||||
|
return this.sigar.getPid();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return this.pid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPid(long pid) {
|
||||||
|
this.pid = pid;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getMemSize() {
|
public Long getMemSize() {
|
||||||
return new Long(getMem().getSize());
|
return new Long(getMem().getSize());
|
||||||
}
|
}
|
||||||
@@ -119,7 +142,11 @@ public class SigarProcess implements SigarProcessMBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Long getOpenFd() {
|
public Long getOpenFd() {
|
||||||
return new Long(getFd().getTotal());
|
try {
|
||||||
|
return new Long(getFd().getTotal());
|
||||||
|
} catch (SigarException e) {
|
||||||
|
return NOTIMPL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
@@ -132,4 +159,9 @@ public class SigarProcess implements SigarProcessMBean {
|
|||||||
System.out.println("TimeSys=" + proc.getTimeSys());
|
System.out.println("TimeSys=" + proc.getTimeSys());
|
||||||
System.out.println("OpenFd=" + proc.getOpenFd());
|
System.out.println("OpenFd=" + proc.getOpenFd());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Double getBytesReadWriteTotal() {
|
||||||
|
return new Double(getDiskIO().getBytesTotal());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -44,4 +44,6 @@ public interface SigarProcessMBean {
|
|||||||
public Double getCpuUsage();
|
public Double getCpuUsage();
|
||||||
|
|
||||||
public Long getOpenFd();
|
public Long getOpenFd();
|
||||||
|
|
||||||
|
public Double getBytesReadWriteTotal();
|
||||||
}
|
}
|
||||||
@@ -133,11 +133,11 @@ public class TestFileInfo extends SigarTestCase {
|
|||||||
tmp.deleteOnExit();
|
tmp.deleteOnExit();
|
||||||
traceln("TMP=" + file);
|
traceln("TMP=" + file);
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
//stat() mtime is in seconds, this happens to quick to detect change.
|
//stat() mtime is in seconds, this happens to quick to detect change.
|
||||||
Thread.sleep(1000 * 1);
|
//Thread.sleep(1000 * 1);
|
||||||
} catch (InterruptedException e) {
|
// } catch (InterruptedException e) {
|
||||||
}
|
// }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileInfo info = sigar.getFileInfo(file);
|
FileInfo info = sigar.getFileInfo(file);
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.hyperic.sigar.test;
|
||||||
|
|
||||||
|
import org.hyperic.sigar.ProcDiskIO;
|
||||||
|
import org.hyperic.sigar.Sigar;
|
||||||
|
import org.hyperic.sigar.SigarException;
|
||||||
|
|
||||||
|
public class TestProcDiskIO extends SigarTestCase {
|
||||||
|
|
||||||
|
public TestProcDiskIO(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void traceDiskIO(Sigar sigar, long pid) throws Exception {
|
||||||
|
ProcDiskIO procDiskIO;
|
||||||
|
|
||||||
|
try {
|
||||||
|
procDiskIO = sigar.getProcDiskIO(pid);
|
||||||
|
} catch (SigarException e) {
|
||||||
|
traceln("pid " + pid + ": " + e.getMessage());
|
||||||
|
// throw e;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
long bytesRead = procDiskIO.getBytesRead();
|
||||||
|
long bytesWritten = procDiskIO.getBytesWritten();
|
||||||
|
long bytesTotal = procDiskIO.getBytesTotal();
|
||||||
|
|
||||||
|
traceln("Pid=" + pid);
|
||||||
|
traceln("Bytes Read=" + Sigar.formatSize(bytesRead));
|
||||||
|
traceln("Bytes Written=" + Sigar.formatSize(bytesWritten));
|
||||||
|
traceln("Bytes Total=" + Sigar.formatSize(bytesTotal));
|
||||||
|
|
||||||
|
if (bytesRead != -1 && bytesWritten != -1 && bytesTotal != -1) {
|
||||||
|
assertTrue("Bytes total should equal bytesRead + bytesWritten",
|
||||||
|
(bytesTotal == bytesRead + bytesWritten));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreate() throws Exception {
|
||||||
|
Sigar sigar = getSigar();
|
||||||
|
|
||||||
|
boolean caughtException = false;
|
||||||
|
try {
|
||||||
|
sigar.getProcDiskIO(getInvalidPid());
|
||||||
|
} catch (SigarException e) {
|
||||||
|
caughtException = true;
|
||||||
|
}
|
||||||
|
assertTrue("Test on invalid PID should have thrown an exception.", caughtException);
|
||||||
|
|
||||||
|
long[] pids = sigar.getProcList();
|
||||||
|
for (int i=0; i<pids.length; i++) {
|
||||||
|
traceDiskIO(sigar, pids[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ package org.hyperic.sigar.test;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.hyperic.sigar.SigarException;
|
import org.hyperic.sigar.SigarException;
|
||||||
|
import org.hyperic.sigar.SigarLoader;
|
||||||
import org.hyperic.sigar.Who;
|
import org.hyperic.sigar.Who;
|
||||||
|
|
||||||
public class TestWho extends SigarTestCase {
|
public class TestWho extends SigarTestCase {
|
||||||
@@ -39,7 +40,9 @@ public class TestWho extends SigarTestCase {
|
|||||||
who[i].getDevice() + "\t" +
|
who[i].getDevice() + "\t" +
|
||||||
new Date(who[i].getTime() * 1000) + "\t" +
|
new Date(who[i].getTime() * 1000) + "\t" +
|
||||||
host);
|
host);
|
||||||
assertLengthTrace("user", who[i].getUser());
|
if (!SigarLoader.IS_WIN32) {
|
||||||
|
assertLengthTrace("user", who[i].getUser());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,8 +157,32 @@ public class EventLogThread implements Runnable {
|
|||||||
// XXX: Using the waitForChange() method would be a
|
// XXX: Using the waitForChange() method would be a
|
||||||
// cleaner way to go, but we cannot interrupt
|
// cleaner way to go, but we cannot interrupt
|
||||||
// a native system call.
|
// a native system call.
|
||||||
|
boolean logChanged = false;
|
||||||
int lastEvent = log.getNewestRecord();
|
int lastEvent = log.getNewestRecord();
|
||||||
|
if (lastEvent < curEvent) {
|
||||||
|
logChanged = true;
|
||||||
|
}
|
||||||
|
else if ((lastEvent == curEvent) && (lastEvent != -1)) {
|
||||||
|
//example: clearing the Security log generates an event
|
||||||
|
//and clear it again before any new events come in
|
||||||
|
try {
|
||||||
|
log.read(lastEvent);
|
||||||
|
} catch (Win32Exception e) {
|
||||||
|
logChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logChanged) {
|
||||||
|
logger.debug(this.logName + " EventLog has changed, re-opening");
|
||||||
|
try { log.close(); } catch (Win32Exception e) {}
|
||||||
|
log.open(this.logName);
|
||||||
|
curEvent = 0; //all events in the log are new to us after being cleared
|
||||||
|
}
|
||||||
|
|
||||||
if (lastEvent > curEvent) {
|
if (lastEvent > curEvent) {
|
||||||
|
if (curEvent == -1) {
|
||||||
|
curEvent = 0; //log was cleared
|
||||||
|
}
|
||||||
handleEvents(log, curEvent, lastEvent);
|
handleEvents(log, curEvent, lastEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ package org.hyperic.sigar.win32;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
@@ -284,6 +286,24 @@ public class Pdh extends Win32 {
|
|||||||
return trans.toString();
|
return trans.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long addPdhCounter(String path, boolean format) throws Win32Exception {
|
||||||
|
long counter;
|
||||||
|
/*
|
||||||
|
* Some metrics are missing the '/sec' suffix. This flow,
|
||||||
|
* first tries to add the counter without the '/sec' and
|
||||||
|
* if fails, try again with it. If the seconds call fails,
|
||||||
|
* throw an exception.This issue must be addressed
|
||||||
|
* at the java level (and not C code), since the counter
|
||||||
|
* names must be translated before.
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
counter = pdhAddCounter(this.query, translate(path));
|
||||||
|
} catch (Win32Exception e) {
|
||||||
|
counter = pdhAddCounter(this.query, translate(path + "/sec"));
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
private double getValue(String path, boolean format)
|
private double getValue(String path, boolean format)
|
||||||
throws Win32Exception {
|
throws Win32Exception {
|
||||||
|
|
||||||
@@ -291,8 +311,8 @@ public class Pdh extends Win32 {
|
|||||||
pdhConnectMachine(this.hostname);
|
pdhConnectMachine(this.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
long counter =
|
long counter = addPdhCounter(path, format);
|
||||||
pdhAddCounter(this.query, translate(path));
|
|
||||||
try {
|
try {
|
||||||
return pdhGetValue(this.query, counter, format);
|
return pdhGetValue(this.query, counter, format);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -353,6 +373,60 @@ public class Pdh extends Win32 {
|
|||||||
return pdhGetObjects();
|
return pdhGetObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
sigar is compatible with java 1.4 (no generics there)
|
||||||
|
**/
|
||||||
|
public Map getFormattedValues(Collection paths) throws Win32Exception {
|
||||||
|
if (this.hostname != null) {
|
||||||
|
pdhConnectMachine(this.hostname);
|
||||||
|
}
|
||||||
|
Map res = new HashMap();
|
||||||
|
|
||||||
|
Map counters = new HashMap();
|
||||||
|
/*
|
||||||
|
* no for each loop either
|
||||||
|
*/
|
||||||
|
Iterator pathsIt = paths.iterator();
|
||||||
|
while (pathsIt.hasNext()) {
|
||||||
|
String path = (String)pathsIt.next();
|
||||||
|
try {
|
||||||
|
counters.put(path, new Long(pdhAddCounter(this.query, translate(path))));
|
||||||
|
} catch ( Win32Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counters.size() > 0) {
|
||||||
|
try {
|
||||||
|
pdhCollectQueryDataOverSecond(this.query);
|
||||||
|
pathsIt = paths.iterator();
|
||||||
|
while (pathsIt.hasNext()) {
|
||||||
|
try {
|
||||||
|
String path = (String)pathsIt.next();
|
||||||
|
Long c = (Long)counters.get(path);
|
||||||
|
if (c != null) {
|
||||||
|
double val = pdhGetFormattedValue(c.longValue());
|
||||||
|
res.put(path, new Double(val));
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Iterator countersIt = counters.values().iterator();
|
||||||
|
while (countersIt.hasNext()) {
|
||||||
|
try {
|
||||||
|
Long counter = (Long)countersIt.next();
|
||||||
|
pdhRemoveCounter(counter.longValue());
|
||||||
|
} catch (Win32Exception ex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final native int validate(String path);
|
public static final native int validate(String path);
|
||||||
|
|
||||||
private static final native void pdhConnectMachine(String host)
|
private static final native void pdhConnectMachine(String host)
|
||||||
@@ -383,6 +457,13 @@ public class Pdh extends Win32 {
|
|||||||
private static final native int pdhLookupPerfIndex(String name)
|
private static final native int pdhLookupPerfIndex(String name)
|
||||||
throws Win32Exception;
|
throws Win32Exception;
|
||||||
|
|
||||||
|
private static final native void pdhCollectQueryDataOverSecond(long query)
|
||||||
|
throws Win32Exception;
|
||||||
|
|
||||||
|
private static final native double pdhGetFormattedValue(long counter)
|
||||||
|
throws Win32Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main method for dumping the entire PDH
|
* Main method for dumping the entire PDH
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
copyright.year=2004-2009
|
copyright.year=2004-2011
|
||||||
version.major=1
|
version.major=1
|
||||||
version.minor=6
|
version.minor=6
|
||||||
version.maint=4
|
version.maint=6
|
||||||
version.build=0
|
version.build=0
|
||||||
|
|
||||||
@@ -284,6 +284,47 @@ typedef struct {
|
|||||||
SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
sigar_proc_mem_t *procmem);
|
sigar_proc_mem_t *procmem);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sigar_uint64_t
|
||||||
|
bytes_read,
|
||||||
|
bytes_written,
|
||||||
|
bytes_total;
|
||||||
|
} sigar_proc_disk_io_t;
|
||||||
|
|
||||||
|
SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_disk_io_t *proc_disk_io);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sigar_uint64_t
|
||||||
|
bytes_read,
|
||||||
|
bytes_written,
|
||||||
|
bytes_total;
|
||||||
|
sigar_uint64_t last_time;
|
||||||
|
sigar_uint64_t
|
||||||
|
bytes_read_diff,
|
||||||
|
bytes_written_diff,
|
||||||
|
bytes_total_diff;
|
||||||
|
} sigar_cached_proc_disk_io_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sigar_uint64_t
|
||||||
|
bytes_read,
|
||||||
|
bytes_written,
|
||||||
|
bytes_total;
|
||||||
|
} sigar_proc_cumulative_disk_io_t;
|
||||||
|
|
||||||
|
SIGAR_DECLARE(int) sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
sigar_uint64_t dummy;
|
||||||
|
}sigar_dump_pid_cache_t;
|
||||||
|
|
||||||
|
SIGAR_DECLARE(int) sigar_dump_pid_cache_get(sigar_t *sigar, sigar_dump_pid_cache_t *info);
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
sigar_uid_t uid;
|
sigar_uid_t uid;
|
||||||
sigar_gid_t gid;
|
sigar_gid_t gid;
|
||||||
|
|||||||
@@ -66,7 +66,8 @@
|
|||||||
sigar_cache_t *proc_cpu; \
|
sigar_cache_t *proc_cpu; \
|
||||||
sigar_cache_t *net_listen; \
|
sigar_cache_t *net_listen; \
|
||||||
sigar_cache_t *net_services_tcp; \
|
sigar_cache_t *net_services_tcp; \
|
||||||
sigar_cache_t *net_services_udp
|
sigar_cache_t *net_services_udp;\
|
||||||
|
sigar_cache_t *proc_io
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
# define SIGAR_INLINE __inline
|
# define SIGAR_INLINE __inline
|
||||||
@@ -339,12 +340,16 @@ int sigar_get_iftype(const char *name, int *type, int *inst);
|
|||||||
#define SIGAR_NIC_LOOPBACK "Local Loopback"
|
#define SIGAR_NIC_LOOPBACK "Local Loopback"
|
||||||
#define SIGAR_NIC_ETHERNET "Ethernet"
|
#define SIGAR_NIC_ETHERNET "Ethernet"
|
||||||
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
|
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
|
||||||
|
#define PID_CACHE_CLEANUP_PERIOD 1000*60*10 /* 10 minutes */
|
||||||
|
#define PID_CACHE_ENTRY_EXPIRE_PERIOD 1000*60*20 /* 20 minutes */
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SIGAR_HOSTENT_LEN 512
|
#define PROC_PID_CPU_CACHE 1
|
||||||
|
#define PROC_PID_IO_CACHE 2
|
||||||
|
|
||||||
|
#define SIGAR_HOSTENT_LEN 1024
|
||||||
#if defined(_AIX)
|
#if defined(_AIX)
|
||||||
#define SIGAR_HAS_HOSTENT_DATA
|
#define SIGAR_HAS_HOSTENT_DATA
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -170,15 +170,21 @@ struct sigar_cache_entry_t {
|
|||||||
sigar_cache_entry_t *next;
|
sigar_cache_entry_t *next;
|
||||||
sigar_uint64_t id;
|
sigar_uint64_t id;
|
||||||
void *value;
|
void *value;
|
||||||
|
sigar_uint64_t last_access_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
sigar_cache_entry_t **entries;
|
sigar_cache_entry_t **entries;
|
||||||
unsigned int count, size;
|
unsigned int count, size;
|
||||||
void (*free_value)(void *ptr);
|
void (*free_value)(void *ptr);
|
||||||
|
sigar_uint64_t entry_expire_period;
|
||||||
|
sigar_uint64_t cleanup_period_millis;
|
||||||
|
sigar_uint64_t last_cleanup_time;
|
||||||
} sigar_cache_t;
|
} sigar_cache_t;
|
||||||
|
|
||||||
sigar_cache_t *sigar_cache_new(int size);
|
sigar_cache_t *sigar_cache_new(int size);
|
||||||
|
sigar_cache_t *sigar_expired_cache_new(int size, sigar_uint64_t cleanup_period_millis, sigar_uint64_t entry_expire_period);
|
||||||
|
void sigar_cache_dump(sigar_cache_t *table);
|
||||||
|
|
||||||
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
||||||
sigar_uint64_t key);
|
sigar_uint64_t key);
|
||||||
|
|||||||
@@ -745,6 +745,23 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *cumulative_proc_disk_io)
|
||||||
|
{
|
||||||
|
int status = sigar_getprocs(sigar, pid);
|
||||||
|
struct procsinfo64 *pinfo = sigar->pinfo;
|
||||||
|
|
||||||
|
if (status != SIGAR_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
cumulative_proc_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
||||||
|
cumulative_proc_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
||||||
|
cumulative_proc_disk_io->bytes_total = pinfo->pi_ioch;
|
||||||
|
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
sigar_proc_cred_t *proccred)
|
sigar_proc_cred_t *proccred)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1241,6 +1241,13 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
||||||
|
{
|
||||||
|
return SIGAR_ENOTIMPL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
sigar_proc_cred_t *proccred)
|
sigar_proc_cred_t *proccred)
|
||||||
{
|
{
|
||||||
@@ -3484,6 +3491,9 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
|||||||
case 6:
|
case 6:
|
||||||
codename = "Snow Leopard";
|
codename = "Snow Leopard";
|
||||||
break;
|
break;
|
||||||
|
case 7:
|
||||||
|
codename = "Lion";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
codename = "Unknown";
|
codename = "Unknown";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -305,6 +305,25 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
||||||
|
{
|
||||||
|
|
||||||
|
int status = sigar_pstat_getproc(sigar, pid);
|
||||||
|
struct pst_status *pinfo = sigar->pinfo;
|
||||||
|
|
||||||
|
if (status != SIGAR_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
proc_cumulative_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
||||||
|
proc_cumulative_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
||||||
|
proc_cumulative_disk_io->bytes_total = pinfo->pst_ioch;
|
||||||
|
|
||||||
|
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
sigar_proc_cred_t *proccred)
|
sigar_proc_cred_t *proccred)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -767,6 +767,34 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SIGAR_INLINE sigar_uint64_t get_named_proc_token(char *buffer,
|
||||||
|
char *token) {
|
||||||
|
char *ptr = strstr(buffer, token);
|
||||||
|
if (!ptr) {
|
||||||
|
return SIGAR_FIELD_NOTIMPL;
|
||||||
|
}
|
||||||
|
ptr = sigar_skip_token(ptr);
|
||||||
|
return sigar_strtoul(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
||||||
|
{
|
||||||
|
char buffer[BUFSIZ];
|
||||||
|
|
||||||
|
int status = SIGAR_PROC_FILE2STR(buffer, pid, "/io");
|
||||||
|
|
||||||
|
if (status != SIGAR_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
proc_cumulative_disk_io->bytes_read = get_named_proc_token(buffer, "\nread_bytes");
|
||||||
|
proc_cumulative_disk_io->bytes_written = get_named_proc_token(buffer, "\nwrite_bytes");
|
||||||
|
proc_cumulative_disk_io->bytes_total = proc_cumulative_disk_io->bytes_read + proc_cumulative_disk_io->bytes_written;
|
||||||
|
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#define NO_ID_MSG "[proc_cred] /proc/%lu" PROC_PSTATUS " missing "
|
#define NO_ID_MSG "[proc_cred] /proc/%lu" PROC_PSTATUS " missing "
|
||||||
|
|
||||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
|||||||
cpu->idle += xcpu->idle;
|
cpu->idle += xcpu->idle;
|
||||||
cpu->nice += xcpu->nice;
|
cpu->nice += xcpu->nice;
|
||||||
cpu->wait += xcpu->wait;
|
cpu->wait += xcpu->wait;
|
||||||
cpu->total = xcpu->total;
|
cpu->total += xcpu->total;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
@@ -717,6 +717,21 @@ int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
||||||
|
{
|
||||||
|
prusage_t usage;
|
||||||
|
int status;
|
||||||
|
if ((status = sigar_proc_usage_get(sigar, &usage, pid)) != SIGAR_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
proc_cumulative_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
||||||
|
proc_cumulative_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
||||||
|
proc_cumulative_disk_io->bytes_total = usage.pr_ioch;
|
||||||
|
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
sigar_proc_cred_t *proccred)
|
sigar_proc_cred_t *proccred)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
/* see apr/include/arch/win32/atime.h */
|
/* see apr/include/arch/win32/atime.h */
|
||||||
#define EPOCH_DELTA INT64_C(11644473600000000)
|
#define EPOCH_DELTA INT64_C(11644473600000000)
|
||||||
|
|
||||||
#define SIGAR_CMDLINE_MAX 4096
|
#define SIGAR_CMDLINE_MAX 4096<<2
|
||||||
|
|
||||||
/* XXX: support CP_UTF8 ? */
|
/* XXX: support CP_UTF8 ? */
|
||||||
|
|
||||||
@@ -317,6 +317,8 @@ typedef struct {
|
|||||||
sigar_uint64_t handles;
|
sigar_uint64_t handles;
|
||||||
sigar_uint64_t threads;
|
sigar_uint64_t threads;
|
||||||
sigar_uint64_t page_faults;
|
sigar_uint64_t page_faults;
|
||||||
|
sigar_uint64_t bytes_read;
|
||||||
|
sigar_uint64_t bytes_written;
|
||||||
} sigar_win32_pinfo_t;
|
} sigar_win32_pinfo_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ typedef enum {
|
|||||||
#define PERF_TITLE_PPID 1410
|
#define PERF_TITLE_PPID 1410
|
||||||
#define PERF_TITLE_PRIORITY 682
|
#define PERF_TITLE_PRIORITY 682
|
||||||
#define PERF_TITLE_START_TIME 684
|
#define PERF_TITLE_START_TIME 684
|
||||||
|
#define PERF_TITLE_IO_READ_BYTES_SEC 1420
|
||||||
|
#define PERF_TITLE_IO_WRITE_BYTES_SEC 1422
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PERF_IX_CPUTIME,
|
PERF_IX_CPUTIME,
|
||||||
@@ -70,6 +72,8 @@ typedef enum {
|
|||||||
PERF_IX_PPID,
|
PERF_IX_PPID,
|
||||||
PERF_IX_PRIORITY,
|
PERF_IX_PRIORITY,
|
||||||
PERF_IX_START_TIME,
|
PERF_IX_START_TIME,
|
||||||
|
PERF_IX_IO_READ_BYTES_SEC,
|
||||||
|
PERF_IX_IO_WRITE_BYTES_SEC,
|
||||||
PERF_IX_MAX
|
PERF_IX_MAX
|
||||||
} perf_proc_offsets_t;
|
} perf_proc_offsets_t;
|
||||||
|
|
||||||
@@ -1187,6 +1191,23 @@ SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SIGAR_DECLARE(int) sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
||||||
|
{
|
||||||
|
int status = get_proc_info(sigar, pid);
|
||||||
|
sigar_win32_pinfo_t *pinfo = &sigar->pinfo;
|
||||||
|
|
||||||
|
if (status != SIGAR_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
proc_cumulative_disk_io->bytes_read = pinfo->bytes_read;
|
||||||
|
proc_cumulative_disk_io->bytes_written = pinfo->bytes_written;
|
||||||
|
proc_cumulative_disk_io->bytes_total = proc_cumulative_disk_io->bytes_read + proc_cumulative_disk_io->bytes_written;
|
||||||
|
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#define TOKEN_DAC (STANDARD_RIGHTS_READ | READ_CONTROL | TOKEN_QUERY)
|
#define TOKEN_DAC (STANDARD_RIGHTS_READ | READ_CONTROL | TOKEN_QUERY)
|
||||||
|
|
||||||
SIGAR_DECLARE(int)
|
SIGAR_DECLARE(int)
|
||||||
@@ -1418,6 +1439,12 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
|
|||||||
case PERF_TITLE_START_TIME:
|
case PERF_TITLE_START_TIME:
|
||||||
perf_offsets[PERF_IX_START_TIME] = offset;
|
perf_offsets[PERF_IX_START_TIME] = offset;
|
||||||
break;
|
break;
|
||||||
|
case PERF_TITLE_IO_READ_BYTES_SEC:
|
||||||
|
perf_offsets[PERF_IX_IO_READ_BYTES_SEC] = offset;
|
||||||
|
break;
|
||||||
|
case PERF_TITLE_IO_WRITE_BYTES_SEC:
|
||||||
|
perf_offsets[PERF_IX_IO_WRITE_BYTES_SEC] = offset;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1443,6 +1470,8 @@ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid)
|
|||||||
pinfo->handles = PERF_VAL(PERF_IX_HANDLE_CNT);
|
pinfo->handles = PERF_VAL(PERF_IX_HANDLE_CNT);
|
||||||
pinfo->threads = PERF_VAL(PERF_IX_THREAD_CNT);
|
pinfo->threads = PERF_VAL(PERF_IX_THREAD_CNT);
|
||||||
pinfo->page_faults = PERF_VAL(PERF_IX_PAGE_FAULTS);
|
pinfo->page_faults = PERF_VAL(PERF_IX_PAGE_FAULTS);
|
||||||
|
pinfo->bytes_read = PERF_VAL(PERF_IX_IO_READ_BYTES_SEC);
|
||||||
|
pinfo->bytes_written = PERF_VAL(PERF_IX_IO_WRITE_BYTES_SEC);
|
||||||
|
|
||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
@@ -3504,6 +3533,7 @@ int sigar_who_list_get_win32(sigar_t *sigar,
|
|||||||
#define SIGAR_ARCH "x86"
|
#define SIGAR_ARCH "x86"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int sigar_os_sys_info_get(sigar_t *sigar,
|
int sigar_os_sys_info_get(sigar_t *sigar,
|
||||||
sigar_sys_info_t *sysinfo)
|
sigar_sys_info_t *sysinfo)
|
||||||
{
|
{
|
||||||
@@ -3511,7 +3541,7 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
|||||||
char *vendor_name, *vendor_version, *code_name=NULL;
|
char *vendor_name, *vendor_version, *code_name=NULL;
|
||||||
|
|
||||||
version.dwOSVersionInfoSize = sizeof(version);
|
version.dwOSVersionInfoSize = sizeof(version);
|
||||||
GetVersionEx((OSVERSIONINFO *)&version);
|
GetVersionEx((OSVERSIONINFO *)&version);
|
||||||
|
|
||||||
if (version.dwMajorVersion == 4) {
|
if (version.dwMajorVersion == 4) {
|
||||||
vendor_name = "Windows NT";
|
vendor_name = "Windows NT";
|
||||||
@@ -3551,11 +3581,25 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
|||||||
code_name = "Vienna";
|
code_name = "Vienna";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vendor_name = "Windows 2008";
|
// not nt work station
|
||||||
vendor_version = "2008";
|
if (version.dwMinorVersion == 0 || version.dwMinorVersion ==1) {
|
||||||
code_name = "Longhorn Server";
|
vendor_name = "Windows 2008";
|
||||||
}
|
vendor_version = "2008";
|
||||||
|
code_name = "Longhorn Server";
|
||||||
|
}
|
||||||
|
else if (version.dwMinorVersion == 2) {
|
||||||
|
vendor_name = "Windows 2012";
|
||||||
|
vendor_version = "2012";
|
||||||
|
code_name = "Windows Server 8";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// defaults
|
||||||
|
vendor_name = "Windows Unknown";
|
||||||
|
vendor_version = "2012";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SIGAR_SSTRCPY(sysinfo->name, "Win32");
|
SIGAR_SSTRCPY(sysinfo->name, "Win32");
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#pragma comment(lib, "wbemuuid.lib")
|
#pragma comment(lib, "wbemuuid.lib")
|
||||||
|
|
||||||
#ifndef SIGAR_CMDLINE_MAX
|
#ifndef SIGAR_CMDLINE_MAX
|
||||||
#define SIGAR_CMDLINE_MAX 4096
|
#define SIGAR_CMDLINE_MAX 4096<<2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class WMI {
|
class WMI {
|
||||||
|
|||||||
+108
-2
@@ -59,6 +59,7 @@ SIGAR_DECLARE(int) sigar_open(sigar_t **sigar)
|
|||||||
(*sigar)->net_listen = NULL;
|
(*sigar)->net_listen = NULL;
|
||||||
(*sigar)->net_services_tcp = NULL;
|
(*sigar)->net_services_tcp = NULL;
|
||||||
(*sigar)->net_services_udp = NULL;
|
(*sigar)->net_services_udp = NULL;
|
||||||
|
(*sigar)->proc_io = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -91,6 +92,11 @@ SIGAR_DECLARE(int) sigar_close(sigar_t *sigar)
|
|||||||
if (sigar->net_services_udp) {
|
if (sigar->net_services_udp) {
|
||||||
sigar_cache_destroy(sigar->net_services_udp);
|
sigar_cache_destroy(sigar->net_services_udp);
|
||||||
}
|
}
|
||||||
|
if (sigar->proc_io) {
|
||||||
|
sigar_cache_destroy(sigar->proc_io);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return sigar_os_close(sigar);
|
return sigar_os_close(sigar);
|
||||||
}
|
}
|
||||||
@@ -118,7 +124,7 @@ SIGAR_DECLARE(int) sigar_proc_cpu_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (!sigar->proc_cpu) {
|
if (!sigar->proc_cpu) {
|
||||||
sigar->proc_cpu = sigar_cache_new(128);
|
sigar->proc_cpu = sigar_expired_cache_new(128, PID_CACHE_CLEANUP_PERIOD, PID_CACHE_ENTRY_EXPIRE_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = sigar_cache_get(sigar->proc_cpu, pid);
|
entry = sigar_cache_get(sigar->proc_cpu, pid);
|
||||||
@@ -167,6 +173,106 @@ SIGAR_DECLARE(int) sigar_proc_cpu_get(sigar_t *sigar, sigar_pid_t pid,
|
|||||||
|
|
||||||
return SIGAR_OK;
|
return SIGAR_OK;
|
||||||
}
|
}
|
||||||
|
void copy_cached_disk_io_into_disk_io( sigar_cached_proc_disk_io_t *cached, sigar_proc_disk_io_t *proc_disk_io) {
|
||||||
|
proc_disk_io->bytes_read = cached->bytes_read_diff;
|
||||||
|
proc_disk_io->bytes_written = cached->bytes_written_diff;
|
||||||
|
proc_disk_io->bytes_total = cached->bytes_total_diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
sigar_uint64_t get_io_diff(sigar_uint64_t current_value, sigar_uint64_t prev_value, sigar_uint64_t time_diff) {
|
||||||
|
double io_diff;
|
||||||
|
sigar_uint64_t int_io_diff;
|
||||||
|
if ( current_value == SIGAR_FIELD_NOTIMPL ) {
|
||||||
|
return SIGAR_FIELD_NOTIMPL;
|
||||||
|
}
|
||||||
|
io_diff = (( current_value - prev_value)/(double)time_diff)*SIGAR_MSEC;
|
||||||
|
int_io_diff = (sigar_uint64_t)io_diff;
|
||||||
|
if (int_io_diff >=0) {
|
||||||
|
return int_io_diff;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void calculate_io_diff(sigar_proc_cumulative_disk_io_t * proc_disk_io, sigar_cached_proc_disk_io_t *cached, sigar_uint64_t time_diff, int is_first_time) {
|
||||||
|
/*calculate avg diff /read/write/total per second*/
|
||||||
|
if (!is_first_time) {
|
||||||
|
cached->bytes_written_diff = get_io_diff(proc_disk_io->bytes_written, cached->bytes_written, time_diff);
|
||||||
|
cached->bytes_read_diff = get_io_diff(proc_disk_io->bytes_read, cached->bytes_read, time_diff);
|
||||||
|
cached->bytes_total_diff = get_io_diff(proc_disk_io->bytes_total, cached->bytes_total, time_diff);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cached->bytes_total_diff = cached->bytes_read_diff = cached->bytes_written_diff = 0.0;
|
||||||
|
}
|
||||||
|
// now put in cache the current cumulative values
|
||||||
|
cached->bytes_written = proc_disk_io->bytes_written;
|
||||||
|
cached->bytes_read = proc_disk_io->bytes_read;
|
||||||
|
cached->bytes_total = proc_disk_io->bytes_total;
|
||||||
|
}
|
||||||
|
|
||||||
|
SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
|
sigar_proc_disk_io_t *proc_disk_io)
|
||||||
|
{
|
||||||
|
sigar_cache_entry_t *entry;
|
||||||
|
sigar_cached_proc_disk_io_t *prev;
|
||||||
|
sigar_proc_cumulative_disk_io_t cumulative_proc_disk_io;
|
||||||
|
sigar_uint64_t time_now = sigar_time_now_millis();
|
||||||
|
sigar_uint64_t time_diff;
|
||||||
|
int status, is_first_time;
|
||||||
|
|
||||||
|
if (!sigar->proc_io) {
|
||||||
|
sigar->proc_io = sigar_expired_cache_new(128, PID_CACHE_CLEANUP_PERIOD, PID_CACHE_ENTRY_EXPIRE_PERIOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = sigar_cache_get(sigar->proc_io, pid);
|
||||||
|
if (entry->value) {
|
||||||
|
prev = (sigar_cached_proc_disk_io_t *)entry->value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prev = entry->value = malloc(sizeof(*prev));
|
||||||
|
SIGAR_ZERO(prev);
|
||||||
|
}
|
||||||
|
is_first_time = (prev->last_time == 0);
|
||||||
|
time_diff = time_now - prev->last_time;
|
||||||
|
|
||||||
|
if (time_diff < 1000) {
|
||||||
|
/* we were just called within < 1 second ago. */
|
||||||
|
copy_cached_disk_io_into_disk_io(prev, proc_disk_io);
|
||||||
|
if (time_diff < 0) {
|
||||||
|
// something is wrong at least from now on the time will be ok
|
||||||
|
prev->last_time = time_now;
|
||||||
|
}
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
prev->last_time = time_now;
|
||||||
|
|
||||||
|
|
||||||
|
status =
|
||||||
|
sigar_proc_cumulative_disk_io_get(sigar, pid,
|
||||||
|
&cumulative_proc_disk_io);
|
||||||
|
|
||||||
|
if (status != SIGAR_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
calculate_io_diff(&cumulative_proc_disk_io, prev, time_diff, is_first_time);
|
||||||
|
copy_cached_disk_io_into_disk_io(prev, proc_disk_io);
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_cache_info(sigar_cache_t * cache, char * name){
|
||||||
|
if (cache == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("******** %s *********\n", name);
|
||||||
|
sigar_cache_dump(cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
SIGAR_DECLARE(int) sigar_dump_pid_cache_get(sigar_t *sigar, sigar_dump_pid_cache_t *info) {
|
||||||
|
|
||||||
|
get_cache_info(sigar->proc_cpu, "proc cpu cache");
|
||||||
|
get_cache_info(sigar->proc_io, "proc io cache");
|
||||||
|
return SIGAR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
SIGAR_DECLARE(int) sigar_proc_stat_get(sigar_t *sigar,
|
SIGAR_DECLARE(int) sigar_proc_stat_get(sigar_t *sigar,
|
||||||
sigar_proc_stat_t *procstat)
|
sigar_proc_stat_t *procstat)
|
||||||
@@ -412,7 +518,7 @@ static int sigar_common_fs_type_get(sigar_file_system_t *fsp)
|
|||||||
|
|
||||||
switch (*type) {
|
switch (*type) {
|
||||||
case 'n':
|
case 'n':
|
||||||
if (strEQ(type, "nfs")) {
|
if (strnEQ(type, "nfs", 3)) {
|
||||||
fsp->type = SIGAR_FSTYPE_NETWORK;
|
fsp->type = SIGAR_FSTYPE_NETWORK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
+81
-7
@@ -35,7 +35,7 @@ static void free_value(void *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
sigar_cache_t *sigar_cache_new(int size)
|
sigar_cache_t *sigar_expired_cache_new(int size, sigar_uint64_t cleanup_period_millis, sigar_uint64_t entry_expire_period)
|
||||||
{
|
{
|
||||||
sigar_cache_t *table = malloc(sizeof(*table));
|
sigar_cache_t *table = malloc(sizeof(*table));
|
||||||
table->count = 0;
|
table->count = 0;
|
||||||
@@ -43,16 +43,27 @@ sigar_cache_t *sigar_cache_new(int size)
|
|||||||
table->entries = malloc(ENTRIES_SIZE(size));
|
table->entries = malloc(ENTRIES_SIZE(size));
|
||||||
memset(table->entries, '\0', ENTRIES_SIZE(size));
|
memset(table->entries, '\0', ENTRIES_SIZE(size));
|
||||||
table->free_value = free_value;
|
table->free_value = free_value;
|
||||||
|
table->cleanup_period_millis = cleanup_period_millis;
|
||||||
|
table->last_cleanup_time = sigar_time_now_millis();
|
||||||
|
table->entry_expire_period = entry_expire_period;
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_CACHE
|
sigar_cache_t *sigar_cache_new(int size)
|
||||||
|
{
|
||||||
|
return sigar_expired_cache_new(size, SIGAR_FIELD_NOTIMPL, SIGAR_FIELD_NOTIMPL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*#ifdef DEBUG_CACHE*/
|
||||||
/* see how well entries are distributed */
|
/* see how well entries are distributed */
|
||||||
static void sigar_cache_dump(sigar_cache_t *table)
|
void sigar_cache_dump(sigar_cache_t *table)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
sigar_cache_entry_t **entries = table->entries;
|
sigar_cache_entry_t **entries = table->entries;
|
||||||
|
printf("table size %lu\n", (long)table->size);
|
||||||
|
printf("table count %lu\n", (long)table->count);
|
||||||
|
|
||||||
for (i=0; i<table->size; i++) {
|
for (i=0; i<table->size; i++) {
|
||||||
sigar_cache_entry_t *entry = *entries++;
|
sigar_cache_entry_t *entry = *entries++;
|
||||||
|
|
||||||
@@ -68,12 +79,12 @@ static void sigar_cache_dump(sigar_cache_t *table)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
#endif
|
/*#endif*/
|
||||||
|
|
||||||
static void sigar_cache_rehash(sigar_cache_t *table)
|
static void sigar_cache_rehash(sigar_cache_t *table)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned int new_size = table->size * 2 + 1;
|
unsigned int new_size = table->count * 2 + 1;
|
||||||
sigar_cache_entry_t **entries = table->entries;
|
sigar_cache_entry_t **entries = table->entries;
|
||||||
sigar_cache_entry_t **new_entries =
|
sigar_cache_entry_t **new_entries =
|
||||||
malloc(ENTRIES_SIZE(new_size));
|
malloc(ENTRIES_SIZE(new_size));
|
||||||
@@ -101,16 +112,76 @@ static void sigar_cache_rehash(sigar_cache_t *table)
|
|||||||
#define SIGAR_CACHE_IX(t, k) \
|
#define SIGAR_CACHE_IX(t, k) \
|
||||||
t->entries + (k % t->size)
|
t->entries + (k % t->size)
|
||||||
|
|
||||||
|
void sigar_perform_cleanup_if_necessary(sigar_cache_t *table) {
|
||||||
|
sigar_uint64_t current_time;
|
||||||
|
int i;
|
||||||
|
sigar_cache_entry_t **entries;
|
||||||
|
if (table->cleanup_period_millis == SIGAR_FIELD_NOTIMPL) {
|
||||||
|
/* no cleanup for this cache) */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
current_time = sigar_time_now_millis();
|
||||||
|
if ((current_time - table->last_cleanup_time) < table->cleanup_period_millis) {
|
||||||
|
/* not enough time has passed since last cleanup */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* performing cleanup */
|
||||||
|
entries = table->entries;
|
||||||
|
|
||||||
|
table->last_cleanup_time = current_time;
|
||||||
|
|
||||||
|
for (i=0; i<table->size; i++) {
|
||||||
|
sigar_cache_entry_t *entry, *ptr, *entry_prev=NULL, **entry_in_table;
|
||||||
|
entry_in_table = entries;
|
||||||
|
entry = *entries++;
|
||||||
|
|
||||||
|
while (entry) {
|
||||||
|
sigar_uint64_t period_with_no_access = current_time - entry->last_access_time;
|
||||||
|
ptr = entry->next;
|
||||||
|
if (table->entry_expire_period < period_with_no_access) {
|
||||||
|
/* no one acess this entry for too long - we can delete it */
|
||||||
|
if (entry->value) {
|
||||||
|
table->free_value(entry->value);
|
||||||
|
}
|
||||||
|
free(entry);
|
||||||
|
table->count--;
|
||||||
|
if (entry_prev != NULL) {
|
||||||
|
entry_prev->next = ptr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* removing first entry - head of list should point to next entry */
|
||||||
|
*entry_in_table = ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* entry not expired - advance entry_prev to current entry*/
|
||||||
|
entry_prev = entry;
|
||||||
|
}
|
||||||
|
entry = ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (table->count < (table->size/4)) {
|
||||||
|
/* hash table (the array size) too big for the amount of values it contains perform rehash */
|
||||||
|
sigar_cache_rehash(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
|
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
|
||||||
sigar_uint64_t key)
|
sigar_uint64_t key)
|
||||||
{
|
{
|
||||||
sigar_cache_entry_t *entry, **ptr;
|
sigar_cache_entry_t *entry, **ptr;
|
||||||
|
sigar_perform_cleanup_if_necessary(table);
|
||||||
|
|
||||||
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
||||||
entry;
|
entry;
|
||||||
ptr = &entry->next, entry = *ptr)
|
ptr = &entry->next, entry = *ptr)
|
||||||
{
|
{
|
||||||
if (entry->id == key) {
|
if (entry->id == key) {
|
||||||
|
entry->last_access_time = sigar_time_now_millis();
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,17 +194,19 @@ sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
|||||||
sigar_uint64_t key)
|
sigar_uint64_t key)
|
||||||
{
|
{
|
||||||
sigar_cache_entry_t *entry, **ptr;
|
sigar_cache_entry_t *entry, **ptr;
|
||||||
|
sigar_perform_cleanup_if_necessary(table);
|
||||||
|
|
||||||
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
||||||
entry;
|
entry;
|
||||||
ptr = &entry->next, entry = *ptr)
|
ptr = &entry->next, entry = *ptr)
|
||||||
{
|
{
|
||||||
if (entry->id == key) {
|
if (entry->id == key) {
|
||||||
|
entry->last_access_time = sigar_time_now_millis();
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (table->count++ > table->size) {
|
if (++table->count > table->size) {
|
||||||
sigar_cache_rehash(table);
|
sigar_cache_rehash(table);
|
||||||
|
|
||||||
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
for (ptr = SIGAR_CACHE_IX(table, key), entry = *ptr;
|
||||||
@@ -147,6 +220,7 @@ sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
|||||||
entry->id = key;
|
entry->id = key;
|
||||||
entry->value = NULL;
|
entry->value = NULL;
|
||||||
entry->next = NULL;
|
entry->next = NULL;
|
||||||
|
entry->last_access_time = sigar_time_now_millis();
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
/* sysconf(_SC_GET{PW,GR}_R_SIZE_MAX) */
|
/* sysconf(_SC_GET{PW,GR}_R_SIZE_MAX) */
|
||||||
#define R_SIZE_MAX 1024
|
#define R_SIZE_MAX 2048
|
||||||
|
|
||||||
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen)
|
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1325,6 +1325,14 @@ static ptql_lookup_t PTQL_Cpu[] = {
|
|||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ptql_lookup_t PTQL_Disk_IO[] = {
|
||||||
|
{ "BytesRead", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_read, UI64) },
|
||||||
|
{ "BytesWritten", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_written, UI64) },
|
||||||
|
{ "BytesTotal", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_total, UI64) },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static ptql_lookup_t PTQL_CredName[] = {
|
static ptql_lookup_t PTQL_CredName[] = {
|
||||||
{ "User", PTQL_LOOKUP_ENTRY(proc_cred_name, user, STR) },
|
{ "User", PTQL_LOOKUP_ENTRY(proc_cred_name, user, STR) },
|
||||||
{ "Group", PTQL_LOOKUP_ENTRY(proc_cred_name, group, STR) },
|
{ "Group", PTQL_LOOKUP_ENTRY(proc_cred_name, group, STR) },
|
||||||
@@ -1411,6 +1419,7 @@ static ptql_entry_t ptql_map[] = {
|
|||||||
{ "Port", PTQL_Port },
|
{ "Port", PTQL_Port },
|
||||||
{ "Pid", PTQL_Pid },
|
{ "Pid", PTQL_Pid },
|
||||||
{ "Service", PTQL_Service },
|
{ "Service", PTQL_Service },
|
||||||
|
{ "Disk_IO", PTQL_Disk_IO },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user