Package ro.isdc.wro.util

Examples of ro.isdc.wro.util.StopWatch$TaskInfo


   *          the cache key which was requested. The key contains the groupName which has to be checked for changes.
   */
  public void check(final CacheKey cacheKey, final Callback callback) {
    notNull(cacheKey);
    LOG.debug("started");
    final StopWatch watch = new StopWatch();
    watch.start("detect changes");
    try {
      final Group group = new WroModelInspector(modelFactory.create()).getGroupByName(cacheKey.getGroupName());
      if (isGroupChanged(group.collectResourcesOfType(cacheKey.getType()), callback)) {
        callback.onGroupChanged(cacheKey);
        cacheStrategy.put(cacheKey, null);
      }
      resourceChangeDetector.reset();
    } catch (final Exception e) {
      onException(e);
    } finally {
      watch.stop();
      LOG.debug("resource watcher info: {}", watch.prettyPrint());
    }
  }
View Full Code Here


      throws IOException {
    Reader input = reader;
    Writer output = null;
    LOG.debug("processing resource: {}", requestUri);
    try {
      final StopWatch stopWatch = new StopWatch();
      final Injector injector = InjectorBuilder.create(new BaseWroManagerFactory()).build();
      final List<ResourcePreProcessor> processors = getProcessorsList();
      if (processors == null || processors.isEmpty()) {
        IOUtils.copy(reader, writer);
      } else {
        for (final ResourcePreProcessor processor : processors) {
          stopWatch.start("Using " + processor.getClass().getSimpleName());
          // inject all required properties
          injector.inject(processor);

          output = new StringWriter();
          LOG.debug("Using {} processor", processor);
          processor.process(createResource(requestUri), input, output);

          input = new StringReader(output.toString());
          stopWatch.stop();
        }
        LOG.debug(stopWatch.prettyPrint());
        writer.write(output.toString());
      }
    } finally {
      reader.close();
      writer.close();
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public synchronized WroModel create() {
    model = new WroModel();
    final StopWatch stopWatch = new StopWatch("Create Wro Model from XML");
    try {
      stopWatch.start("createDocument");
      final Document document = createDocument();
      stopWatch.stop();

      stopWatch.start("processGroups");
      processGroups(document);
      stopWatch.stop();

      stopWatch.start("processImports");
      processImports(document);
      stopWatch.stop();

      stopWatch.start("createModel");
      parseGroups();
      stopWatch.stop();
      return model;
    } finally {
      // clear the processed imports even when the model creation fails.
      processedImports.clear();
      LOG.debug(stopWatch.prettyPrint());
    }
  }
View Full Code Here

          Thread.sleep((long) sleep);
          return result;
        }
      });
    }
    final StopWatch watch = new StopWatch();
    watch.start("submit tasks");
    executor.submit(tasks);
    watch.stop();
    LOG.debug(watch.prettyPrint());
  }
View Full Code Here

  /**
   * @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

TOP

Related Classes of ro.isdc.wro.util.StopWatch$TaskInfo

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.