org.apache.htrace.core.Tracer类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(297)

本文整理了Java中org.apache.htrace.core.Tracer类的一些代码示例,展示了Tracer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer类的具体详情如下:
包路径:org.apache.htrace.core.Tracer
类名称:Tracer

Tracer介绍

[英]Use a Tracer instance inside a 'process' to collect and distribute its trace Spans. Example processes are an HDFS DataNode or an HBase RegionServer. A Tracer instance is your one-stop shop for all things tracing.
[中]在“进程”中使用跟踪程序实例来收集和分发其跟踪范围。例如,HDFS数据节点或HBase RegionServer。Tracer实例是所有事物跟踪的一站式商店。

代码示例

代码示例来源:origin: apache/hbase

/**
 * Wrapper method to create new TraceScope with the given description
 * @return TraceScope or null when not tracing
 */
public static TraceScope createTrace(String description) {
 return (tracer == null) ? null : tracer.newScope(description);
}

代码示例来源:origin: apache/hbase

/**
 * Wrapper method to add timeline annotiation to current span with given message
 */
public static void addTimelineAnnotation(String msg) {
 Span span = Tracer.getCurrentSpan();
 if (span != null) {
  span.addTimelineAnnotation(msg);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

@VisibleForTesting
public static synchronized void clear() {
 if (instance == null) {
  return;
 }
 try {
  instance.close();
 } finally {
  instance = null;
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

LOG.debug("GroupCacheLoader - load.");
TraceScope scope = null;
Tracer tracer = Tracer.curThreadTracer();
if (tracer != null) {
 scope = tracer.newScope("Groups#fetchGroupList");
 scope.addKVAnnotation("user", user);

代码示例来源:origin: brianfrankcooper/YCSB

int opsDone;
try (final TraceScope span = tracer.newScope(CLIENT_WORKLOAD_SPAN)) {
  threads.put(new Thread(tracer.wrap(client, "ClientThread")), client);
 try (final TraceScope span = tracer.newScope(CLIENT_CLEANUP_SPAN)) {
 try (final TraceScope span = tracer.newScope(CLIENT_EXPORT_MEASUREMENTS_SPAN)) {
  exportMeasurements(props, opsDone, en - st);

代码示例来源:origin: org.apache.hadoop/hadoop-common

throw new UnknownCommandException();
  TraceScope scope = tracer.newScope(instance.getCommandName());
  if (scope.getSpan() != null) {
   String args = StringUtils.join(" ", argv);
tracer.close();
return exitCode;

代码示例来源:origin: apache/incubator-htrace

@Test
public void TestSimpleScope() throws Exception {
 Tracer tracer = new Tracer.Builder().
   name("TestSimpleScope").
   tracerPool(new TracerPool("TestSimpleScope")).
   conf(HTraceConfiguration.fromKeyValuePairs(
     "sampler.classes", "AlwaysSampler")).
   build();
 POJOSpanReceiver receiver =
   new POJOSpanReceiver(HTraceConfiguration.EMPTY);
 tracer.getTracerPool().addReceiver(receiver);
 TraceScope scope = tracer.newScope("Foo");
 scope.close();
 tracer.close();
 Assert.assertEquals(1, receiver.getSpans().size());
 Span span = receiver.getSpans().iterator().next();
 Assert.assertEquals(0, span.getParents().length);
}

代码示例来源:origin: apache/incubator-htrace

conf(new HBaseHTraceConfiguration(HBaseConfiguration.create())).
  build();
tracer.addSampler(Sampler.ALWAYS);
TraceScope parent = tracer.newScope("HBaseSpanReceiver.main.parent");
Thread.sleep(10);
long traceid = parent.getSpan().getSpanId().getHigh();
TraceScope child1 = tracer.newScope("HBaseSpanReceiver.main.child.1");
Thread.sleep(10);
child1.close();
TraceScope child2 = tracer.newScope("HBaseSpanReceiver.main.child.2");
Thread.sleep(10);
TraceScope gchild = tracer.newScope("HBaseSpanReceiver.main.grandchild");
gchild.addTimelineAnnotation("annotation 1.");
Thread.sleep(10);
Thread.sleep(10);
parent.close();
tracer.close();
System.out.println("trace id: " + traceid);

代码示例来源:origin: apache/incubator-htrace

final ThreadFactory tf = new NamingThreadFactory();
ses = Executors.newScheduledThreadPool(TASK_COUNT, tf);
ses = tracer.newTraceExecutorService(ses);
try (TraceScope scope = tracer.newScope("TestRunnable")) {
 Collection<Future<String>> futures = new ArrayList<>();
   Tracer.getCurrentSpan().getTimelineAnnotations().isEmpty());
 assertEquals("Duplicated child span descriptions.", TASK_COUNT,
   results.size());

代码示例来源:origin: apache/hbase

/**
  * Wrap runnable with current tracer and description
  * @param runnable to wrap
  * @return wrapped runnable or original runnable when not tracing
  */
 public static Runnable wrap(Runnable runnable, String description) {
  return (tracer == null) ? runnable : tracer.wrap(runnable, description);
 }
}

代码示例来源:origin: apache/hbase

SingleServerRequestRunnable runnable = createSingleServerRequest(
    multiAction, numAttempt, server, callsInProgress);
Tracer tracer = Tracer.curThreadTracer();
 return Collections.singletonList(tracer.wrap(runnable, "AsyncProcess.sendMultiAction"));

代码示例来源:origin: apache/incubator-htrace

private List<SpanReceiver> createSpanReceivers(String classes) {
 Tracer tracer = new Tracer.Builder().
   name("MyTracer").
   tracerPool(new TracerPool("createSpanReceivers")).
   conf(HTraceConfiguration.fromKeyValuePairs(
     "span.receiver.classes", classes)).
   build();
 SpanReceiver[] receivers = tracer.getTracerPool().getReceivers();
 tracer.close();
 LinkedList<SpanReceiver> receiverList = new LinkedList<SpanReceiver>();
 for (SpanReceiver item: receivers) {
  receiverList.add(item);
 }
 return receiverList;
}

代码示例来源:origin: apache/incubator-htrace

private Sampler[] getSamplersFromConf(HTraceConfiguration conf) {
 Tracer tracer = new Tracer.Builder().
   name("MyTracer").
   tracerPool(new TracerPool("getSamplersFromConf")).
   conf(conf).
   build();
 Sampler[] samplers = tracer.getSamplers();
 tracer.close();
 return samplers;
}

代码示例来源:origin: apache/hbase

/**
 * Wrapper method to remove receiver from actual tracerpool
 * @return true if removed, false if doesn't exist
 */
public static boolean removeReceiver(SpanReceiver rcvr) {
 return (tracer == null) ? false : tracer.getTracerPool().removeReceiver(rcvr);
}

代码示例来源:origin: apache/hbase

/**
 * Wrapper method to add new sampler to the default tracer
 * @return true if added, false if it was already added
 */
public static boolean addSampler(Sampler sampler) {
 if (sampler == null) {
  return false;
 }
 return (tracer == null) ? false : tracer.addSampler(sampler);
}

代码示例来源:origin: io.hops/hadoop-common

throw new UnknownCommandException();
  TraceScope scope = tracer.newScope(instance.getCommandName());
  if (scope.getSpan() != null) {
   String args = StringUtils.join(" ", argv);
tracer.close();
return exitCode;

代码示例来源:origin: org.apache.hadoop/hadoop-common

@Override
public Object invoke(Object proxy, Method method, Object[] args)
 throws Throwable {
 long startTime = 0;
 if (LOG.isDebugEnabled()) {
  startTime = Time.monotonicNow();
 }
 // if Tracing is on then start a new span for this rpc.
 // guard it in the if statement to make sure there isn't
 // any extra string manipulation.
 Tracer tracer = Tracer.curThreadTracer();
 TraceScope traceScope = null;
 if (tracer != null) {
  traceScope = tracer.newScope(RpcClientUtil.methodToTraceString(method));
 }
 ObjectWritable value;
 try {
  value = (ObjectWritable)
   client.call(RPC.RpcKind.RPC_WRITABLE, new Invocation(method, args),
    remoteId, fallbackToSimpleAuth);
 } finally {
  if (traceScope != null) traceScope.close();
 }
 if (LOG.isDebugEnabled()) {
  long callTime = Time.monotonicNow() - startTime;
  LOG.debug("Call: " + method.getName() + " " + callTime);
 }
 return value.get();
}

代码示例来源:origin: apache/incubator-htrace

POJOSpanReceiver receiver =
  new POJOSpanReceiver(HTraceConfiguration.EMPTY);
tracer.getTracerPool().addReceiver(receiver);
final ScopeHolder scopeHolder = new ScopeHolder();
Thread th = new Thread(new Runnable() {
TraceScope nested = tracer.newScope("nested");
nested.close();
TraceScope nested2 = tracer.newScope("nested2");
nested2.close();
TraceScope lateChildScope = tracer.newScope("lateChild", workerScopeId);
lateChildScope.close();
tracer.close();

代码示例来源:origin: apache/incubator-htrace

/**
 * Creates the demo trace (will create different traces from call to call).
 */
public void createThreadedTrace() {
 try (TraceScope s = tracer.newScope(THREADED_TRACE_ROOT)) {
  Random r = ThreadLocalRandom.current();
  int numThreads = r.nextInt(4) + 1;
  Thread[] threads = new Thread[numThreads];
  for (int i = 0; i < numThreads; i++) {
   threads[i] = new Thread(tracer.wrap(new MyRunnable(), null));
  }
  for (int i = 0; i < numThreads; i++) {
   threads[i].start();
  }
  for (int i = 0; i < numThreads; i++) {
   try {
    threads[i].join();
   } catch (InterruptedException e) {
   }
  }
  importantWork1();
 }
}

代码示例来源:origin: org.apache.hbase/hbase-common

/**
  * Wrap runnable with current tracer and description
  * @param runnable to wrap
  * @return wrapped runnable or original runnable when not tracing
  */
 public static Runnable wrap(Runnable runnable, String description) {
  return (tracer == null) ? runnable : tracer.wrap(runnable, description);
 }
}

相关文章