Search in sources :

Example 1 with Tracer

use of org.apache.htrace.core.Tracer in project hadoop by apache.

the class FsShell method run.

/**
   * run
   */
@Override
public int run(String[] argv) throws Exception {
    // initialize FsShell
    init();
    Tracer tracer = new Tracer.Builder("FsShell").conf(TraceUtils.wrapHadoopConf(SHELL_HTRACE_PREFIX, getConf())).build();
    int exitCode = -1;
    if (argv.length < 1) {
        printUsage(System.err);
    } else {
        String cmd = argv[0];
        Command instance = null;
        try {
            instance = commandFactory.getInstance(cmd);
            if (instance == null) {
                throw new UnknownCommandException();
            }
            TraceScope scope = tracer.newScope(instance.getCommandName());
            if (scope.getSpan() != null) {
                String args = StringUtils.join(" ", argv);
                if (args.length() > 2048) {
                    args = args.substring(0, 2048);
                }
                scope.getSpan().addKVAnnotation("args", args);
            }
            try {
                exitCode = instance.run(Arrays.copyOfRange(argv, 1, argv.length));
            } finally {
                scope.close();
            }
        } catch (IllegalArgumentException e) {
            if (e.getMessage() == null) {
                displayError(cmd, "Null exception message");
                e.printStackTrace(System.err);
            } else {
                displayError(cmd, e.getLocalizedMessage());
            }
            printUsage(System.err);
            if (instance != null) {
                printInstanceUsage(System.err, instance);
            }
        } catch (Exception e) {
            // instance.run catches IOE, so something is REALLY wrong if here
            LOG.debug("Error", e);
            displayError(cmd, "Fatal internal error");
            e.printStackTrace(System.err);
        }
    }
    tracer.close();
    return exitCode;
}
Also used : Command(org.apache.hadoop.fs.shell.Command) FsCommand(org.apache.hadoop.fs.shell.FsCommand) Tracer(org.apache.htrace.core.Tracer) TraceScope(org.apache.htrace.core.TraceScope) IOException(java.io.IOException)

Example 2 with Tracer

use of org.apache.htrace.core.Tracer in project hadoop by apache.

the class FileSystem method createFileSystem.

/**
   * Create and initialize a new instance of a FileSystem.
   * @param uri URI containing the FS schema and FS details
   * @param conf configuration to use to look for the FS instance declaration
   * and to pass to the {@link FileSystem#initialize(URI, Configuration)}.
   * @return the initialized filesystem.
   * @throws IOException problems loading or initializing the FileSystem
   */
private static FileSystem createFileSystem(URI uri, Configuration conf) throws IOException {
    Tracer tracer = FsTracer.get(conf);
    try (TraceScope scope = tracer.newScope("FileSystem#createFileSystem")) {
        scope.addKVAnnotation("scheme", uri.getScheme());
        Class<?> clazz = getFileSystemClass(uri.getScheme(), conf);
        FileSystem fs = (FileSystem) ReflectionUtils.newInstance(clazz, conf);
        fs.initialize(uri, conf);
        return fs;
    }
}
Also used : Tracer(org.apache.htrace.core.Tracer) TraceScope(org.apache.htrace.core.TraceScope)

Example 3 with Tracer

use of org.apache.htrace.core.Tracer in project hadoop by apache.

the class TestTracing method testTracing.

@Test
public void testTracing() throws Exception {
    // write and read without tracing started
    String fileName = "testTracingDisabled.dat";
    writeTestFile(fileName);
    Assert.assertEquals(0, SetSpanReceiver.size());
    readTestFile(fileName);
    Assert.assertEquals(0, SetSpanReceiver.size());
    writeTestFile("testReadTraceHooks.dat");
    FsTracer.clear();
    Tracer tracer = FsTracer.get(TRACING_CONF);
    writeWithTracing(tracer);
    readWithTracing(tracer);
}
Also used : Tracer(org.apache.htrace.core.Tracer) FsTracer(org.apache.hadoop.fs.FsTracer) Test(org.junit.Test)

Example 4 with Tracer

use of org.apache.htrace.core.Tracer in project YCSB by brianfrankcooper.

