當前位置: 首頁>>代碼示例>>Java>>正文


Java SimonManager.getStopwatch方法代碼示例

本文整理匯總了Java中org.javasimon.SimonManager.getStopwatch方法的典型用法代碼示例。如果您正苦於以下問題:Java SimonManager.getStopwatch方法的具體用法?Java SimonManager.getStopwatch怎麽用?Java SimonManager.getStopwatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.javasimon.SimonManager的用法示例。


在下文中一共展示了SimonManager.getStopwatch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findAndRunActiveJobs

import org.javasimon.SimonManager; //導入方法依賴的package包/類
public void findAndRunActiveJobs () {

		Stopwatch allStopWatch = SimonManager.getStopwatch( SERVICE_JOB_ID + "all.script.checkForActive" );
		Split allServicesSplit = allStopWatch.start();

		try {
			csapApplication.getActiveModel()
				.getServicesOnHost( Application.getHOST_NAME() )
				.filter( ServiceInstance::hasJobs )
				.flatMap( this::jobEntries )
				.forEach( jobEntry -> {
					jobRunnerService.submit( () -> runJob( jobEntry ) );
				} );
		} catch (Exception e) {
			logger.error( "Failed to schedule job", CSAP.getCsapFilteredStackTrace( e ) );
		}

		allServicesSplit.stop();
	}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:20,代碼來源:ServiceJobRunner.java

示例2: main

import org.javasimon.SimonManager; //導入方法依賴的package包/類
public static void main(String[] args) throws InterruptedException {
	String stopwatchName = "stopwatch";

	Split cpuSplit = Split.start(SimonClock.CPU);
	Split systemSplit = Split.start();

	System.out.println("cpuSplit = " + cpuSplit);
	System.out.println("systemSplit = " + systemSplit);

	for (int loop = 0; loop < 10; loop++) {
		for (int i = 0; i < 1000000; i++) {
			SimonManager.getStopwatch(stopwatchName);
		}
		Thread.sleep(200); // this should cause roughly 200 ms difference on each loop
		System.out.println("\nAfter iteration #" + loop);
		System.out.println("cpuSplit = " + cpuSplit);
		System.out.println("systemSplit = " + systemSplit);
	}
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:20,代碼來源:ClockExample.java

示例3: main

import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
 * Entry point to the JMX Callback Example.
 *
 * @param args unused
 * @throws Exception whatever may happen in this crazy world
 */
@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
	SimonManager.callback().addCallback(new JmxRegisterCallback("org.javasimon.examples.jmx.JmxCallbackExample"));

	Counter counter = SimonManager.getCounter("org.javasimon.examples.jmx.counter");
	Stopwatch stopwatch = SimonManager.getStopwatch("org.javasimon.examples.jmx.stopwatch");
	// these created just to have more stuff in jconsole
	SimonManager.getCounter("org.javasimon.different.counter");
	SimonManager.getStopwatch("org.javasimon.some.other.jmx.stopwatch1");
	SimonManager.getStopwatch("org.javasimon.some.other.jmx.stopwatch2");
	System.out.println("Now open jconsole and check it out...\nWatch org.javasimon.examples.jmx.stopwatch for changes.");
	while (true) {
		counter.increase();
		try (Split ignored = stopwatch.start()) {
			ExampleUtils.waitRandomlySquared(40);
		}
	}
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:25,代碼來源:JmxCallbackExample.java

示例4: main

import org.javasimon.SimonManager; //導入方法依賴的package包/類
public static void main(String... args) {
	List<Integer> circularList = new CircularList<>(10);
	Stopwatch stopwatch = SimonManager.getStopwatch(CircularListAddPerfromance.class.getName() + ".testAddPerformance");
	Split split = stopwatch.start();
	for (int i = 0; i < ITERATIONS; i++) {
		circularList.add(i);
	}
	long circular = split.stop().runningFor();
	LinkedList<Integer> linkedList = new LinkedList<>();
	split = stopwatch.start();
	for (int i = 0; i < ITERATIONS; i++) {
		linkedList.add(i);
		if (linkedList.size() > 10) {
			linkedList.removeFirst();
		}
	}
	long linked = split.stop().runningFor();
	System.out.println("Circular " + circular + " /Linked " + linked + " " + ((linked - circular) * 100 / circular) + "%");
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:20,代碼來源:CircularListAddPerfromance.java

示例5: execute

import org.javasimon.SimonManager; //導入方法依賴的package包/類
void execute() throws InterruptedException {
	Stopwatch stopwatch = SimonManager.getStopwatch(NAME);
	for (int i = 1; i <= threads; i++) {
		startTask();
		if (i % 500 == 0) {
			System.out.println("Created thread: " + i +
				" (already executed loops " + stopwatch.getCounter() +
				", currently active " + stopwatch.getActive() + ")");
		}
	}
	System.out.println("All threads created (already executed loops " + stopwatch.getCounter() +
		", currently active " + stopwatch.getActive() + ")");
	// here we wait for all threads to end
	latch.await();
	System.out.println("All threads finished: " + stopwatch.sample());
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:17,代碼來源:MultithreadedStopwatchLoad.java

示例6: managerClearTest

import org.javasimon.SimonManager; //導入方法依賴的package包/類
@Test
public void managerClearTest() throws MalformedObjectNameException {
	String counterName = "test.1";
	ObjectName counterObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.COUNTER + ",name=" + counterName);

	String stopwatchName = "test.2";
	ObjectName stopwatchObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.STOPWATCH + ",name=" + stopwatchName);

	Assert.assertFalse(mbs.isRegistered(counterObjectName));
	Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));

	SimonManager.getCounter(counterName);
	Assert.assertTrue(mbs.isRegistered(counterObjectName));

	SimonManager.getStopwatch(stopwatchName);
	Assert.assertTrue(mbs.isRegistered(stopwatchObjectName));

	SimonManager.clear();
	Assert.assertFalse(mbs.isRegistered(counterObjectName));
	Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:22,代碼來源:JmxRegistrationCallbackTest.java

