Better integration of sigar instrumentation library. Should work on windows, linux, mac.

Added PID and virt memory used to log when application starts.
This commit is contained in:
adam-m 2013-03-07 14:31:22 -05:00
parent 55077002d3
commit 7037fb8403
9 changed files with 95 additions and 20 deletions

View File

@ -54,6 +54,14 @@ public class Installer extends ModuleInstall {
autopsyLogger.log(Level.INFO, "Application name: " + Version.getName()
+ ", version: " + Version.getVersion() + ", build: " + Version.getBuildType());
autopsyLogger.log(Level.INFO, "os.name: " + System.getProperty("os.name"));
autopsyLogger.log(Level.INFO, "os.arch: " + System.getProperty("os.arch"));
autopsyLogger.log(Level.INFO, "PID: " + PlatformUtil.getPID());
autopsyLogger.log(Level.INFO, "Process Virtual Memory Used: " + PlatformUtil.getProcessVirtualMemoryUsed());
}
@Override

View File

@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.swing.filechooser.FileSystemView;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarLoader;
import org.openide.modules.InstalledFileLocator;
import org.openide.modules.Places;
import org.sleuthkit.autopsy.casemodule.LocalDisk;
@ -398,11 +399,14 @@ public class PlatformUtil {
try {
if (sigar == null) {
sigar = new Sigar();
sigar = org.sleuthkit.autopsy.corelibs.SigarLoader.getSigar();
}
if (sigar != null) {
pid = sigar.getPid();
}
else {
System.out.println("Can't get PID");
}
pid = sigar.getPid();
} catch (UnsatisfiedLinkError e) {
System.out.println("Can't load library and get PID, " + e.toString());
} catch (Exception e) {
System.out.println("Can't get PID, " + e.toString());
}
@ -421,16 +425,14 @@ public class PlatformUtil {
try {
if (sigar == null) {
sigar = new Sigar();
sigar = org.sleuthkit.autopsy.corelibs.SigarLoader.getSigar();
}
if (sigar == null || pid == -1) {
System.out.println("Can't get virt mem used");
return -1;
}
virtMem = sigar.getProcMem(pid).getSize();
} catch (UnsatisfiedLinkError e) {
System.out.println("Can't load library and get virt mem used, " + e.toString());
} catch (Exception e) {
System.out.println("Can't get virt mem used, " + e.toString());
}

View File

@ -4,9 +4,9 @@
<!-- sigar: note, matching jar is pulled with ivy -->
<mkdir dir="${lib.dir}"/>
<unzip src="${thirdparty.dir}/sigar/1.6.4/sigar-native.zip" dest="${lib.dir}" >
<patternset>
<!-- get all, rely on jna to locate <patternset>
<include name="**/*.dylib"/>
</patternset>
</patternset> -->
</unzip>
</target>

View File

@ -4,9 +4,9 @@
<!-- sigar: note, matching jar is pulled with ivy -->
<mkdir dir="${lib.dir}"/>
<unzip src="${thirdparty.dir}/sigar/1.6.4/sigar-native.zip" dest="${lib.dir}" >
<patternset>
<!-- get all, rely on jna to locate <patternset>
<include name="**/*.so"/>
</patternset>
</patternset> -->
</unzip>
</target>

View File

@ -4,9 +4,9 @@
<!-- sigar: note, matching jar is pulled with ivy -->
<mkdir dir="${lib.dir}"/>
<unzip src="${thirdparty.dir}/sigar/1.6.4/sigar-native.zip" dest="${lib.dir}" >
<patternset>
<!-- get all, rely on jna to locate <patternset>
<include name="**/*.dll"/>
</patternset>
</patternset> -->
</unzip>
</target>

View File

@ -4,6 +4,7 @@ file.reference.ant-launcher-1.8.2.jar=release/modules/ext/ant-launcher-1.8.2.jar
file.reference.AppleJavaExtensions-1.4.jar=release/modules/ext/AppleJavaExtensions-1.4.jar
file.reference.avalon-framework-4.1.3.jar=release/modules/ext/avalon-framework-4.1.3.jar
file.reference.commons-codec-1.5.jar=release/modules/ext/commons-codec-1.5.jar
file.reference.commons-io-2.4.jar=release/modules/ext/commons-io-2.4.jar
file.reference.commons-lang-2.4.jar=release/modules/ext/commons-lang-2.4.jar
file.reference.commons-logging-1.1.1.jar=release/modules/ext/commons-logging-1.1.1.jar
file.reference.dom4j-1.6.1.jar=release/modules/ext/dom4j-1.6.1.jar
@ -28,7 +29,6 @@ file.reference.poi-ooxml-schemas-3.8.jar=release/modules/ext/poi-ooxml-schemas-3
file.reference.poi-scratchpad-3.8.jar=release/modules/ext/poi-scratchpad-3.8.jar
file.reference.reflections-0.9.8.jar=release/modules/ext/reflections-0.9.8.jar
file.reference.servlet-api-2.5.jar=release/modules/ext/servlet-api-2.5.jar
file.reference.sigar-1.6.4.jar=release/modules/ext/sigar-1.6.4.jar
file.reference.slf4j-api-1.6.1.jar=release/modules/ext/slf4j-api-1.6.1.jar
file.reference.slf4j-simple-1.6.1.jar=release/modules/ext/slf4j-simple-1.6.1.jar
file.reference.stax-api-1.0.1.jar=release/modules/ext/stax-api-1.0.1.jar

View File

@ -661,7 +661,6 @@
<package>org.hyperic.sigar.util</package>
<package>org.hyperic.sigar.vmware</package>
<package>org.hyperic.sigar.win32</package>
<package>org.hyperic.sigar.win32.test</package>
<package>org.jbundle.thin.base.screen.jcalendarbutton</package>
<package>org.openxmlformats.schemas.drawingml.x2006.chart</package>
<package>org.openxmlformats.schemas.drawingml.x2006.chart.impl</package>
@ -693,6 +692,7 @@
<package>org.reflections.serializers</package>
<package>org.reflections.util</package>
<package>org.reflections.vfs</package>
<package>org.sleuthkit.autopsy.corelibs</package>
<package>org.slf4j</package>
<package>org.slf4j.helpers</package>
<package>org.slf4j.impl</package>
@ -822,18 +822,22 @@
<runtime-relative-path>ext/AppleJavaExtensions-1.4.jar</runtime-relative-path>
<binary-origin>release/modules/ext/AppleJavaExtensions-1.4.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/jfxrt.jar</runtime-relative-path>
<binary-origin>release/modules/ext/jfxrt.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/sigar-1.6.4.jar</runtime-relative-path>
<binary-origin>release/modules/ext/sigar-1.6.4.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/jfxrt.jar</runtime-relative-path>
<binary-origin>release/modules/ext/jfxrt.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/gson-1.4.jar</runtime-relative-path>
<binary-origin>release/modules/ext/gson-1.4.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/sigar-1.6.4-sources.jar</runtime-relative-path>
<binary-origin>release/modules/ext/sigar-1.6.4-sources.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/servlet-api-2.5.jar</runtime-relative-path>
<binary-origin>release/modules/ext/servlet-api-2.5.jar</binary-origin>

View File

@ -0,0 +1,61 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* 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.sleuthkit.autopsy.corelibs;
import java.io.File;
import org.hyperic.sigar.Sigar;
/**
* Wrapper over Sigar instrumentation class to facilitate dll loading.
* Our setup bypasses Sigar library loader which does not work well for netbeans environment
* We are responsible for loading the library ourselves.
*/
public class SigarLoader {
private static volatile Sigar sigar;
static {
//bypass the process of validation/loading of the library by sigar jar
System.setProperty("org.hyperic.sigar.path", "-");
//System.setProperty(org.hyperic.sigar.SigarLoader.PROP_SIGAR_JAR_NAME, "sigar-1.6.4.jar");
}
public static Sigar getSigar() {
if (sigar == null) {
synchronized (SigarLoader.class) {
try {
//rely on netbeans / jna to locate the lib variation for architecture/OS
System.loadLibrary("libsigar");
sigar = new Sigar();
sigar.enableLogging(false); //forces a test
} catch (UnsatisfiedLinkError ex) {
System.out.println("Error loading sigar library" + ex.toString());
}
catch (Exception ex) {
System.out.println("Error loading sigar library" + ex.toString());
}
}
}
return sigar;
}
}

Binary file not shown.