- Timestamp:
- 08/11/13 20:21:27 (9 years ago)
- Location:
- Tests/JAVA/test/src/main/java/com/db
- Files:
-
- 14 added
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
Tests/JAVA/test/src/main/java/com/db/chronos/api/Profiler.java
r572 r580 1 package test.threads.metrics.profiler;1 package com.db.chronos.api; 2 2 3 3 /** … … 51 51 * </pre> 52 52 * <p/> 53 * You must <b>always</b> finish profiling record with {@link Profiler.Record#now()},54 * {@link Profiler.Record#atMillis(long)} or {@linkProfiler.Record#atNanos(long)}53 * You must <b>always</b> finish profiling record with {@link com.db.chronos.api.Profiler.Record#now()}, 54 * {@link com.db.chronos.api.Profiler.Record#atMillis(long)} or {@link com.db.chronos.api.Profiler.Record#atNanos(long)} 55 55 * -- it is the point there record is actually made visible to reporter. This also means 56 * you should call {@link Profiler.Record#now()}/... as soon as possible, as it can56 * you should call {@link com.db.chronos.api.Profiler.Record#now()}/... as soon as possible, as it can 57 57 * stop pipeline 58 58 * <p/> 59 * You should <b>not</b> store {@link Record} instances for later use. After calling60 * {@link Profiler.Record#now()}/... record should <b>not</b> be read nor modified in61 * any way.59 * You should <b>not</b> store {@linkplain Record} instances for later use. After 60 * calling {@linkplain com.db.chronos.api.Profiler.Record#now()}/... record should 61 * <b>not</b> be read nor modified in any way. 62 62 * <p/> 63 63 * … … 65 65 * created 7/3/12 at 6:05 PM 66 66 */ 67 public interface Profiler <ControlPointEnum extends Enum<ControlPointEnum>>{67 public interface Profiler { 68 68 69 public Record <ControlPointEnum>event();69 public Record event(); 70 70 71 public Record <ControlPointEnum>event( final long id );71 public Record event( final long id ); 72 72 73 public interface Record <ControlPointEnum extends Enum<ControlPointEnum>>{73 public interface Record { 74 74 public static final int INVALID_EVENT_ID = -1; 75 75 76 public long id();77 76 78 public Record <ControlPointEnum> tag( final Object tag);77 public Record derivedFrom( final long parentId ); 79 78 80 public Record<ControlPointEnum> tags( final Object tag1, 81 final Object tag2 ); 79 public Record passedBy( final long whereId ); 82 80 83 public Record<ControlPointEnum> tags( final Object tag1, 84 final Object tag2, 85 final Object tag3 ); 81 public Record withLong( final int index, 82 final long data ); 86 83 87 public Record<ControlPointEnum> passedBy( final ControlPointEnum controlPoint ); 88 89 /** @return packetId of current record */ 84 /** @return eventId of current record */ 90 85 public long atNanos( final long timeNanos ); 91 86 92 /** @return packetId of current record */87 /** @return eventId of current record */ 93 88 public long atMillis( final long timeMillis ); 94 89 95 /** @return packetId of current record */90 /** @return eventId of current record */ 96 91 public long now(); 97 92 -
Tests/JAVA/test/src/main/java/com/db/chronos/api/impl/DemultiplexingBuffer.java
r572 r580 1 package test.threads.demultiplexor;1 package com.db.chronos.api.impl; 2 2 3 3 import java.util.concurrent.atomic.AtomicLongFieldUpdater; -
Tests/JAVA/test/src/main/java/com/db/chronos/api/impl/ProfilerImpl.java
r572 r580 1 package test.threads.metrics.profiler;1 package com.db.chronos.api.impl; 2 2 3 3 import java.util.concurrent.ScheduledExecutorService; … … 6 6 import java.util.concurrent.atomic.AtomicLong; 7 7 8 import com.db.chronos.api.Profiler; 8 9 import gnu.trove.TObjectProcedure; 9 10 import org.apache.commons.logging.Log; … … 17 18 * created 7/3/12 at 6:12 PM 18 19 */ 19 public class ProfilerImpl <ControlPointEnum extends Enum<ControlPointEnum>>20 implements Profiler <ControlPointEnum>, RecordImpl.RecordHandler {20 public class ProfilerImpl 21 implements Profiler, RecordImpl.RecordHandler { 21 22 private static final Log log = LogFactory.getLog( ProfilerImpl.class ); 22 23 23 24 private final AtomicLong idGenerator = new AtomicLong( 0 ); 24 25 25 private final TimingRecordsBuffer <ControlPointEnum>buffer;26 private final TimingRecordsBuffer buffer; 26 27 27 private final Reporter <ControlPointEnum>reporter;28 private final Reporter reporter; 28 29 private final ScheduledExecutorService scheduler; 29 30 … … 37 38 final int maxTagsCount, 38 39 final ITimestampSource timestampSource, 39 final Reporter <ControlPointEnum>reporter,40 final Reporter reporter, 40 41 final ScheduledExecutorService scheduler, 41 42 final long reportingPeriodInSeconds ) { … … 47 48 checkArgument( reporter != null, "reporter can't be null" ); 48 49 49 buffer = new TimingRecordsBuffer <ControlPointEnum>(50 buffer = new TimingRecordsBuffer( 50 51 bufferSize, 51 new RecordImpl.RecordImplFactory <ControlPointEnum>( this, maxTagsCount )52 new RecordImpl.RecordImplFactory( this, maxTagsCount ) 52 53 ); 53 54 this.maxTagsCount = maxTagsCount; 55 //TODO use dedicated thread instead of scheduler, for precise threading model 56 //and detailed control over timings 54 57 this.scheduler = scheduler; 55 58 this.reporter = reporter; … … 66 69 @Override 67 70 public void run() { 68 final Reporter <ControlPointEnum>reporter = ProfilerImpl.this.reporter;71 final Reporter reporter = ProfilerImpl.this.reporter; 69 72 try { 70 73 reporter.reportStarting(); 71 buffer.drainTo( new TObjectProcedure<RecordImpl <ControlPointEnum>>() {74 buffer.drainTo( new TObjectProcedure<RecordImpl>() { 72 75 @Override 73 public boolean execute( final RecordImpl <ControlPointEnum>record ) {76 public boolean execute( final RecordImpl record ) { 74 77 reporter.append( 75 78 record.id(), 76 record. controlPoint,77 record. tags,78 record.t agsCount,79 record.t imestampNanos79 record.parentId, 80 record.whereId, 81 record.timestampNanos, 82 record.tags 80 83 ); 81 84 return true; … … 105 108 106 109 @Override 107 public Record <ControlPointEnum>event() {110 public Record event() { 108 111 return event( Record.INVALID_EVENT_ID ); 109 112 } 110 113 111 114 @Override 112 public Record <ControlPointEnum>event( final long id ) {115 public Record event( final long id ) { 113 116 return buffer.eventWithID( id ); 114 117 } … … 124 127 } 125 128 126 public interface Reporter <ControlPointEnum extends Enum<ControlPointEnum>>{129 public interface Reporter { 127 130 public void reportStarting(); 128 131 129 132 public void append( final long eventId, 130 final ControlPointEnum passedBy,131 final Object[] tags,132 final int tagsCount,133 final long timestampNanos );133 final long parentId, 134 final long whereId, 135 final long timestampNanos, 136 final long[] tags ); 134 137 135 138 public void reportFinished(); -
Tests/JAVA/test/src/main/java/com/db/chronos/api/impl/ProfilerMock.java
r572 r580 1 package test.threads.metrics.profiler; 1 package com.db.chronos.api.impl; 2 3 import com.db.chronos.api.Profiler; 2 4 3 5 /** 4 * Mock implementation of LatencyProfiler. Do no record any data.6 * Mock implementation of {@linkplain com.db.chronos.api.Profiler}. Do no record any data. 5 7 * 6 8 * @author cherrus 7 9 * created 7/3/12 at 6:12 PM 8 10 */ 9 public class ProfilerMock <ControlPointEnum extends Enum<ControlPointEnum>> implements Profiler<ControlPointEnum>{11 public class ProfilerMock implements Profiler { 10 12 11 13 public static final ProfilerMock INSTANCE = new ProfilerMock(); 12 14 13 p ublicProfilerMock() {15 private ProfilerMock() { 14 16 } 15 17 16 18 @Override 17 public Record <ControlPointEnum>event() {19 public Record event() { 18 20 return event( -1 ); 19 21 } 20 22 21 23 @Override 22 public Record <ControlPointEnum>event( final long id ) {24 public Record event( final long id ) { 23 25 return FAKE_RECORD; 24 26 } 25 27 26 28 /** 27 * We do not use {@link TimingRecordsBuffer#FAKE_RECORD} 'cos we try to have28 * only one implementation of {@link Record} interface for each {@linkProfiler}29 * We do not use {@link test.threads.metrics.profiler.TimingRecordsBuffer#FAKE_RECORD} 'cos we try to have 30 * only one implementation of {@link com.db.chronos.api.Profiler.Record} interface for each {@link com.db.chronos.api.Profiler} 29 31 * implementation. It will be more optimal then only one implementation is 30 32 * actually in use in one JVM instance, since virtual calls will be monomorphic … … 32 34 */ 33 35 private static final Record FAKE_RECORD = new Record() { 34 @Override35 public long id() {36 return INVALID_EVENT_ID;37 }38 36 39 37 @Override 40 public Record tag( final Object tag) {38 public Record derivedFrom( final long parentId ) { 41 39 return this; 42 40 } 43 41 44 42 @Override 45 public Record tags( final Object tag1, 46 final Object tag2 ) { 43 public Record passedBy( final long whereId ) { 47 44 return this; 48 45 } 49 46 50 47 @Override 51 public Record tags( final Object tag1, 52 final Object tag2, 53 final Object tag3 ) { 54 return this; 55 } 56 57 @Override 58 public Record passedBy( final Enum controlPoint ) { 48 public Record withLong( final int index, 49 final long data ) { 59 50 return this; 60 51 } … … 62 53 @Override 63 54 public long atNanos( final long timeNanos ) { 64 return id();55 return INVALID_EVENT_ID; 65 56 } 66 57 67 58 @Override 68 59 public long atMillis( final long timeMillis ) { 69 return id();60 return INVALID_EVENT_ID; 70 61 } 71 62 72 63 @Override 73 64 public long now() { 74 return id();65 return INVALID_EVENT_ID; 75 66 } 76 67 -
Tests/JAVA/test/src/main/java/com/db/chronos/api/impl/ProfilerSpringBean.java
r572 r580 1 package test.threads.metrics.profiler;1 package com.db.chronos.api.impl; 2 2 3 3 import java.util.concurrent.ScheduledExecutorService; 4 4 5 import com.db.chronos.api.Profiler; 5 6 import org.springframework.beans.factory.config.AbstractFactoryBean; 6 7 import test.threads.metrics.timesource.ITimestampSource; … … 11 12 12 13 /** 13 * Spring factory bean for simplifying spring-based configuration of {@link Profiler}14 * Spring factory bean for simplifying spring-based configuration of {@link com.db.chronos.api.Profiler} 14 15 * instances 15 16 * … … 32 33 ); 33 34 34 private volatile ProfilerImpl.Reporter reporter = new SimpleLatencyReporter( 35 LatencyControlPoints.class 36 ); 37 35 private volatile ProfilerImpl.Reporter reporter = null; 38 36 39 37 @Override … … 53 51 54 52 @Override 55 protected ObjectcreateInstance() throws Exception {53 protected Profiler createInstance() throws Exception { 56 54 if( enable ) { 57 55 checkState( bufferSize > 0, "bufferSize(%s) must be > 0", bufferSize ); -
Tests/JAVA/test/src/main/java/com/db/chronos/api/impl/RecordImpl.java
r572 r580 1 package test.threads.metrics.profiler;1 package com.db.chronos.api.impl; 2 2 3 3 import java.util.*; … … 5 5 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; 6 6 7 import com.db.chronos.api.Profiler; 7 8 import com.google.common.base.Supplier; 8 9 import test.threads.metrics.timesource.ITimestampSource; … … 14 15 * created 7/4/12 at 5:44 PM 15 16 */ 16 class RecordImpl <ControlPointEnum extends Enum<ControlPointEnum>> implements Profiler.Record<ControlPointEnum>{17 class RecordImpl implements Profiler.Record { 17 18 private static final AtomicIntegerFieldUpdater<RecordImpl> doneUpdater = AtomicIntegerFieldUpdater.newUpdater( 18 19 RecordImpl.class, … … 20 21 ); 21 22 22 private static final Object[] EMPTY_ARRAY = new Object[0];23 private static final long[] EMPTY_ARRAY = new long[0]; 23 24 24 25 private static final int DONE = 1; … … 28 29 29 30 protected long eventId = -1; 30 31 protected long parentId = -1; 32 protected long whereId = -1; 31 33 protected long timestampNanos = -1; 32 34 33 protected final Object[] tags; 34 protected int tagsCount = 0; 35 36 protected ControlPointEnum controlPoint; 35 protected final long[] tags; 37 36 38 37 private volatile int done = 0; … … 43 42 this.handler = handler; 44 43 if( tagsCount > 0 ) { 45 tags = new Object[tagsCount];44 tags = new long[tagsCount]; 46 45 } else { 47 46 tags = EMPTY_ARRAY; … … 57 56 } 58 57 59 @Override60 58 public long id() { 61 59 if( isValid() ) { … … 67 65 68 66 @Override 69 public RecordImpl<ControlPointEnum> tag( final Object tag) {67 public Profiler.Record derivedFrom( final long parentId ) { 70 68 if( isValid() ) { 71 if( tagsCount < tags.length ) { 72 tags[tagsCount] = tag; 73 tagsCount++; 74 } else { 75 //TODO RC minor: log.debug("...") 76 } 69 this.parentId = parentId; 77 70 } 78 71 return this; … … 80 73 81 74 @Override 82 public RecordImpl<ControlPointEnum> tags( final Object tag1, 83 final Object tag2 ) { 84 return tag( tag1 ) 85 .tag( tag2 ); 75 public Profiler.Record passedBy( final long whereId ) { 76 if( isValid() ) { 77 this.whereId = whereId; 78 } 79 return this; 86 80 } 87 81 88 82 @Override 89 public RecordImpl<ControlPointEnum> tags( final Object tag1, 90 final Object tag2, 91 final Object tag3 ) { 92 return tag( tag1 ) 93 .tag( tag2 ) 94 .tag( tag3 ); 95 } 96 97 @Override 98 public RecordImpl<ControlPointEnum> passedBy( final ControlPointEnum controlPoint ) { 83 public Profiler.Record withLong( final int index, 84 final long data ) { 99 85 if( isValid() ) { 100 this. controlPoint = controlPoint;86 this.tags[index] = data; 101 87 } 102 88 return this; 103 89 } 90 104 91 105 92 @Override … … 124 111 125 112 protected void reset() { 126 tagsCount = 0;127 Arrays.fill( tags, null );//for GC?113 eventId = INVALID_EVENT_ID; 114 Arrays.fill( tags, 0 ); 128 115 129 116 doneUpdater.lazySet( this, NOT_DONE ); … … 143 130 @Override 144 131 public boolean isValid() { 145 //TODO RC: use handler==null instead of eventId == -1,146 //TODO RC: and use eventId==-1 as flag "ID needs to be generated on .end()"147 // return eventId != INVALID_EVENT_ID;148 132 return handler != null; 149 133 } … … 156 140 public String toString() { 157 141 return String.format( 158 "%s[#%d @ %d ns; %s : %s, done:%b]",142 "%s[#%d @%d (%d) at %d ns; {%s}, done:%b]", 159 143 getClass().getSimpleName(), 160 144 id(), 145 whereId, 146 parentId, 161 147 timestampNanos, 162 148 Arrays.toString( tags ), 163 controlPoint,164 149 isDone() 165 150 ); 166 151 } 167 152 168 public static class RecordImplFactory <CPE extends Enum<CPE>> implements Supplier<RecordImpl<CPE>> {153 public static class RecordImplFactory implements Supplier<RecordImpl> { 169 154 170 155 private final int maxTagsCount; … … 180 165 181 166 @Override 182 public RecordImpl <CPE>get() {183 return new RecordImpl <CPE>( handler, maxTagsCount );167 public RecordImpl get() { 168 return new RecordImpl( handler, maxTagsCount ); 184 169 } 185 170 } -
Tests/JAVA/test/src/main/java/com/db/chronos/api/impl/TimingRecordsBuffer.java
r572 r580 1 package test.threads.metrics.profiler;1 package com.db.chronos.api.impl; 2 2 3 3 import com.google.common.base.Supplier; … … 8 8 9 9 /** 10 * Wrap {@link DemultiplexingBuffer}, and adds:10 * Wrap {@link test.threads.demultiplexor.DemultiplexingBuffer}, and adds: 11 11 * <ol> 12 * <li>"done" flag management: {@link RecordImpl} does have volatile .done field,13 * which is set to true on {@link Profiler.Record#now()}12 * <li>"done" flag management: {@link test.threads.metrics.profiler.RecordImpl} does have volatile .done field, 13 * which is set to true on {@link com.db.chronos.api.Profiler.Record#now()} 14 14 * and resetted in {@link #drainTo(gnu.trove.TObjectProcedure)} 15 15 * </li> … … 22 22 * created 7/3/12 at 6:12 PM 23 23 */ 24 class TimingRecordsBuffer <ControlPointEnum extends Enum<ControlPointEnum>>{24 class TimingRecordsBuffer { 25 25 26 26 protected static final RecordImpl FAKE_RECORD = RecordImpl.createInvalid(); 27 27 28 private final DemultiplexingBuffer<RecordImpl <ControlPointEnum>> buffer;28 private final DemultiplexingBuffer<RecordImpl> buffer; 29 29 30 30 public TimingRecordsBuffer( final int bufferSize, 31 final Supplier<RecordImpl <ControlPointEnum>> recordFactory ) {31 final Supplier<RecordImpl> recordFactory ) { 32 32 checkArgument( bufferSize > 0, "bufferSize(%s) must be >0", bufferSize ); 33 buffer = new DemultiplexingBuffer<RecordImpl <ControlPointEnum>>(33 buffer = new DemultiplexingBuffer<RecordImpl>( 34 34 bufferSize, 35 35 recordFactory … … 37 37 } 38 38 39 public void drainTo( final TObjectProcedure<RecordImpl <ControlPointEnum>> processor ) {39 public void drainTo( final TObjectProcedure<RecordImpl> processor ) { 40 40 checkArgument( processor != null, "processor can't be null" ); 41 41 buffer.drainTo( 42 new TObjectProcedure<RecordImpl <ControlPointEnum>>() {42 new TObjectProcedure<RecordImpl>() { 43 43 @Override 44 public boolean execute( final RecordImpl <ControlPointEnum>record ) {44 public boolean execute( final RecordImpl record ) { 45 45 if( !record.isDone() ) { 46 46 return false; … … 57 57 58 58 59 public RecordImpl <ControlPointEnum>eventWithID( final long id ) {60 final RecordImpl <ControlPointEnum>record = buffer.nextAvailable();59 public RecordImpl eventWithID( final long id ) { 60 final RecordImpl record = buffer.nextAvailable(); 61 61 if( record == null ) { 62 62 return FAKE_RECORD;
Note: See TracChangeset
for help on using the changeset viewer.