com.google.monitoring.runtime.instrumentation.Sampler Java Examples

The following examples show how to use com.google.monitoring.runtime.instrumentation.Sampler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestGarbageDefaultLoggerServiceImpl.java    From gflogger with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init(){

	final ThreadLocal<StringBuilder> local = new ThreadLocal<StringBuilder>(){
		@Override
		public StringBuilder get() {
			return new StringBuilder(1 << 10);
		}
	};

	final ThreadLocal<String> threadName = new ThreadLocal<String>(){
		@Override
		protected String initialValue() {
			return Thread.currentThread().getName();
		}
	};

	// pre init
	local.get();
	threadName.get();

	AllocationRecorder.addSampler(new Sampler() {

		@Override
		public void sampleAllocation(int count, String desc, Object newObj, long size) {
		  if (!objectCounting.get() ||
				  // bypass for gradle workers thread
				  threadName.get().contains("0.0.0.0:"))
		  	return;

		  objectCount.incrementAndGet();
		  objectSize.addAndGet(size);

		  objectCounting.getAndSet(false);
		  try {

			  final StringBuilder builder = local.get();
			  builder.setLength(0);
			  if (count != -1) {
				  builder.append("an array of ").
					append(newObj.getClass().getComponentType().getName()).
					append("[").append(count).append("]");
			  } else {
				  if (newObj instanceof String){
					  builder.append("allocated the string '").append(newObj).
						  append('\'');
					} else {
						builder.append("allocated the object ").append(newObj).
						append(" of type ").append(desc).append(" whose size is ").append(size);
					}
			  }
			  //builder.append(" [").append(threadName.get()).append(']');

			  if (!detailedAllocation.get()) return;
			  System.out.println(builder);
		  } finally {
			  objectCounting.set(true);
		  }
		  /*/
		  //*/
		}
	  });
	BasicConfigurator.configure();
	org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger("com.db.fxpricing.Logger");
}
 
Example #2
Source File: TestZODDefaultLoggerServiceImpl.java    From gflogger with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void init(){

	final ThreadLocal<StringBuilder> local = new ThreadLocal<StringBuilder>(){
		@Override
		public StringBuilder get() {
			return new StringBuilder(1 << 10);
		}
	};

	final ThreadLocal<String> threadName = new ThreadLocal<String>(){
		@Override
		protected String initialValue() {
			return Thread.currentThread().getName();
		}
	};

	// pre init
	local.get();
	threadName.get();

	AllocationRecorder.addSampler(new Sampler() {

		@Override
		public void sampleAllocation(int count, String desc, Object newObj, long size) {
		  if (!objectCounting.get()
				  ||
				  // bypass for gradle workers thread
				  threadName.get().contains("0.0.0.0:")
			  ) return;

		  objectCount.incrementAndGet();
		  objectSize.addAndGet(size);

		  final StringBuilder builder = local.get();
		  builder.setLength(0);
		  if (count != -1) {
			  builder.append("an array of ").
				append(newObj.getClass().getComponentType().getName()).
				append("[").append(count).append("]");
		  } else {
			  if (newObj instanceof String){
				  builder.append("just allocated the string '").append(newObj).
					  append('\'');
				} else {
					builder.append("I just allocated the object ").append(newObj).
					append(" of type ").append(desc).append(" whose size is ").append(size);
				}
		  }
		  builder.append('[').append(threadName.get()).append(']');

		  if (!detailedAllocation.get()) return;
		  System.err.println(builder);
		  /*/
		  //*/
		}
	  });
}