Skip to content

Commit

Permalink
More stats and tracking support to multi Application
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf committed Sep 6, 2024
1 parent d801f82 commit cf8fc39
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ProfileStats {
private final String id;
private String action;
private String contextId;
private String label;

private long maxMemory;
private long allocatedMemory;
Expand All @@ -47,8 +48,8 @@ public class ProfileStats {
private long nonHeapCommitted;
private long nonHeapMax;
private int threadCount;
private List<String> deadThreads;
private List<String> liveThreads;
private final List<String> deadThreads;
private final List<String> liveThreads;

private ProfileStats() {
version = VERSION;
Expand Down Expand Up @@ -150,6 +151,10 @@ public Map<String, JsonValue> toJsonValueMap() {
.toJsonValue().map;
}

public String getLabel() {
return label;
}

public String getAction() {
return action;
}
Expand Down Expand Up @@ -234,18 +239,23 @@ private static boolean equivalent(List<String> l1, List<String> l2)
private static final String REPORT_LINE_HEADER = "| %-15s | max | allocated | free | heap init | heap used | heap cmtd | heap max | non init | non used | non cmtd | non max | alive | dead |\n";
private static final String REPORT_LINE_FORMAT = "| %-15s | %12s | %12s | %12s | %12s | %12s | %12s | %12s | %12s | %12s | %12s | %12s | %7s | %7s |\n";

public ProfileStats label(String label) {
this.label = label;
return this;
}

public static void report(List<ProfileStats> list) {
for (int x = 0; x < list.size(); x++) {
ProfileStats ps = list.get(x);
report(ps, ps.contextId, x == 0, false, System.out);
report(ps, lineLabel(x, ps.label), x == 0, false, System.out);
}
System.out.println(REPORT_SEP_LINE);
}

public static void report(ProfileStats p, String label, boolean header, boolean footer, PrintStream out) {
if (header) {
out.println("\n" + REPORT_SEP_LINE);
out.printf(REPORT_LINE_HEADER, p.action);
out.printf(REPORT_LINE_HEADER, "");
out.println(REPORT_SEP_LINE);
}
out.printf(REPORT_LINE_FORMAT, label,
Expand All @@ -267,4 +277,11 @@ public static void report(ProfileStats p, String label, boolean header, boolean
out.println(REPORT_SEP_LINE);
}
}

private static String lineLabel(int x, String profileLabel) {
if (profileLabel != null) {
return profileLabel;
}
return "Thread " + (x + 1);
}
}
32 changes: 19 additions & 13 deletions js-multi-tool/src/main/java/io/nats/jsmulti/shared/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class Stats {
public final String key;

private String exceptionMessage;
public String label;

// running numbers
private long elapsed = 0;
Expand Down Expand Up @@ -158,6 +159,15 @@ public Map<String, JsonValue> toJsonValueMap() {
.toJsonValue().map;
}

public Stats label(String label) {
this.label = label;
return this;
}

public String getLabel() {
return label;
}

public void setException(Exception e){
exceptionMessage = e.getMessage();
}
Expand Down Expand Up @@ -373,21 +383,17 @@ public static void report(List<Stats> statList) {
}

public static void report(List<Stats> statList, PrintStream out) {
report(statList, out, true, false);
}

public static void report(List<Stats> statList, boolean idAsColumnLabel) {
report(statList, System.out, true, idAsColumnLabel);
report(statList, out, true);
}

public static void report(List<Stats> statList, PrintStream out, boolean showTotal, boolean idAsColumnLabel) {
public static void report(List<Stats> statList, PrintStream out, boolean showTotal) {
Stats totalStats = total(statList);

Context ctx = statList.get(0).ctx;
if (ctx != null && ctx.action == Action.RTT) {
for (int x = 0; x < statList.size(); x++) {
Stats stats = statList.get(x);
rttReport(stats, mainLabel(x, idAsColumnLabel, stats), x == 0, false, out);
rttReport(stats, lineLabel(x, stats.label), x == 0, false, out);
}
out.println(RTT_REPORT_SEP_LINE);
if (showTotal) {
Expand All @@ -398,7 +404,7 @@ public static void report(List<Stats> statList, PrintStream out, boolean showTot

for (int x = 0; x < statList.size(); x++) {
Stats stats = statList.get(x);
report(stats, mainLabel(x, idAsColumnLabel, stats), x == 0, false, out);
report(stats, lineLabel(x, stats.label), x == 0, false, out);
}
out.println(REPORT_SEP_LINE);
if (showTotal) {
Expand All @@ -408,7 +414,7 @@ public static void report(List<Stats> statList, PrintStream out, boolean showTot
if (statList.get(0).messagePubToServerTimeElapsed > 0) {
for (int x = 0; x < statList.size(); x++) {
Stats stats = statList.get(x);
ltReport(stats, mainLabel(x, idAsColumnLabel, stats), x == 0, false, out);
ltReport(stats, lineLabel(x, stats.label), x == 0, false, out);
}
out.println(LT_REPORT_SEP_LINE);
if (showTotal) {
Expand All @@ -417,17 +423,17 @@ public static void report(List<Stats> statList, PrintStream out, boolean showTot

for (int x = 0; x < statList.size(); x++) {
Stats stats = statList.get(x);
lmReport(stats, mainLabel(x, idAsColumnLabel, stats), x == 0, false, out);
lmReport(stats, lineLabel(x, stats.label), x == 0, false, out);
}
if (showTotal) {
lmReport(totalStats, "Total", false, true, out);
}
}
}

private static String mainLabel(int x, boolean idAsColumnLabel, Stats stats) {
if (idAsColumnLabel) {
return stats.id;
private static String lineLabel(int x, String statsLabel) {
if (statsLabel != null) {
return statsLabel;
}
return "Thread " + (x + 1);
}
Expand Down

0 comments on commit cf8fc39

Please sign in to comment.