示例7: destroySimonTest

import org.javasimon.SimonManager; //導入方法依賴的package包/類
@Test
public void destroySimonTest() throws MalformedObjectNameException {
	String counterName = "test.1";
	ObjectName counterObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.COUNTER + ",name=" + counterName);

	String stopwatchName = "test.2";
	ObjectName stopwatchObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.STOPWATCH + ",name=" + stopwatchName);

	Assert.assertFalse(mbs.isRegistered(counterObjectName));
	Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));

	SimonManager.getCounter(counterName);
	Assert.assertTrue(mbs.isRegistered(counterObjectName));
	SimonManager.destroySimon(counterName);
	Assert.assertFalse(mbs.isRegistered(counterObjectName));

	SimonManager.getStopwatch(stopwatchName);
	Assert.assertTrue(mbs.isRegistered(stopwatchObjectName));
	SimonManager.destroySimon(stopwatchName);
	Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:22,代碼來源:JmxRegistrationCallbackTest.java

示例8: handleProcessList

import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
 * Simple Wrapper so that we can block inside the method, and capture AOP
 * timings
 *
 * @param psResult
 * @param duResult
 */
private void handleProcessList ( String psResult, String duResult ) {

	// logger.info("Got here ========== ");
	Stopwatch stopwatch = SimonManager
		.getStopwatch( "java.OsManager.getProcessStats.parse" );

	Split split = stopwatch.start();
	synchronized (this) {
		handleProcessListSync( psResult, duResult );
	}
	split.stop();
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:20,代碼來源:OsManager.java

示例9: collect

import org.javasimon.SimonManager; //導入方法依賴的package包/類
public void collect () {
	// TODO Auto-generated method stub
	Stopwatch stopwatch = SimonManager
		.getStopwatch( "collector.http" );
	Split split = stopwatch.start();

	csapApplication
		.getActiveModel()
		.getServicesOnHost( Application.getHOST_NAME() )
		.filter( serviceInstance -> serviceInstance.hasHttpCollection() )
		.forEach( this::executeHttpCollection );

	split.stop();
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:15,代碼來源:HttpCollector.java

示例10: startSplit

import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
 * Starts the split for the SQL specific stopwatch, sets the note and returns the split.
 * Used in the statment and prepared statement classes to measure runs of "execute" methods.
 *
 * @return split for the execution of the specific SQL command
 */
protected Split startSplit() {
	Stopwatch stopwatch = SimonManager.getStopwatch(sqlCmdLabel + Manager.HIERARCHY_DELIMITER + sqlNormalizer.getNormalizedSql().hashCode());
	if (stopwatch.getNote() == null) {
		stopwatch.setNote(sqlNormalizer.getNormalizedSql());
	}
	return stopwatch.start();
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:14,代碼來源:SimonStatement.java

示例11: fillManagerWithSimons

import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
 * Fills the {@link org.javasimon.SimonManager} with specified number of Simons (or slightly more).
 *
 * @param roughCount how many Stopwatches to create (or a bit more)
 */
public static void fillManagerWithSimons(int roughCount) {
	System.out.print("Filling manager with ~" + roughCount + " Simons...");
	while (SimonManager.getSimonNames().size() < roughCount) {
		SimonManager.getStopwatch(generateRandomName(RANDOM.nextInt(10) + 1));
	}
	System.out.println(" " + SimonManager.getSimonNames().size() + " created.");
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:13,代碼來源:ExampleUtils.java

示例12: main

import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
 * Entry point of the example application.
 *
 * @param args command line arguments
 * @throws MalformedObjectNameException probably never
 */
public static void main(String[] args) throws MalformedObjectNameException {
	// We create some example Simons
	Stopwatch stopwatch = SimonManager.getStopwatch("org.javasimon.jmx.example1");
	Counter counter = SimonManager.getCounter("org.javasimon.jmx.example2");

	// Do little measurement for stopwatch Simon ...
	try (Split ignored = stopwatch.start()) {
		Thread.sleep(632);
	} catch (InterruptedException e) { /* do nothing */ }

	// ... and few usage of counter Simon.
	counter.increase(52);
	counter.decrease(12);
	counter.increase(18);

	// Than, we register provided SimonManagerMXBean.
	// SimonManagerMXBean is part of javasimon, but register method is client responsibility
	// so look to it for more detail.
	register();

	// The following is client part of code.
	// Because, this is same VM, we don't need to create JMXConnector object and
	// than obtain MBeanServerConnection. Platform MBeanServer is a MBeanServerConnection
	// already, so it's used.
	// So we use JMX.newMXBeanProxy method to make JMX create new client proxy of SimonManagerMXBean
	// for us.
	SimonManagerMXBean simonManagerMXBean = JMX.newMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
		new ObjectName("org.javasimon.jmx.example:type=Simon"), SimonManagerMXBean.class);

	// Now, we can freely retrieve samples for counter and stopwatch example Simons
	System.out.println("counter = " + simonManagerMXBean.getCounterSample("org.javasimon.jmx.example2"));
	System.out.println("stopwatch = " + simonManagerMXBean.getStopwatchSample("org.javasimon.jmx.example1"));

	// After all, it's good manner to clean up, so we unregister MXBean
	unregister();
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:43,代碼來源:StandaloneExample.java

示例13: main

import org.javasimon.SimonManager; //導入方法依賴的package包/類
public static void main(String... args) throws InterruptedException {
	Stopwatch existingStopwatch = SimonManager.getStopwatch("any.previously.ExistingStopwatch");
	// Create JMX reporter
	JmxReporter reporter = JmxReporter.forDefaultManager()
		.registerSimons() // add MBean for every Simon
		.registerExistingSimons() // register also already existing ones (ExistingStopwatch in this case)
		.start(); // this performs actual MXBean registration + JmxRegisterCallback is added to manager

	// "testStopwatch" can be accessed through JMX bean for manager and
	// through separate beans for this particular Simon
	Stopwatch stopwatch = SimonManager.manager().getStopwatch("testStopwatch");

	// Generate some metrics data that can be accessed through JMX
	Random random = new Random();
	// loop will finish when ExistingStopwatch is set to disabled
	// go to jconsole/jvisualvm, find MBean for ExistingStopwatch, go to Operations and call setState(DISABLED,true)
	while (existingStopwatch.isEnabled()) {
		try (Split ignored = stopwatch.start()) {
			Thread.sleep(random.nextInt(1000));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	reporter.stop();
	// this is here to give user some time to check, that all MBeans were unregistered
	Thread.sleep(10000);
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:29,代碼來源:JmxReporterExample.java

示例14: doTestPerformance

import org.javasimon.SimonManager; //導入方法依賴的package包/類
private static long doTestPerformance(MonitoredInterface monitoredInterface, int iterations) {
		Stopwatch stopwatch = SimonManager.getStopwatch(StopwatchProxyPerformance.class.getName() + ".testPerformance");
		Split split = stopwatch.start();

//		stopwatch.reset();
		for (int i = 0; i < iterations; i++) {
			monitoredInterface.welcome("world");
		}

		LOGGER.info(stopwatch.toString());
		return split.stop().runningFor();
	}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:13,代碼來源:StopwatchProxyPerformance.java

示例15: run

import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
 * Run method implementing the code performed by the thread.
 */
@Override
public void run() {
	Stopwatch stopwatch = SimonManager.getStopwatch(NAME);
	try (Split ignored = stopwatch.start();) {
		sleep(SLEEP);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	// signal to latch that the thread is finished
	latch.countDown();
}
 
開發者ID:virgo47,項目名稱:javasimon,代碼行數:15,代碼來源:MultithreadedSleeping.java


注:本文中的org.javasimon.SimonManager.getStopwatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。