Package ro.isdc.wro.util

Examples of ro.isdc.wro.util.StopWatch


  /**
   * @return instance of watch to use.
   */
  private StopWatch getWatch() {
    if (watch == null) {
      watch = new StopWatch() {
        @Override
        public String shortSummary() {
          return SHORT_SUMMARY;
        }
      };
View Full Code Here


   * {@inheritDoc}
   */
  @Override
  public void process(final Resource resource, final Reader reader, final Writer writer)
      throws IOException {
    StopWatch stopWatch = null;
    if (isDebug()) {
      stopWatch = new StopWatch();
      before(stopWatch);
    }
    try {
      super.process(resource, reader, writer);
    } finally {
View Full Code Here

   */
  public void submit(final Collection<Callable<T>> callables)
      throws Exception {
    Validate.notNull(callables);

    final StopWatch watch = new StopWatch();
    watch.start("init");
    final long start = System.currentTimeMillis();
    final AtomicLong totalTime = new AtomicLong();
    LOG.debug("running {} tasks", callables.size());

    if (callables.size() == 1) {
      final T result = callables.iterator().next().call();
      onResultAvailable(result);
    } else {
      LOG.debug("Running tasks in parallel");
      watch.stop();

      watch.start("submit tasks");
      for (final Callable<T> callable : callables) {
        getCompletionService().submit(decorate(callable, totalTime));
      }
      watch.stop();

      watch.start("consume results");
      for (int i = 0; i < callables.size(); i++) {
        doConsumeResult();
      }
    }
    watch.stop();
    destroy();

    LOG.debug("Number of Tasks: {}", callables.size());
    final long averageExecutionTime = callables.size() != 0 ? totalTime.longValue() / callables.size() : 0;
    LOG.debug("Average Execution Time: {}", averageExecutionTime);
    LOG.debug("Total Task Time: {}", totalTime);
    LOG.debug("Grand Total Execution Time: {}", System.currentTimeMillis() - start);
    LOG.debug(watch.prettyPrint());
  }
View Full Code Here

    injector.inject(locator);
  }

  @Test
  public void test() throws Exception {
    final StopWatch watch = new StopWatch();
    watch.start("load processors");
    final List<ResourcePreProcessor> processors = loadProcessors();
    LOG.debug("found: {} processors", processors.size());
    watch.stop();
    LOG.debug(watch.prettyPrint());

    final String jsSample = IOUtils.toString(locator
        .locate("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js"), "UTF-8");
    final String cssSample = IOUtils.toString(locator
        .locate("https://gist.github.com/raw/4525988/29e5791d999181a12ae700633acc7823ed17eadb/bootstrap"), "UTF-8");
View Full Code Here

      throws Exception {
    final int availableProcessors = Runtime.getRuntime().availableProcessors();
    LOG.info("availableProcessors: {}", availableProcessors);
    // test it only if number there are more than 1 CPU cores are available
    if (availableProcessors > 1) {
      final StopWatch watch = new StopWatch();
      final WroConfiguration config = Context.get().getConfig();

      initExecutor(createSlowPreProcessor(100), createSlowPreProcessor(100), createSlowPreProcessor(100));
      final List<Resource> resources = createResources(Resource.create("r1", ResourceType.JS),
          Resource.create("r2", ResourceType.JS));

      // warm up
      config.setParallelPreprocessing(true);
      victim.processAndMerge(resources, true);

      // parallel
      watch.start("parallel preProcessing");
      config.setParallelPreprocessing(true);
      victim.processAndMerge(resources, true);
      watch.stop();
      final long parallelExecution = watch.getLastTaskTimeMillis();

      // sequential
      config.setParallelPreprocessing(false);
      watch.start("sequential preProcessing");
      victim.processAndMerge(resources, true);
      watch.stop();
      final long sequentialExecution = watch.getLastTaskTimeMillis();

      final String message = "Processing details: \n" + watch.prettyPrint();
      LOG.debug(message);

      // prove that running in parallel is faster
      // delta indicates the improvement relative to parallel execution (we use 80% relative improvement, but it
      // normally
View Full Code Here

  }

  @Override
  public void process(final Reader reader, final Writer writer)
      throws IOException {
    final StopWatch watch = new StopWatch();
    watch.start("rhino setup");
    RhinoExecutor.execute(new JsTask<String>() {
      @Override
      public String run(final Global global, final Context context,
          final Scriptable scope) throws IOException {
        watch.stop();
        watch.start("r.js");
        ServletContext servletContext = servletContext();
        final String tmpdir = System.getProperty("java.io.tmpdir");
        final HttpServletRequest currentRequest = currentRequest();
        final String profile = currentRequest.getParameter("profile");
        final String uri = currentRequest.getRequestURI().replace(
            servletContext.getContextPath(), "");
        final String baseName = getBaseName(uri);
        final String name = baseName + "-" + System.nanoTime();
        final String appDir = servletContext.getRealPath("/");
        final String base = appDir;
        // mkdirs
        new File(base).mkdirs();
        final String baseBuild = base + "/build";
        final File tmpIn = new File(base, name + ".js");
        final File out = new File(tmpdir, name + "-bundle.js");
        // safe the current input to file and use it. doing this we make sure
        // that if any previous processor in the chain changed the input we use
        // that in r.js.
        WroHelper.safeCopy(reader, new FileWriter(tmpIn));

        // r.js arguments
        List<String> args = Lists.newArrayList(
            "-o",
            "name=" + name,
            "baseUrl=" + base,
            "out=" + out.getAbsolutePath(),
            "optimize=none"
            );

        // Find a specific build profile for the given file.
        File build =
            buildFile(baseBuild, baseName, profile, mode.name());
        if (build == null) {
          // no luck, find a global profile per environment
          build = buildFile(baseBuild, "build", profile, mode.name());
          if (build == null) {
            // no luck, defaults to build.js
            build = new File(baseBuild, "build.js");
          }
        }
        if (build.exists()) {
          logger.debug("Build's profile found: {}", build.getName());
          args.add(1, build.getAbsolutePath());
        }

        global.defineProperty("arguments",
            context.newArray(global, args.toArray(new Object[args.size()])),
            ScriptableObject.DONTENUM);

        logger.debug("r.js {}", StringUtils.join(args, " "));

        // execute r.js
        Reader bundle = null;
        try {
          context.evaluateString(scope, source, "r.js", 1, null);
          // Read the r.js output.
          bundle = new FileReader(out);
          String content = IOUtils.toString(bundle).replace(name, baseName);
          WroHelper.safeCopy(new StringReader(content), writer);
          return null;
        } finally {
          logger.debug("Deleting: {}", tmpIn);
          FileUtils.deleteQuietly(tmpIn);

          logger.debug("Deleting: {}", out);
          FileUtils.deleteQuietly(out);
          watch.stop();
          logger.debug(watch.prettyPrint());
        }
      }

    });
  }
View Full Code Here

  }

  @Override
  public void process(final Reader reader, final Writer writer)
      throws IOException {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start("lessify");
    Context context = Context.get();
    HttpServletRequest request = context.getRequest();
    String uri = request.getRequestURI();
    try {
      logger.debug("lessifying: {}", uri);
      LessCompiler less = new LessCompiler();
      String content = IOUtils.toString(reader);
      writer.write(less.compile(content));
    } catch (LessException ex) {
      throw new LessRuntimeException(LessCssError.of(
          uri, ex.getCause()), ex.getCause());
    } finally {
      // Rhino throws an exception when trying to exit twice. Make sure we don't
      // get any exception
      if (org.mozilla.javascript.Context.getCurrentContext() != null) {
        org.mozilla.javascript.Context.exit();
      }
      IOUtils.closeQuietly(reader);
      IOUtils.closeQuietly(writer);
      stopWatch.stop();
      logger.debug(stopWatch.prettyPrint());
    }
  }
View Full Code Here

TOP

Related Classes of ro.isdc.wro.util.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.