Example #1
0
  public static Stats analyze(
      InputStream eventStream, long startTimestamp, EventMetadata eventMetadata)
      throws IOException {
    Stats stats = new Stats();

    stats.setEventMetadata(eventMetadata);

    stats.setStartTimestamp(startTimestamp);

    stats.computeStats(eventStream);

    return stats;
  }
Example #2
0
  public static void main(String[] args) {
    Options options = new Options();

    options.addOption(
        Option.builder(OPTION_PERCENTILE).hasArg().type(Float.class).required().build());
    options.addOption(Option.builder(OPTION_IN_FILE).hasArg().build());
    options.addOption(Option.builder(OPTION_START_OFFSET).required(false).hasArg().build());
    options.addOption(Option.builder(OPTION_USE_CASE).required(false).hasArg().build());
    options.addOption(Option.builder(OPTION_DUMP_LOG).hasArg().build());

    try {
      CommandLineParser clParser = new DefaultParser();
      CommandLine cmd = clParser.parse(options, args);

      float percentile = Float.parseFloat(cmd.getOptionValue(OPTION_PERCENTILE));

      if (percentile <= 0 || percentile > 1) {
        throw new ParseException("Percentile value must be within (0,1]");
      }

      long startOffset =
          cmd.hasOption(OPTION_START_OFFSET)
              ? Long.valueOf(cmd.getOptionValue(OPTION_START_OFFSET))
              : 0;

      InputStream in = null;

      if (cmd.hasOption(OPTION_IN_FILE)) {
        String path = cmd.getOptionValue(OPTION_IN_FILE);
        in = new FileInputStream(path);
      } else {
        in = System.in;
      }

      EventMetadata eventMetadata;

      if (cmd.hasOption(OPTION_USE_CASE) && cmd.getOptionValue(OPTION_USE_CASE).equals("traffic")) {
        eventMetadata = new TrafficEventMetadata();
      } else {
        eventMetadata = new CCFEventMetadata();
      }

      Stats stats = Stats.analyze(in, startOffset, eventMetadata);

      System.out.println(
          String.format(
              "%.1f%% End-to-end latency: %d ms", percentile * 100, stats.getLatency(percentile)));
      System.out.println(
          String.format(
              "%.1f%% Processing latency: %d ms",
              percentile * 100, stats.getProcessingLatency(percentile)));

      System.out.println(
          String.format("%.1f%% End-to-end latencies per event type:", percentile * 100));
      for (String type : stats.e2eLatenciesPerType.keySet()) {
        System.out.println(
            String.format("%s: %d ms", type, stats.getPerTypeLatency(type, percentile)));
      }
      System.out.println(
          String.format(
              "%.1f%% Input phase latency: %d ms",
              percentile * 100, stats.getInLatency(percentile)));
      System.out.println(
          String.format(
              "%.1f%% Output phase latency: %d ms",
              percentile * 100, stats.getOutLatency(percentile)));
      System.out.println(
          String.format(
              "Num of input events: %d, average rate: %f events/sec",
              stats.numOfInEvents, stats.getAvgInRate()));

      if (cmd.hasOption(OPTION_DUMP_LOG)) {
        String path = cmd.getOptionValue(OPTION_DUMP_LOG);
        stats.dumpLog(path, true);
      }

    } catch (ParseException pe) {
      System.err.println(pe.getMessage());
      System.err.println(USAGE);
      System.exit(1);
    } catch (IOException ioe) {
      System.out.println(ioe.getMessage());
      System.exit(1);
    }
  }