Ejemplo n.º 1
0
  public static void end() {
    if (logger.isDebugEnabled()) {
      try {
        long thread = Thread.currentThread().getId();
        CloudOperation current = operations.get(thread);

        if (current == null) {
          return;
        }
        CloudOperation parent = null;

        while (current.currentChild != null) {
          parent = current;
          current = current.currentChild;
        }
        current.endTimestamp = System.currentTimeMillis();
        if (parent != null) {
          if (parent.priorChildren == null) {
            parent.priorChildren = new ArrayList<CloudOperation>();
          }
          parent.priorChildren.add(current);
          parent.currentChild = null;
        } else {
          operations.remove(thread);
        }
        log(current);
      } catch (Throwable t) {
        logger.warn("Error with API trace end: " + t.getMessage());
      }
    }
  }
Ejemplo n.º 2
0
  public static void begin(@Nonnull CloudProvider provider, @Nonnull String operationName) {
    if (logger.isDebugEnabled()) {
      try {
        ProviderContext ctx = provider.getContext();
        String accountNumber = getAccountNumber(ctx);

        operationName =
            provider.getProviderName().replaceAll(DELIMITER_REGEX, "_")
                + DELIMITER
                + provider.getCloudName().replaceAll(DELIMITER_REGEX, "_")
                + DELIMITER
                + accountNumber.replaceAll(DELIMITER_REGEX, "_")
                + DELIMITER
                + operationName;
        long thread = Thread.currentThread().getId();
        CloudOperation operation = new CloudOperation(operationName);
        CloudOperation current = operations.get(thread);

        if (current == null) {
          operations.put(thread, operation);
        } else {
          while (current.currentChild != null) {
            current = current.currentChild;
          }
          current.currentChild = operation;
        }
        synchronized (operationCount) {
          if (operationCount.containsKey(operationName)) {
            operationCount.put(operationName, operationCount.get(operationName) + 1);
          } else {
            operationCount.put(operationName, 1L);
          }
        }
      } catch (Throwable t) {
        logger.warn("Error with API trace begin: " + t.getMessage());
      }
    }
  }