the class Client method main.

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    Properties props = parseArguments(args);
    boolean status = Boolean.valueOf(props.getProperty(STATUS_PROPERTY, String.valueOf(false)));
    String label = props.getProperty(LABEL_PROPERTY, "");
    long maxExecutionTime = Integer.parseInt(props.getProperty(MAX_EXECUTION_TIME, "0"));
    //get number of threads, target and db
    int threadcount = Integer.parseInt(props.getProperty(THREAD_COUNT_PROPERTY, "1"));
    String dbname = props.getProperty(DB_PROPERTY, "com.yahoo.ycsb.BasicDB");
    int target = Integer.parseInt(props.getProperty(TARGET_PROPERTY, "0"));
    //compute the target throughput
    double targetperthreadperms = -1;
    if (target > 0) {
        double targetperthread = ((double) target) / ((double) threadcount);
        targetperthreadperms = targetperthread / 1000.0;
    }
    Thread warningthread = setupWarningThread();
    warningthread.start();
    Measurements.setProperties(props);
    Workload workload = getWorkload(props);
    final Tracer tracer = getTracer(props, workload);
    initWorkload(props, warningthread, workload, tracer);
    System.err.println("Starting test.");
    final CountDownLatch completeLatch = new CountDownLatch(threadcount);
    final List<ClientThread> clients = initDb(dbname, props, threadcount, targetperthreadperms, workload, tracer, completeLatch);
    if (status) {
        boolean standardstatus = false;
        if (props.getProperty(Measurements.MEASUREMENT_TYPE_PROPERTY, "").compareTo("timeseries") == 0) {
            standardstatus = true;
        }
        int statusIntervalSeconds = Integer.parseInt(props.getProperty("status.interval", "10"));
        boolean trackJVMStats = props.getProperty(Measurements.MEASUREMENT_TRACK_JVM_PROPERTY, Measurements.MEASUREMENT_TRACK_JVM_PROPERTY_DEFAULT).equals("true");
        statusthread = new StatusThread(completeLatch, clients, label, standardstatus, statusIntervalSeconds, trackJVMStats);
        statusthread.start();
    }
    Thread terminator = null;
    long st;
    long en;
    int opsDone;
    try (final TraceScope span = tracer.newScope(CLIENT_WORKLOAD_SPAN)) {
        final Map<Thread, ClientThread> threads = new HashMap<>(threadcount);
        for (ClientThread client : clients) {
            threads.put(new Thread(tracer.wrap(client, "ClientThread")), client);
        }
        st = System.currentTimeMillis();
        for (Thread t : threads.keySet()) {
            t.start();
        }
        if (maxExecutionTime > 0) {
            terminator = new TerminatorThread(maxExecutionTime, threads.keySet(), workload);
            terminator.start();
        }
        opsDone = 0;
        for (Map.Entry<Thread, ClientThread> entry : threads.entrySet()) {
            try {
                entry.getKey().join();
                opsDone += entry.getValue().getOpsDone();
            } catch (InterruptedException ignored) {
            // ignored
            }
        }
        en = System.currentTimeMillis();
    }
    try {
        try (final TraceScope span = tracer.newScope(CLIENT_CLEANUP_SPAN)) {
            if (terminator != null && !terminator.isInterrupted()) {
                terminator.interrupt();
            }
            if (status) {
                // wake up status thread if it's asleep
                statusthread.interrupt();
                // at this point we assume all the monitored threads are already gone as per above join loop.
                try {
                    statusthread.join();
                } catch (InterruptedException ignored) {
                // ignored
                }
            }
            workload.cleanup();
        }
    } catch (WorkloadException e) {
        e.printStackTrace();
        e.printStackTrace(System.out);
        System.exit(0);
    }
    try {
        try (final TraceScope span = tracer.newScope(CLIENT_EXPORT_MEASUREMENTS_SPAN)) {
            exportMeasurements(props, opsDone, en - st);
        }
    } catch (IOException e) {
        System.err.println("Could not export measurements, error: " + e.getMessage());
        e.printStackTrace();
        System.exit(-1);
    }
    System.exit(0);
}
Also used : Tracer(org.apache.htrace.core.Tracer) TraceScope(org.apache.htrace.core.TraceScope) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Tracer (org.apache.htrace.core.Tracer)4 TraceScope (org.apache.htrace.core.TraceScope)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 FsTracer (org.apache.hadoop.fs.FsTracer)1 Command (org.apache.hadoop.fs.shell.Command)1 FsCommand (org.apache.hadoop.fs.shell.FsCommand)1 Test (org.junit.Test)1