Java Code Examples for org.apache.htrace.Span#getStartTimeMillis()

The following examples show how to use org.apache.htrace.Span#getStartTimeMillis() . 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: TestTracing.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public void readWithTracing() throws Exception {
  String fileName = "testReadTraceHooks.dat";
  writeTestFile(fileName);
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testReadTraceHooks", Sampler.ALWAYS);
  readTestFile(fileName);
  ts.close();
  long endTime = System.currentTimeMillis();

  String[] expectedSpanNames = {
    "testReadTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations",
    "ClientNamenodeProtocol#getBlockLocations",
    "OpReadBlockProto"
  };
  assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
  Span s = map.get("testReadTraceHooks").get(0);
  Assert.assertNotNull(s);

  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();
  Assert.assertTrue(spanStart - startTime < 100);
  Assert.assertTrue(spanEnd - endTime < 100);

  // There should only be one trace id as it should all be homed in the
  // top trace.
  for (Span span : SetSpanReceiver.SetHolder.spans.values()) {
    Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
  }
  SetSpanReceiver.SetHolder.spans.clear();
}
 
Example 2
Source File: TestTracing.java    From big-c with Apache License 2.0 5 votes vote down vote up
public void readWithTracing() throws Exception {
  String fileName = "testReadTraceHooks.dat";
  writeTestFile(fileName);
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testReadTraceHooks", Sampler.ALWAYS);
  readTestFile(fileName);
  ts.close();
  long endTime = System.currentTimeMillis();

  String[] expectedSpanNames = {
    "testReadTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations",
    "ClientNamenodeProtocol#getBlockLocations",
    "OpReadBlockProto"
  };
  assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
  Span s = map.get("testReadTraceHooks").get(0);
  Assert.assertNotNull(s);

  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();
  Assert.assertTrue(spanStart - startTime < 100);
  Assert.assertTrue(spanEnd - endTime < 100);

  // There should only be one trace id as it should all be homed in the
  // top trace.
  for (Span span : SetSpanReceiver.SetHolder.spans.values()) {
    Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
  }
  SetSpanReceiver.SetHolder.spans.clear();
}
 
Example 3
Source File: TestTracing.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void writeWithTracing() throws Exception {
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testWriteTraceHooks", Sampler.ALWAYS);
  writeTestFile("testWriteTraceHooks.dat");
  long endTime = System.currentTimeMillis();
  ts.close();

  String[] expectedSpanNames = {
    "testWriteTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.create",
    "ClientNamenodeProtocol#create",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync",
    "ClientNamenodeProtocol#fsync",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete",
    "ClientNamenodeProtocol#complete",
    "newStreamForCreate",
    "DFSOutputStream#writeChunk",
    "DFSOutputStream#close",
    "dataStreamer",
    "OpWriteBlockProto",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.addBlock",
    "ClientNamenodeProtocol#addBlock"
  };
  assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
  Span s = map.get("testWriteTraceHooks").get(0);
  Assert.assertNotNull(s);
  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();

  // Spans homed in the top trace shoud have same trace id.
  // Spans having multiple parents (e.g. "dataStreamer" added by HDFS-7054)
  // and children of them are exception.
  String[] spansInTopTrace = {
    "testWriteTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.create",
    "ClientNamenodeProtocol#create",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync",
    "ClientNamenodeProtocol#fsync",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete",
    "ClientNamenodeProtocol#complete",
    "newStreamForCreate",
    "DFSOutputStream#writeChunk",
    "DFSOutputStream#close",
  };
  for (String desc : spansInTopTrace) {
    for (Span span : map.get(desc)) {
      Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
    }
  }
  SetSpanReceiver.SetHolder.spans.clear();
}
 
Example 4
Source File: TestTracing.java    From big-c with Apache License 2.0 4 votes vote down vote up
public void writeWithTracing() throws Exception {
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testWriteTraceHooks", Sampler.ALWAYS);
  writeTestFile("testWriteTraceHooks.dat");
  long endTime = System.currentTimeMillis();
  ts.close();

  String[] expectedSpanNames = {
    "testWriteTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.create",
    "ClientNamenodeProtocol#create",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync",
    "ClientNamenodeProtocol#fsync",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete",
    "ClientNamenodeProtocol#complete",
    "newStreamForCreate",
    "DFSOutputStream#writeChunk",
    "DFSOutputStream#close",
    "dataStreamer",
    "OpWriteBlockProto",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.addBlock",
    "ClientNamenodeProtocol#addBlock"
  };
  assertSpanNamesFound(expectedSpanNames);

  // The trace should last about the same amount of time as the test
  Map<String, List<Span>> map = SetSpanReceiver.SetHolder.getMap();
  Span s = map.get("testWriteTraceHooks").get(0);
  Assert.assertNotNull(s);
  long spanStart = s.getStartTimeMillis();
  long spanEnd = s.getStopTimeMillis();

  // Spans homed in the top trace shoud have same trace id.
  // Spans having multiple parents (e.g. "dataStreamer" added by HDFS-7054)
  // and children of them are exception.
  String[] spansInTopTrace = {
    "testWriteTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.create",
    "ClientNamenodeProtocol#create",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync",
    "ClientNamenodeProtocol#fsync",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete",
    "ClientNamenodeProtocol#complete",
    "newStreamForCreate",
    "DFSOutputStream#writeChunk",
    "DFSOutputStream#close",
  };
  for (String desc : spansInTopTrace) {
    for (Span span : map.get(desc)) {
      Assert.assertEquals(ts.getSpan().getTraceId(), span.getTraceId());
    }
  }
  SetSpanReceiver.SetHolder.spans.clear();
}