当前位置: 首页>>代码示例>>Java>>正文


Java Span.getStopTimeMillis方法代码示例

本文整理汇总了Java中org.htrace.Span.getStopTimeMillis方法的典型用法代码示例。如果您正苦于以下问题:Java Span.getStopTimeMillis方法的具体用法?Java Span.getStopTimeMillis怎么用?Java Span.getStopTimeMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.htrace.Span的用法示例。


在下文中一共展示了Span.getStopTimeMillis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWriteTraceHooks

import org.htrace.Span; //导入方法依赖的package包/类
@Test
public void testWriteTraceHooks() throws Exception {
  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testWriteTraceHooks", Sampler.ALWAYS);
  Path file = new Path("traceWriteTest.dat");
  FSDataOutputStream stream = dfs.create(file);

  for (int i = 0; i < 10; i++) {
    byte[] data = RandomStringUtils.randomAlphabetic(102400).getBytes();
    stream.write(data);
  }
  stream.hflush();
  stream.close();
  long endTime = System.currentTimeMillis();
  ts.close();

  String[] expectedSpanNames = {
    "testWriteTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.create",
    "org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ClientNamenodeProtocol.BlockingInterface.create",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.fsync",
    "org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ClientNamenodeProtocol.BlockingInterface.fsync",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.complete",
    "org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ClientNamenodeProtocol.BlockingInterface.complete",
    "DFSOutputStream",
    "OpWriteBlockProto",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.addBlock",
    "org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ClientNamenodeProtocol.BlockingInterface.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();
  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());
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:47,代码来源:TestTracing.java

示例2: testReadTraceHooks

import org.htrace.Span; //导入方法依赖的package包/类
@Test
public void testReadTraceHooks() throws Exception {
  String fileName = "traceReadTest.dat";
  Path filePath = new Path(fileName);

  // Create the file.
  FSDataOutputStream ostream = dfs.create(filePath);
  for (int i = 0; i < 50; i++) {
    byte[] data = RandomStringUtils.randomAlphabetic(10240).getBytes();
    ostream.write(data);
  }
  ostream.close();


  long startTime = System.currentTimeMillis();
  TraceScope ts = Trace.startSpan("testReadTraceHooks", Sampler.ALWAYS);
  FSDataInputStream istream = dfs.open(filePath, 10240);
  ByteBuffer buf = ByteBuffer.allocate(10240);

  int count = 0;
  try {
    while (istream.read(buf) > 0) {
      count += 1;
      buf.clear();
      istream.seek(istream.getPos() + 5);
    }
  } catch (IOException ioe) {
    // Ignore this it's probably a seek after eof.
  } finally {
    istream.close();
  }
  ts.getSpan().addTimelineAnnotation("count: " + count);
  long endTime = System.currentTimeMillis();
  ts.close();

  String[] expectedSpanNames = {
    "testReadTraceHooks",
    "org.apache.hadoop.hdfs.protocol.ClientProtocol.getBlockLocations",
    "org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos.ClientNamenodeProtocol.BlockingInterface.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());
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:60,代码来源:TestTracing.java


注:本文中的org.htrace.Span.getStopTimeMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。