Profiles: Omit comments from stored profiles

This commit is contained in:
zzz
2019-05-21 17:24:18 +00:00
parent 67e7e45779
commit a8f11d1834
8 changed files with 246 additions and 124 deletions

View File

@ -15,29 +15,45 @@ import net.i2p.util.Log;
class PersistenceHelper {
private final static String NL = System.getProperty("line.separator");
public final static void add(StringBuilder buf, String prefix, String name, String description, double value) {
buf.append("# ").append(prefix).append(name).append(NL);
buf.append("# ").append(description).append(NL);
buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL);
public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, double value) {
if (addComments) {
buf.append("# ").append(prefix).append(name).append(NL);
buf.append("# ").append(description).append(NL);
}
buf.append(prefix).append(name).append('=').append(value).append(NL);
if (addComments)
buf.append(NL);
}
/** @since 0.8.5 */
public final static void addDate(StringBuilder buf, String prefix, String name, String description, long value) {
String when = value > 0 ? (new Date(value)).toString() : "Never";
add(buf, prefix, name, description + ' ' + when, value);
public final static void addDate(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
if (addComments) {
String when = value > 0 ? (new Date(value)).toString() : "Never";
add(buf, true, prefix, name, description + ' ' + when, value);
} else {
add(buf, false, prefix, name, description, value);
}
}
/** @since 0.8.5 */
public final static void addTime(StringBuilder buf, String prefix, String name, String description, long value) {
String when = DataHelper.formatDuration(value);
add(buf, prefix, name, description + ' ' + when, value);
}
public final static void addTime(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
if (addComments) {
String when = DataHelper.formatDuration(value);
add(buf, true, prefix, name, description + ' ' + when, value);
} else {
add(buf, false, prefix, name, description, value);
}
}
/** @param value non-negative */
public final static void add(StringBuilder buf, String prefix, String name, String description, long value) {
buf.append("# ").append(prefix).append(name).append(NL);
buf.append("# ").append(description).append(NL);
buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL);
public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
if (addComments) {
buf.append("# ").append(prefix).append(name).append(NL);
buf.append("# ").append(description).append(NL);
}
buf.append(prefix).append(name).append('=').append(value).append(NL);
if (addComments)
buf.append(NL);
}
/**

View File

@ -452,41 +452,52 @@ public class Rate {
return out;
}
/**
* Includes comment lines
*/
public synchronized void store(String prefix, StringBuilder buf) throws IOException {
PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period);
PersistenceHelper.addDate(buf, prefix, ".creationDate",
store(prefix, buf, true);
}
/**
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public synchronized void store(String prefix, StringBuilder buf, boolean addComments) throws IOException {
PersistenceHelper.addTime(buf, addComments, prefix, ".period", "Length of the period:", _period);
PersistenceHelper.addDate(buf, addComments, prefix, ".creationDate",
"When was this rate created?", _creationDate);
PersistenceHelper.addDate(buf, prefix, ".lastCoalesceDate",
PersistenceHelper.addDate(buf, addComments, prefix, ".lastCoalesceDate",
"When did we last coalesce this rate?",
_lastCoalesceDate);
PersistenceHelper.addDate(buf, prefix, ".currentDate",
PersistenceHelper.addDate(buf, addComments, prefix, ".currentDate",
"When was this data written?", now());
PersistenceHelper.add(buf, prefix, ".currentTotalValue",
PersistenceHelper.add(buf, addComments, prefix, ".currentTotalValue",
"Total value of data points in the current (uncoalesced) period", _currentTotalValue);
PersistenceHelper.add(buf, prefix, ".currentEventCount",
PersistenceHelper.add(buf, addComments, prefix, ".currentEventCount",
"How many events have occurred in the current (uncoalesced) period?", _currentEventCount);
PersistenceHelper.addTime(buf, prefix, ".currentTotalEventTime",
PersistenceHelper.addTime(buf, addComments, prefix, ".currentTotalEventTime",
"How much time have the events in the current (uncoalesced) period consumed?",
_currentTotalEventTime);
PersistenceHelper.add(buf, prefix, ".lastTotalValue",
PersistenceHelper.add(buf, addComments, prefix, ".lastTotalValue",
"Total value of data points in the most recent (coalesced) period", _lastTotalValue);
PersistenceHelper.add(buf, prefix, ".lastEventCount",
PersistenceHelper.add(buf, addComments, prefix, ".lastEventCount",
"How many events have occurred in the most recent (coalesced) period?", _lastEventCount);
PersistenceHelper.addTime(buf, prefix, ".lastTotalEventTime",
PersistenceHelper.addTime(buf, addComments, prefix, ".lastTotalEventTime",
"How much time have the events in the most recent (coalesced) period consumed?",
_lastTotalEventTime);
PersistenceHelper.add(buf, prefix, ".extremeTotalValue",
PersistenceHelper.add(buf, addComments, prefix, ".extremeTotalValue",
"Total value of data points in the most extreme period", _extremeTotalValue);
PersistenceHelper.add(buf, prefix, ".extremeEventCount",
PersistenceHelper.add(buf, addComments, prefix, ".extremeEventCount",
"How many events have occurred in the most extreme period?", _extremeEventCount);
PersistenceHelper.addTime(buf, prefix, ".extremeTotalEventTime",
PersistenceHelper.addTime(buf, addComments, prefix, ".extremeTotalEventTime",
"How much time have the events in the most extreme period consumed?",
_extremeTotalEventTime);
PersistenceHelper.add(buf, prefix, ".lifetimeTotalValue",
PersistenceHelper.add(buf, addComments, prefix, ".lifetimeTotalValue",
"Total value of data points since this stat was created", _lifetimeTotalValue);
PersistenceHelper.add(buf, prefix, ".lifetimeEventCount",
PersistenceHelper.add(buf, addComments, prefix, ".lifetimeEventCount",
"How many events have occurred since this stat was created?", _lifetimeEventCount);
PersistenceHelper.addTime(buf, prefix, ".lifetimeTotalEventTime",
PersistenceHelper.addTime(buf, addComments, prefix, ".lifetimeTotalEventTime",
"How much total time was consumed by the events since this stat was created?",
_lifetimeTotalEventTime);
}

View File

@ -177,22 +177,37 @@ public class RateStat {
&& DataHelper.eq(getName(), rs.getName());
}
/**
* Includes comment lines
*/
public void store(OutputStream out, String prefix) throws IOException {
store(out, prefix, true);
}
/**
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public void store(OutputStream out, String prefix, boolean addComments) throws IOException {
StringBuilder buf = new StringBuilder(1024);
buf.append(NL);
buf.append("################################################################################").append(NL);
buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
buf.append("# ").append(_description).append(NL);
buf.append("# ").append(NL).append(NL);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
for (Rate r: _rates){
buf.append("#######").append(NL);
buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);
if (addComments) {
buf.append(NL);
buf.append("################################################################################").append(NL);
buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
buf.append("# ").append(_description).append(NL);
buf.append("# ").append(NL).append(NL);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
}
for (Rate r: _rates){
if (addComments) {
buf.append("#######").append(NL);
buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);
buf.append(NL);
}
String curPrefix = prefix + "." + DataHelper.formatDuration(r.getPeriod());
r.store(curPrefix, buf);
r.store(curPrefix, buf, addComments);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
}