Package com.google.common.base

Examples of com.google.common.base.Stopwatch


   protected void createAndRunAServiceInGroup(String group) throws RunNodesException {
      // note that some cloud providers do not support mixed case tag names
      ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("test", group);
     
      ImmutableSet<String> tags = ImmutableSet. of(group);
      Stopwatch watch = new Stopwatch().start();
      NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1,
            inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags)));
      long createSeconds = watch.elapsed(TimeUnit.SECONDS);

      final String nodeId = node.getId();

      checkUserMetadataContains(node, userMetadata);
      checkTagsInNodeEquals(node, tags);

      getAnonymousLogger().info(
            format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds));

      watch.reset().start();

      client.runScriptOnNode(nodeId, JettyStatements.install(), nameTask("configure-jetty"));

      long configureSeconds = watch.elapsed(TimeUnit.SECONDS);

      getAnonymousLogger().info(
            format(
                  "<< configured node(%s) with %s and jetty %s in %ss",
                  nodeId,
View Full Code Here


      TemplateClassDefinition<T> templateDefinition, //
      String entireClass, //
      String materializedClassName) throws ClassTransformationException {

    try {
      Stopwatch t1 = new Stopwatch().start();
      final byte[] implementationClass = classLoader.getClassByteCode(materializedClassName, entireClass);

      // Get Template Class
      final String templateClassName = templateDefinition.getTemplateClassName().replace('.', FileUtils.separatorChar);
      final String templateClassPath = FileUtils.separator + templateClassName + ".class";
      t1.stop();
      Stopwatch t2 = new Stopwatch().start();
      final byte[] templateClass = getClassByteCodeFromPath(templateClassPath);
//      int fileNum = new Random().nextInt(100);
      //Files.write(templateClass, new File(String.format("/tmp/%d-template.class", fileNum)));
      // Generate Merge Class

      // Setup adapters for merging, remapping class names and class writing. This is done in reverse order of how they
      // will be evaluated.
      String oldTemplateSlashName = templateDefinition.getTemplateClassName().replace('.', FileUtils.separatorChar);
      String materializedSlashName = materializedClassName.replace('.', FileUtils.separatorChar);
      RemapClasses remapper = new RemapClasses(oldTemplateSlashName, materializedSlashName);
     
      Stopwatch t3;
      {
       
        ClassNode impl = getClassNodeFromByteCode(implementationClass);
        t2.stop();
        t3 = new Stopwatch().start();
       
       
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

        ClassVisitor remappingAdapter = new RemappingClassAdapter(cw, remapper);
        MergeAdapter mergingAdapter = new MergeAdapter(oldTemplateSlashName, materializedSlashName, remappingAdapter,
            impl);
        ClassReader tReader = new ClassReader(templateClass);
        tReader.accept(mergingAdapter, ClassReader.EXPAND_FRAMES);
        byte[] outputClass = cw.toByteArray();
//        Files.write(outputClass, new File(String.format("/tmp/%d-output.class", fileNum)));
        outputClass = cw.toByteArray();

        // Load the class
        classLoader.injectByteCode(materializedClassName, outputClass);
      }
      t3.stop();
      Stopwatch t4 = new Stopwatch().start();
      int i = 0;
      for (String s : remapper.getSubclasses()) {
        logger.debug("Setting up sub class {}", s);
        // for each sub class, remap them into the new class.
        String subclassPath = FileUtils.separator + s + ".class";
        final byte[] bytecode = getClassByteCodeFromPath(subclassPath);
        RemapClasses localRemapper = new RemapClasses(oldTemplateSlashName, materializedSlashName);
        Preconditions.checkArgument(localRemapper.getSubclasses().isEmpty(), "Class transformations are only supported for classes that have a single level of inner classes.");
        ClassWriter subcw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
        ClassVisitor remap = new RemappingClassAdapter(subcw, localRemapper);
        ClassReader reader = new ClassReader(bytecode);
        reader.accept(remap, ClassReader.EXPAND_FRAMES);
        byte[] newByteCode = subcw.toByteArray();
        classLoader.injectByteCode(s.replace(oldTemplateSlashName, materializedSlashName).replace(FileUtils.separatorChar, '.'), newByteCode);
//        Files.write(subcw.toByteArray(), new File(String.format("/tmp/%d-sub-%d.class", fileNum, i)));
        i++;
      }
      t4.stop();
      logger.debug(String.format("[Compile Time] Janino: %dms, Bytecode load and parse: %dms, Class Merge: %dms, Subclass remap and load: %dms.", t1.elapsed(TimeUnit.MILLISECONDS), t2.elapsed(TimeUnit.MILLISECONDS), t3.elapsed(TimeUnit.MILLISECONDS), t4.elapsed(TimeUnit.MILLISECONDS)));
      Class<?> c = classLoader.findClass(materializedClassName);
      if (templateDefinition.getExternalInterface().isAssignableFrom(c)) {
        return (T) c.newInstance();
      } else {
        throw new ClassTransformationException("The requested class did not implement the expected interface.");
View Full Code Here

        break;
      default:
        System.out.println("Invalid query type: " + type);
        return -1;
    }
    Stopwatch watch = new Stopwatch();
    watch.start();
    client.runQuery(queryType, plan, listener);
    int rows = listener.await();
    System.out.println(String.format("Got %d record%s in %f seconds", rows, rows > 1 ? "s" : "", (float)watch.elapsed(TimeUnit.MILLISECONDS) / (float)1000));
    return 0;
  }
View Full Code Here

  /**
   * Builds a mapping of block locations to file byte range
   */
  private void buildBlockMap(String fileName) {
    Stopwatch watch = new Stopwatch();
    BlockLocation[] blocks;
    ImmutableRangeMap<Long,BlockLocation> blockMap;
    try {
      watch.start();
      FileStatus file = fs.getFileStatus(new Path(fileName));
      blocks = fs.getFileBlockLocations(file, 0 , file.getLen());
      watch.stop();
      logger.debug("Block locations: {}", blocks);
      logger.debug("Took {} ms to get Block locations", watch.elapsed(TimeUnit.MILLISECONDS));
    } catch (IOException ioe) { throw new RuntimeException(ioe); }
    watch.reset();
    watch.start();
    ImmutableRangeMap.Builder<Long, BlockLocation> blockMapBuilder = new ImmutableRangeMap.Builder<Long,BlockLocation>();
    for (BlockLocation block : blocks) {
      long start = block.getOffset();
      long end = start + block.getLength();
      Range<Long> range = Range.closedOpen(start, end);
      blockMapBuilder = blockMapBuilder.put(range, block);
    }
    blockMap = blockMapBuilder.build();
    watch.stop();
    logger.debug("Took {} ms to build block map", watch.elapsed(TimeUnit.MILLISECONDS));
    blockMapMap.put(fileName, blockMap);
  }
View Full Code Here

   * For a given RowGroup, calculate how many bytes are available on each on drillbit endpoint
   *
   * @param rowGroup the RowGroup to calculate endpoint bytes for
   */
  public void setEndpointBytes(ParquetGroupScan.RowGroupInfo rowGroup) {
    Stopwatch watch = new Stopwatch();
    watch.start();
    String fileName = rowGroup.getPath();
    if (!blockMapMap.containsKey(fileName)) {
      buildBlockMap(fileName);
    }

    ImmutableRangeMap<Long,BlockLocation> blockMap = blockMapMap.get(fileName);
    HashMap<String,Long> hostMap = new HashMap<>();
    HashMap<DrillbitEndpoint,Long> endpointByteMap = new HashMap();
    long start = rowGroup.getStart();
    long end = start + rowGroup.getLength();
    Range<Long> rowGroupRange = Range.closedOpen(start, end);

    // Find submap of ranges that intersect with the rowGroup
    ImmutableRangeMap<Long,BlockLocation> subRangeMap = blockMap.subRangeMap(rowGroupRange);

    // Iterate through each block in this submap and get the host for the block location
    for (Map.Entry<Range<Long>,BlockLocation> block : subRangeMap.asMapOfRanges().entrySet()) {
      String[] hosts;
      Range<Long> blockRange = block.getKey();
      try {
        hosts = block.getValue().getHosts();
      } catch (IOException ioe) {
        throw new RuntimeException("Failed to get hosts for block location", ioe);
      }
      Range<Long> intersection = rowGroupRange.intersection(blockRange);
      long bytes = intersection.upperEndpoint() - intersection.lowerEndpoint();

      // For each host in the current block location, add the intersecting bytes to the corresponding endpoint
      for (String host : hosts) {
        DrillbitEndpoint endpoint = getDrillBitEndpoint(host);
        if (endpointByteMap.containsKey(endpoint)) {
          endpointByteMap.put(endpoint, endpointByteMap.get(endpoint) + bytes);
        } else {
          if (endpoint != null ) endpointByteMap.put(endpoint, bytes);
        }
      }
    }

    rowGroup.setEndpointBytes(endpointByteMap);
    rowGroup.setMaxBytes(endpointByteMap.size() > 0 ? Collections.max(endpointByteMap.values()) : 0);
    logger.debug("Row group ({},{}) max bytes {}", rowGroup.getPath(), rowGroup.getStart(), rowGroup.getMaxBytes());
    watch.stop();
    logger.debug("Took {} ms to set endpoint bytes", watch.elapsed(TimeUnit.MILLISECONDS));
  }
View Full Code Here

  /**
   * Builds a mapping of drillbit endpoints to hostnames
   */
  private void buildEndpointMap() {
    Stopwatch watch = new Stopwatch();
    watch.start();
    endPointMap = new HashMap<String, DrillbitEndpoint>();
    for (DrillbitEndpoint d : endpoints) {
      String hostName = d.getAddress();
      endPointMap.put(hostName, d);
    }
    watch.stop();
    logger.debug("Took {} ms to build endpoint map", watch.elapsed(TimeUnit.MILLISECONDS));
  }
View Full Code Here

    try(Drillbit bit1 = new Drillbit(config, serviceSet); DrillClient client = new DrillClient(config, serviceSet.getCoordinator());){
      bit1.run();
      client.connect();
      RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
      ParquetResultListener resultListener = new ParquetResultListener(recordsPerRowGroup, batchLoader, numberOfRowGroups, numberOfTimesRead);
      Stopwatch watch = new Stopwatch().start();
      client.runQuery(UserProtos.QueryType.LOGICAL, planText, resultListener);
      resultListener.get();
      System.out.println(String.format("Took %d ms to run query", watch.elapsed(TimeUnit.MILLISECONDS)));

    }
   
  }
View Full Code Here

    try(Drillbit bit1 = new Drillbit(config, serviceSet); DrillClient client = new DrillClient(config, serviceSet.getCoordinator());){
      bit1.run();
      client.connect();
      RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
      ParquetResultListener resultListener = new ParquetResultListener(recordsPerRowGroup, batchLoader, numberOfRowGroups, numberOfTimesRead);
      Stopwatch watch = new Stopwatch().start();
      client.runQuery(UserProtos.QueryType.PHYSICAL, Files.toString(FileUtils.getResourceAsFile(planName), Charsets.UTF_8), resultListener);
      resultListener.get();
      System.out.println(String.format("Took %d ms to run query", watch.elapsed(TimeUnit.MILLISECONDS)));

    }

  }
View Full Code Here

    DrillConfig config = DrillConfig.create();

    try(DrillClient client = new DrillClient(config);){
      client.connect();
      ParquetResultsListener listener = new ParquetResultsListener();
      Stopwatch watch = new Stopwatch();
      watch.start();
      client.runQuery(UserProtos.QueryType.PHYSICAL, Resources.toString(Resources.getResource(fileName),Charsets.UTF_8), listener);
      System.out.println(String.format("Got %d total records in %d seconds", listener.await(), watch.elapsed(TimeUnit.SECONDS)));
      client.close();
    }
  }
View Full Code Here

/**
* Calculates hashes of file contents and records metrics about the run time.
*/
public class FileHasher {
  public static ByteString getSha1(String contents) {
    Stopwatch stopWatch = new Stopwatch().start();
    ByteString sha1 = ByteString.copyFrom(Hashing.sha1().hashString(contents).asBytes());
    return sha1;
  }
View Full Code Here

TOP

Related Classes of com.google.common.base.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.