Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7BB1A200D48 for ; Thu, 19 Oct 2017 01:25:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7A699160BEC; Wed, 18 Oct 2017 23:25:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 06717160BF3 for ; Thu, 19 Oct 2017 01:25:52 +0200 (CEST) Received: (qmail 58140 invoked by uid 500); 18 Oct 2017 23:25:46 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 57805 invoked by uid 99); 18 Oct 2017 23:25:46 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Oct 2017 23:25:46 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 8179281C74; Wed, 18 Oct 2017 23:25:45 +0000 (UTC) Date: Wed, 18 Oct 2017 23:26:03 +0000 To: "commits@sling.apache.org" Subject: [sling-org-apache-sling-tracer] 19/49: SLING-5459 - Recording of tracer logs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: rombert@apache.org In-Reply-To: <150836914449.11639.7756158614526709952@gitbox.apache.org> References: <150836914449.11639.7756158614526709952@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: sling-org-apache-sling-tracer X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 71d3afa7e3869875e936b00a8066e369fb4129e6 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20171018232545.8179281C74@gitbox.apache.org> archived-at: Wed, 18 Oct 2017 23:25:55 -0000 This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tracer.git commit 71d3afa7e3869875e936b00a8066e369fb4129e6 Author: Chetan Mehrotra AuthorDate: Wed Feb 10 05:53:13 2016 +0000 SLING-5459 - Recording of tracer logs Expose the size of recording in web console git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1729533 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/tracer/internal/JSONRecording.java | 13 ++++++++ .../sling/tracer/internal/TracerLogServlet.java | 37 +++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java b/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java index a7b29d9..592477b 100644 --- a/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java +++ b/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java @@ -50,6 +50,7 @@ class JSONRecording implements Recording { private static final Logger log = LoggerFactory.getLogger(JSONRecording.class); private final String method; private final String requestId; + private final String uri; private final List queries = new ArrayList(); private final List logs = new ArrayList(); private RequestProgressTracker tracker; @@ -58,6 +59,7 @@ class JSONRecording implements Recording { public JSONRecording(String requestId, HttpServletRequest r) { this.requestId = requestId; this.method = r.getMethod(); + this.uri = r.getRequestURI(); } public boolean render(Writer w) throws IOException { @@ -77,6 +79,17 @@ class JSONRecording implements Recording { return false; } + public long size() { + if (json != null){ + return json.length; + } + return 0; + } + + public String getUri() { + return uri; + } + //~---------------------------------------< Recording > @Override diff --git a/src/main/java/org/apache/sling/tracer/internal/TracerLogServlet.java b/src/main/java/org/apache/sling/tracer/internal/TracerLogServlet.java index ae9d1b8..827d890 100644 --- a/src/main/java/org/apache/sling/tracer/internal/TracerLogServlet.java +++ b/src/main/java/org/apache/sling/tracer/internal/TracerLogServlet.java @@ -21,6 +21,7 @@ package org.apache.sling.tracer.internal; import java.io.IOException; import java.io.PrintWriter; +import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -116,7 +117,8 @@ class TracerLogServlet extends SimpleWebConsolePlugin implements TraceLogRecorde } private void renderStatus(PrintWriter pw) { - pw.printf("

Log Tracer Recordings: %d recordings

%n", cache.size()); + pw.printf("

Log Tracer Recordings: %d recordings, %s memory

%n", cache.size(), + memorySize()); pw.println("
"); pw.println("Tracer Recordings"); @@ -124,15 +126,25 @@ class TracerLogServlet extends SimpleWebConsolePlugin implements TraceLogRecorde pw.println("
"); } + private String memorySize() { + long size = 0; + for (JSONRecording r : cache.asMap().values()){ + size += r.size(); + } + return humanReadableByteCount(size); + } + private void renderRequests(PrintWriter pw) { if (cache.size() > 0){ pw.println("
    "); - for (String id : cache.asMap().keySet()){ - pw.printf("
  • %s
  • ", LABEL, id, id); + for (Map.Entry e : cache.asMap().entrySet()){ + String id = e.getKey(); + JSONRecording r = e.getValue(); + pw.printf("
  • %s - %s (%s)
  • ", LABEL, id, id, r.getUri(), + humanReadableByteCount(r.size())); } pw.println("
"); } - } private static String getRequestId(HttpServletRequest request) { @@ -193,6 +205,23 @@ class TracerLogServlet extends SimpleWebConsolePlugin implements TraceLogRecorde return UUID.randomUUID().toString(); } + /** + * Returns a human-readable version of the file size, where the input represents + * a specific number of bytes. Based on http://stackoverflow.com/a/3758880/1035417 + */ + private static String humanReadableByteCount(long bytes) { + if (bytes < 0) { + return "0"; + } + int unit = 1000; + if (bytes < unit) { + return bytes + " B"; + } + int exp = (int) (Math.log(bytes) / Math.log(unit)); + char pre = "kMGTPE".charAt(exp - 1); + return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); + } + void resetCache(){ cache.invalidateAll(); } -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" .