mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-22 15:53:58 +02:00
Bug 148484 - Refactor logging plugin
This commit is contained in:
parent
cdf07cd4b3
commit
9ab955d6bf
8 changed files with 85 additions and 136 deletions
|
@ -18,14 +18,11 @@ package org.eclipse.rse.internal.logging;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.rse.logging.Logger;
|
import org.eclipse.rse.logging.Logger;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
||||||
|
|
||||||
public class LoggerController {
|
public class LoggerController {
|
||||||
|
|
||||||
public static final String Copyright =
|
|
||||||
"(C) Copyright IBM Corp. 2002, 2003. All Rights Reserved.";
|
|
||||||
|
|
||||||
private static Hashtable pluginTable = new Hashtable();
|
private static Hashtable pluginTable = new Hashtable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,19 +30,19 @@ public class LoggerController {
|
||||||
* It will return null if no Logger instance has been created
|
* It will return null if no Logger instance has been created
|
||||||
* for this plugin before.
|
* for this plugin before.
|
||||||
*/
|
*/
|
||||||
public static Logger getInst(AbstractUIPlugin plugin) {
|
public static Logger getInst(Plugin plugin) {
|
||||||
if (pluginTable.containsKey(plugin))
|
if (pluginTable.containsKey(plugin))
|
||||||
return (Logger) pluginTable.get(plugin);
|
return (Logger) pluginTable.get(plugin);
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerInst(AbstractUIPlugin plugin, Logger logger) {
|
public static void registerInst(Plugin plugin, Logger logger) {
|
||||||
pluginTable.put(plugin, logger);
|
pluginTable.put(plugin, logger);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void freeInst(AbstractUIPlugin plugin) {
|
public static void freeInst(Plugin plugin) {
|
||||||
// get cached instance if one exists.
|
// get cached instance if one exists.
|
||||||
Logger logger = getInst(plugin);
|
Logger logger = getInst(plugin);
|
||||||
// no luck, this means we have an incorrect free, do nothing.
|
// no luck, this means we have an incorrect free, do nothing.
|
||||||
|
|
|
@ -25,65 +25,59 @@ import java.util.Date;
|
||||||
import org.eclipse.core.runtime.ILogListener;
|
import org.eclipse.core.runtime.ILogListener;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
import org.eclipse.core.runtime.Preferences;
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
|
||||||
|
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
|
||||||
import org.eclipse.rse.logging.IRemoteSystemsLogging;
|
import org.eclipse.rse.logging.IRemoteSystemsLogging;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log Listener is a sink for messages coming from Logger.
|
* Log Listener is a sink for messages coming from Logger.
|
||||||
*/
|
*/
|
||||||
public class RemoteSystemLogListener
|
public class RemoteSystemLogListener implements ILogListener, IPropertyChangeListener {
|
||||||
implements ILogListener, IPropertyChangeListener {
|
|
||||||
|
|
||||||
public static final String Copyright =
|
|
||||||
"(C) Copyright IBM Corp. 2002, 2003. All Rights Reserved.";
|
|
||||||
|
|
||||||
private PrintWriter log = null;
|
private PrintWriter log = null;
|
||||||
private File outputFile = null;
|
private File outputFile = null;
|
||||||
private boolean log_to_stdout = false;
|
private boolean log_to_stdout = false;
|
||||||
private AbstractUIPlugin plugin = null;
|
private Plugin plugin = null;
|
||||||
|
|
||||||
public RemoteSystemLogListener(AbstractUIPlugin plugin) {
|
/**
|
||||||
|
* Create a new log listener for a plugin.
|
||||||
|
* @param plugin The plugin for which to create a log listener.
|
||||||
|
*/
|
||||||
|
public RemoteSystemLogListener(Plugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
IPath path =
|
IPath path = plugin.getStateLocation().addTrailingSeparator().append(".log");
|
||||||
plugin.getStateLocation().addTrailingSeparator().append(".log");
|
|
||||||
|
|
||||||
outputFile = path.toFile();
|
outputFile = path.toFile();
|
||||||
|
|
||||||
// make sure to delete old log file.
|
|
||||||
if ((outputFile != null) && (outputFile.exists())) {
|
if ((outputFile != null) && (outputFile.exists())) {
|
||||||
outputFile.delete();
|
outputFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the logger. Retrieves the logging location preference and sets up the logger
|
||||||
|
* to log to that location.
|
||||||
|
*/
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
try {
|
try {
|
||||||
// Initialize log file location here. Check to see
|
Preferences store = plugin.getPluginPreferences();
|
||||||
// if we need to log to file or View.
|
String log_location = store.getString(IRemoteSystemsLogging.LOG_LOCATION);
|
||||||
IPreferenceStore store = plugin.getPreferenceStore();
|
if ((log_location != null) && (log_location.equalsIgnoreCase(IRemoteSystemsLogging.LOG_TO_STDOUT))) {
|
||||||
String log_location =
|
|
||||||
store.getString(
|
|
||||||
IRemoteSystemsLogging.LOG_LOCATION);
|
|
||||||
|
|
||||||
if ((log_location != null)
|
|
||||||
&& (log_location
|
|
||||||
.equalsIgnoreCase(IRemoteSystemsLogging.LOG_TO_STDOUT))) {
|
|
||||||
doLogToView();
|
doLogToView();
|
||||||
} else {
|
} else {
|
||||||
doLogToFile();
|
doLogToFile();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// can not log anything.
|
|
||||||
log = null;
|
log = null;
|
||||||
System.err.println("Exception in RemoteSystemLogListener.initialize(): " + e.getMessage());
|
System.err.println("Exception in RemoteSystemLogListener.initialize(): " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs to standard output.
|
||||||
|
*/
|
||||||
private void doLogToView() {
|
private void doLogToView() {
|
||||||
// make sure we free resources first
|
// make sure we free resources first
|
||||||
freeResources();
|
freeResources();
|
||||||
|
@ -153,7 +147,6 @@ public class RemoteSystemLogListener
|
||||||
if (log == null)
|
if (log == null)
|
||||||
return;
|
return;
|
||||||
else {
|
else {
|
||||||
int severity = status.getSeverity();
|
|
||||||
log.print("\t\t");
|
log.print("\t\t");
|
||||||
log.println(status.getMessage());
|
log.println(status.getMessage());
|
||||||
if (status.getException() != null)
|
if (status.getException() != null)
|
||||||
|
|
|
@ -16,14 +16,13 @@
|
||||||
|
|
||||||
package org.eclipse.rse.logging;
|
package org.eclipse.rse.logging;
|
||||||
|
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main plugin class to be used in the desktop.
|
* The main plugin class to be used in the desktop.
|
||||||
*/
|
*/
|
||||||
public class Activator extends AbstractUIPlugin {
|
public class Activator extends Plugin {
|
||||||
|
|
||||||
//The shared instance.
|
//The shared instance.
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
@ -57,14 +56,4 @@ public class Activator extends AbstractUIPlugin {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an image descriptor for the image file at the given
|
|
||||||
* plug-in relative path.
|
|
||||||
*
|
|
||||||
* @param path the path
|
|
||||||
* @return the image descriptor
|
|
||||||
*/
|
|
||||||
public static ImageDescriptor getImageDescriptor(String path) {
|
|
||||||
return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.rse.logging", path);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -20,12 +20,12 @@ import org.eclipse.core.runtime.ILog;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.Plugin;
|
||||||
|
import org.eclipse.core.runtime.Preferences;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
|
||||||
import org.eclipse.rse.internal.logging.RemoteSystemLogListener;
|
import org.eclipse.rse.internal.logging.RemoteSystemLogListener;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class Logger implements IPropertyChangeListener {
|
||||||
|
|
||||||
// Cashed Plugin ID, and plugin
|
// Cashed Plugin ID, and plugin
|
||||||
private String pluginId = null;
|
private String pluginId = null;
|
||||||
AbstractUIPlugin systemPlugin = null;
|
Plugin systemPlugin = null;
|
||||||
|
|
||||||
// Controls logging level
|
// Controls logging level
|
||||||
private int debug_level = 0;
|
private int debug_level = 0;
|
||||||
|
@ -100,7 +100,7 @@ public class Logger implements IPropertyChangeListener {
|
||||||
// Captures initialization errors
|
// Captures initialization errors
|
||||||
private boolean init_ok = true;
|
private boolean init_ok = true;
|
||||||
|
|
||||||
protected Logger(AbstractUIPlugin systemPlugin) {
|
protected Logger(Plugin systemPlugin) {
|
||||||
this.systemPlugin = systemPlugin;
|
this.systemPlugin = systemPlugin;
|
||||||
this.pluginId = systemPlugin.getBundle().getSymbolicName();
|
this.pluginId = systemPlugin.getBundle().getSymbolicName();
|
||||||
initialize();
|
initialize();
|
||||||
|
@ -116,11 +116,11 @@ public class Logger implements IPropertyChangeListener {
|
||||||
|
|
||||||
// get the debug level from plugin Preference store.
|
// get the debug level from plugin Preference store.
|
||||||
// note: logListener must be initialized before calling getPreference store!
|
// note: logListener must be initialized before calling getPreference store!
|
||||||
IPreferenceStore store = systemPlugin.getPreferenceStore();
|
Preferences store = systemPlugin.getPluginPreferences();
|
||||||
debug_level = store.getInt(IRemoteSystemsLogging.DEBUG_LEVEL);
|
debug_level = store.getInt(IRemoteSystemsLogging.DEBUG_LEVEL);
|
||||||
|
|
||||||
systemPlugin.getPreferenceStore().addPropertyChangeListener(this);
|
store.addPropertyChangeListener(this);
|
||||||
systemPlugin.getPreferenceStore().addPropertyChangeListener(logListener);
|
store.addPropertyChangeListener(logListener);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Errors occured during initialize, disable logging.
|
// Errors occured during initialize, disable logging.
|
||||||
|
@ -264,10 +264,8 @@ public class Logger implements IPropertyChangeListener {
|
||||||
*/
|
*/
|
||||||
public synchronized void propertyChange(PropertyChangeEvent event) {
|
public synchronized void propertyChange(PropertyChangeEvent event) {
|
||||||
// refresh the debug level from plugin Preference store
|
// refresh the debug level from plugin Preference store
|
||||||
debug_level =
|
Preferences prefs = systemPlugin.getPluginPreferences();
|
||||||
systemPlugin.getPreferenceStore().getInt(
|
debug_level = prefs.getInt(IRemoteSystemsLogging.DEBUG_LEVEL);
|
||||||
IRemoteSystemsLogging.DEBUG_LEVEL);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -16,9 +16,8 @@
|
||||||
|
|
||||||
package org.eclipse.rse.logging;
|
package org.eclipse.rse.logging;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.rse.internal.logging.LoggerController;
|
import org.eclipse.rse.internal.logging.LoggerController;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class for creating Logger instances.<br>
|
* Factory class for creating Logger instances.<br>
|
||||||
|
@ -34,7 +33,7 @@ public class LoggerFactory {
|
||||||
* a singelton instance of the Logger class per plugin. You are guarenteed the
|
* a singelton instance of the Logger class per plugin. You are guarenteed the
|
||||||
* same instance if one has previously been created.
|
* same instance if one has previously been created.
|
||||||
*/
|
*/
|
||||||
public static Logger getInst(AbstractUIPlugin plugin) {
|
public static Logger getInst(Plugin plugin) {
|
||||||
|
|
||||||
// get cached instance from controller if one exists.
|
// get cached instance from controller if one exists.
|
||||||
Logger inst = LoggerController.getInst(plugin);
|
Logger inst = LoggerController.getInst(plugin);
|
||||||
|
@ -58,7 +57,7 @@ public class LoggerFactory {
|
||||||
* Frees resources used by the Logger instance for the given plugin.<br>
|
* Frees resources used by the Logger instance for the given plugin.<br>
|
||||||
* This methods must be called as part of the the plugin shutdown life cycle.
|
* This methods must be called as part of the the plugin shutdown life cycle.
|
||||||
*/
|
*/
|
||||||
public static void freeInst(AbstractUIPlugin plugin) {
|
public static void freeInst(Plugin plugin) {
|
||||||
// delegate to controller
|
// delegate to controller
|
||||||
LoggerController.freeInst(plugin);
|
LoggerController.freeInst(plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,10 +94,10 @@ public abstract class LoggingPreferencePage extends PreferencePage implements IW
|
||||||
String bundleName = (String)(bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME));
|
String bundleName = (String)(bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME));
|
||||||
String topLabel1 = RemoteSystemsLoggingPlugin.getResourceString("LoggingPreferencePage.topLabel1");
|
String topLabel1 = RemoteSystemsLoggingPlugin.getResourceString("LoggingPreferencePage.topLabel1");
|
||||||
topLabel1 = MessageFormat.format(topLabel1, new Object[] {bundleName});
|
topLabel1 = MessageFormat.format(topLabel1, new Object[] {bundleName});
|
||||||
Label label1 = createLabel(composite_tab, topLabel1);
|
createLabel(composite_tab, topLabel1);
|
||||||
forceSpace(composite_tab);
|
forceSpace(composite_tab);
|
||||||
String topLabel2 = RemoteSystemsLoggingPlugin.getResourceString("LoggingPreferencePage.topLabel2");
|
String topLabel2 = RemoteSystemsLoggingPlugin.getResourceString("LoggingPreferencePage.topLabel2");
|
||||||
Label label2 = createLabel(composite_tab, topLabel2);
|
createLabel(composite_tab, topLabel2);
|
||||||
tabForward(composite_tab);
|
tabForward(composite_tab);
|
||||||
Composite composite1_radioButton = createComposite(composite_tab, 1);
|
Composite composite1_radioButton = createComposite(composite_tab, 1);
|
||||||
String text = RemoteSystemsLoggingPlugin.getResourceString("LoggingPreferencePage.errors_only");
|
String text = RemoteSystemsLoggingPlugin.getResourceString("LoggingPreferencePage.errors_only");
|
||||||
|
@ -341,12 +341,10 @@ public abstract class LoggingPreferencePage extends PreferencePage implements IW
|
||||||
* This is needed to get to the plugin id, and then plugin instance.
|
* This is needed to get to the plugin id, and then plugin instance.
|
||||||
*/
|
*/
|
||||||
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
|
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
|
||||||
// we are assuming here that only AbstractUIPlugins will be used.
|
|
||||||
try {
|
try {
|
||||||
String nameSpace = config.getDeclaringExtension().getNamespace();
|
String pluginName = config.getDeclaringExtension().getContributor().getName();
|
||||||
this.bundle = Platform.getBundle(nameSpace);
|
this.bundle = Platform.getBundle(pluginName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// log error. plugin remains null.
|
|
||||||
RemoteSystemsLoggingPlugin.out.logError("Failed to create LoggingPreferencePage.", e);
|
RemoteSystemsLoggingPlugin.out.logError("Failed to create LoggingPreferencePage.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,18 @@ import java.net.URL;
|
||||||
import java.util.PropertyResourceBundle;
|
import java.util.PropertyResourceBundle;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.FileLocator;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
import org.eclipse.core.runtime.Preferences;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote Systems Logging plugin.
|
* Remote Systems Logging plugin.
|
||||||
*/
|
*/
|
||||||
public class RemoteSystemsLoggingPlugin extends AbstractUIPlugin {
|
public class RemoteSystemsLoggingPlugin extends Plugin {
|
||||||
|
|
||||||
|
|
||||||
//The shared instance.
|
//The shared instance.
|
||||||
|
@ -83,7 +84,7 @@ public class RemoteSystemsLoggingPlugin extends AbstractUIPlugin {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IPath path = new Path("$nl$/RemoteSystemsLogging.properties");
|
IPath path = new Path("$nl$/RemoteSystemsLogging.properties");
|
||||||
URL url = Platform.find(getBundle(), path);
|
URL url = FileLocator.find(getBundle(), path, null);
|
||||||
resourceBundle = new PropertyResourceBundle(url.openStream());
|
resourceBundle = new PropertyResourceBundle(url.openStream());
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
resourceBundle = null;
|
resourceBundle = null;
|
||||||
|
@ -95,16 +96,12 @@ public class RemoteSystemsLoggingPlugin extends AbstractUIPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets default preference values. These values will be used
|
* Sets default preference values.
|
||||||
* until some preferences are actually set using Preference dialog.
|
|
||||||
*/
|
*/
|
||||||
public void initializeDefaultPreferences() {
|
public void initializeDefaultPreferences() {
|
||||||
getPreferenceStore().setDefault(
|
Preferences prefs = getPluginPreferences();
|
||||||
IRemoteSystemsLogging.DEBUG_LEVEL,
|
prefs.setDefault(IRemoteSystemsLogging.DEBUG_LEVEL, IRemoteSystemsLogging.LOG_ERROR);
|
||||||
IRemoteSystemsLogging.LOG_ERROR);
|
prefs.setDefault(IRemoteSystemsLogging.LOG_LOCATION, IRemoteSystemsLogging.LOG_TO_FILE);
|
||||||
getPreferenceStore().setDefault(
|
|
||||||
IRemoteSystemsLogging.LOG_LOCATION,
|
|
||||||
IRemoteSystemsLogging.LOG_TO_FILE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -94,6 +94,13 @@ public class PerformanceLogger
|
||||||
static boolean _initialized = false;
|
static boolean _initialized = false;
|
||||||
static HashMap perfLogRegistry = new HashMap();
|
static HashMap perfLogRegistry = new HashMap();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Static initializer to normalize this logger.
|
||||||
|
*/
|
||||||
|
static {
|
||||||
|
normalize();
|
||||||
|
}
|
||||||
|
|
||||||
static class StartData
|
static class StartData
|
||||||
{
|
{
|
||||||
long startTime = -1;
|
long startTime = -1;
|
||||||
|
@ -120,17 +127,6 @@ public class PerformanceLogger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PerformanceLogger(): class constructor
|
|
||||||
* @return
|
|
||||||
* - Normalization time generated
|
|
||||||
* - XML file for default component created
|
|
||||||
*/
|
|
||||||
private PerformanceLogger() {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* public static void enablePerformanceLogging(boolean enable) : enable performance logging
|
* public static void enablePerformanceLogging(boolean enable) : enable performance logging
|
||||||
* @param
|
* @param
|
||||||
|
@ -241,35 +237,28 @@ public class PerformanceLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* private void init() : method for class instance initialization.
|
* Set the normalization unit for this run.based on a standard method for class instance initialization.
|
||||||
* @return
|
* @return a string containing the unit.
|
||||||
* Normalization value generated
|
*/
|
||||||
|
public static String normalize() {
|
||||||
|
/*
|
||||||
|
* Execute some standard code and time it to generate our normalization interval.
|
||||||
|
* Return the value to attempt to make it is not optimized by the compiler.
|
||||||
*/
|
*/
|
||||||
private void init() {
|
|
||||||
if (samplingTime == -1) {
|
|
||||||
|
|
||||||
/*Set normalization values*/
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
/*Trying to make sure it is not optimized by the compiler? */
|
|
||||||
/* Excute some standard instruction sets, such that a reasonably elapsed time can be obtained */
|
|
||||||
double val = 0;
|
|
||||||
Double q = null;
|
Double q = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int n = 1000000;
|
int n = 1000000;
|
||||||
for ( i = 0; i < n; i++) { /* increment operation for 1000 times */
|
for ( i = 0; i < n; i++) {
|
||||||
Double dd = new Double(n);
|
Double dd = new Double(n);
|
||||||
Double dr = new Double(n+i);
|
Double dr = new Double(n+i);
|
||||||
q = new Double(dd.doubleValue() / dr.doubleValue());
|
q = new Double(dd.doubleValue() / dr.doubleValue());
|
||||||
}
|
}
|
||||||
val = q.doubleValue()/i;
|
double val = q.doubleValue() / i;
|
||||||
|
|
||||||
long stopTime = System.currentTimeMillis();
|
long stopTime = System.currentTimeMillis();
|
||||||
samplingTime = stopTime-startTime;
|
samplingTime = stopTime-startTime;
|
||||||
System.out.println("SystemPerformanceLogger::Normalization Elapsed time = " + samplingTime);
|
String result = "SystemPerformanceLogger::Normalization Elapsed time = " + samplingTime + " " + val;
|
||||||
}
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -495,7 +484,7 @@ public class PerformanceLogger
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(cd.XMLFile), "UTF8"));
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(cd.XMLFile), "UTF8"));
|
||||||
Element root = cd.doc.getDocumentElement();
|
cd.doc.getDocumentElement();
|
||||||
Element task = td.node;
|
Element task = td.node;
|
||||||
|
|
||||||
/* Construct Long class insatnce for string manipulation */
|
/* Construct Long class insatnce for string manipulation */
|
||||||
|
@ -658,19 +647,10 @@ public class PerformanceLogger
|
||||||
* os.version
|
* os.version
|
||||||
*/
|
*/
|
||||||
public static void listSystemProfile() {
|
public static void listSystemProfile() {
|
||||||
String java_version = System.getProperty("java.version");
|
|
||||||
System.out.println("java version : " + System.getProperty("java.version"));
|
System.out.println("java version : " + System.getProperty("java.version"));
|
||||||
String java_vm_version = System.getProperty("java.vm.version");
|
|
||||||
String java_class_version = System.getProperty("java.class.version");
|
|
||||||
String java_class_path = System.getProperty("java.class.path");
|
|
||||||
String java_library_path = System.getProperty("java.library.path");
|
|
||||||
String os_name = System.getProperty("os.name");
|
|
||||||
System.out.println("OS name : " + System.getProperty("os.name"));
|
System.out.println("OS name : " + System.getProperty("os.name"));
|
||||||
String os_version = System.getProperty("os.version");
|
|
||||||
System.out.println("OS version : " + System.getProperty("os.version"));
|
System.out.println("OS version : " + System.getProperty("os.version"));
|
||||||
String user_dir = System.getProperty("user.dir");
|
|
||||||
System.out.println("working dir : " + System.getProperty("user.dir"));
|
System.out.println("working dir : " + System.getProperty("user.dir"));
|
||||||
String home_dir = System.getProperty("home.dir");
|
|
||||||
System.out.println("home dir : " + System.getProperty("home.dir"));
|
System.out.println("home dir : " + System.getProperty("home.dir"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,8 +712,6 @@ public class PerformanceLogger
|
||||||
key = PerformanceLogger.register(key); // Expect error: already registered
|
key = PerformanceLogger.register(key); // Expect error: already registered
|
||||||
PerformanceLogger.deRegister(key);
|
PerformanceLogger.deRegister(key);
|
||||||
key = PerformanceLogger.register(key);
|
key = PerformanceLogger.register(key);
|
||||||
|
|
||||||
String val = "i = " + i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue