Changeset a8f11d1 for core


Ignore:
Timestamp:
May 21, 2019 5:24:18 PM (11 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a6434fb
Parents:
67e7e45
Message:

Profiles: Omit comments from stored profiles

Location:
core/java/src/net/i2p/stat
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/stat/PersistenceHelper.java

    r67e7e45 ra8f11d1  
    1616    private final static String NL = System.getProperty("line.separator");
    1717
    18     public final static void add(StringBuilder buf, String prefix, String name, String description, double value) {
    19         buf.append("# ").append(prefix).append(name).append(NL);
    20         buf.append("# ").append(description).append(NL);
    21         buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL);
     18    public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, double value) {
     19        if (addComments) {
     20            buf.append("# ").append(prefix).append(name).append(NL);
     21            buf.append("# ").append(description).append(NL);
     22        }
     23        buf.append(prefix).append(name).append('=').append(value).append(NL);
     24        if (addComments)
     25           buf.append(NL);
    2226    }
    2327
    2428    /** @since 0.8.5 */
    25     public final static void addDate(StringBuilder buf, String prefix, String name, String description, long value) {
    26         String when = value > 0 ? (new Date(value)).toString() : "Never";
    27         add(buf, prefix, name, description + ' ' + when, value);
     29    public final static void addDate(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
     30        if (addComments) {
     31            String when = value > 0 ? (new Date(value)).toString() : "Never";
     32            add(buf, true, prefix, name, description + ' ' + when, value);
     33       } else {
     34            add(buf, false, prefix, name, description, value);
     35       }
    2836    }
    2937
    3038    /** @since 0.8.5 */
    31     public final static void addTime(StringBuilder buf, String prefix, String name, String description, long value) {
    32         String when = DataHelper.formatDuration(value);
    33         add(buf, prefix, name, description + ' ' + when, value);
    34     }
     39    public final static void addTime(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
     40        if (addComments) {
     41            String when = DataHelper.formatDuration(value);
     42            add(buf, true, prefix, name, description + ' ' + when, value);
     43       } else {
     44            add(buf, false, prefix, name, description, value);
     45       }
     46   }
    3547
    3648    /** @param value non-negative */
    37     public final static void add(StringBuilder buf, String prefix, String name, String description, long value) {
    38         buf.append("# ").append(prefix).append(name).append(NL);
    39         buf.append("# ").append(description).append(NL);
    40         buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL);
     49    public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
     50        if (addComments) {
     51            buf.append("# ").append(prefix).append(name).append(NL);
     52            buf.append("# ").append(description).append(NL);
     53        }
     54        buf.append(prefix).append(name).append('=').append(value).append(NL);
     55        if (addComments)
     56           buf.append(NL);
    4157    }
    4258
  • core/java/src/net/i2p/stat/Rate.java

    r67e7e45 ra8f11d1  
    453453    }
    454454
     455    /**
     456     * Includes comment lines
     457     */
    455458    public synchronized void store(String prefix, StringBuilder buf) throws IOException {
    456         PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period);
    457         PersistenceHelper.addDate(buf, prefix, ".creationDate",
     459        store(prefix, buf, true);
     460    }
     461
     462    /**
     463     * @param addComments add comment lines to the output
     464     * @since 0.9.41
     465     */
     466    public synchronized void store(String prefix, StringBuilder buf, boolean addComments) throws IOException {
     467        PersistenceHelper.addTime(buf, addComments, prefix, ".period", "Length of the period:", _period);
     468        PersistenceHelper.addDate(buf, addComments, prefix, ".creationDate",
    458469                              "When was this rate created?", _creationDate);
    459         PersistenceHelper.addDate(buf, prefix, ".lastCoalesceDate",
     470        PersistenceHelper.addDate(buf, addComments, prefix, ".lastCoalesceDate",
    460471                              "When did we last coalesce this rate?",
    461472                              _lastCoalesceDate);
    462         PersistenceHelper.addDate(buf, prefix, ".currentDate",
     473        PersistenceHelper.addDate(buf, addComments, prefix, ".currentDate",
    463474                              "When was this data written?", now());
    464         PersistenceHelper.add(buf, prefix, ".currentTotalValue",
     475        PersistenceHelper.add(buf, addComments, prefix, ".currentTotalValue",
    465476                              "Total value of data points in the current (uncoalesced) period", _currentTotalValue);
    466         PersistenceHelper.add(buf, prefix, ".currentEventCount",
     477        PersistenceHelper.add(buf, addComments, prefix, ".currentEventCount",
    467478                              "How many events have occurred in the current (uncoalesced) period?", _currentEventCount);
    468         PersistenceHelper.addTime(buf, prefix, ".currentTotalEventTime",
     479        PersistenceHelper.addTime(buf, addComments, prefix, ".currentTotalEventTime",
    469480                              "How much time have the events in the current (uncoalesced) period consumed?",
    470481                              _currentTotalEventTime);
    471         PersistenceHelper.add(buf, prefix, ".lastTotalValue",
     482        PersistenceHelper.add(buf, addComments, prefix, ".lastTotalValue",
    472483                              "Total value of data points in the most recent (coalesced) period", _lastTotalValue);
    473         PersistenceHelper.add(buf, prefix, ".lastEventCount",
     484        PersistenceHelper.add(buf, addComments, prefix, ".lastEventCount",
    474485                              "How many events have occurred in the most recent (coalesced) period?", _lastEventCount);
    475         PersistenceHelper.addTime(buf, prefix, ".lastTotalEventTime",
     486        PersistenceHelper.addTime(buf, addComments, prefix, ".lastTotalEventTime",
    476487                              "How much time have the events in the most recent (coalesced) period consumed?",
    477488                              _lastTotalEventTime);
    478         PersistenceHelper.add(buf, prefix, ".extremeTotalValue",
     489        PersistenceHelper.add(buf, addComments, prefix, ".extremeTotalValue",
    479490                              "Total value of data points in the most extreme period", _extremeTotalValue);
    480         PersistenceHelper.add(buf, prefix, ".extremeEventCount",
     491        PersistenceHelper.add(buf, addComments, prefix, ".extremeEventCount",
    481492                              "How many events have occurred in the most extreme period?", _extremeEventCount);
    482         PersistenceHelper.addTime(buf, prefix, ".extremeTotalEventTime",
     493        PersistenceHelper.addTime(buf, addComments, prefix, ".extremeTotalEventTime",
    483494                              "How much time have the events in the most extreme period consumed?",
    484495                              _extremeTotalEventTime);
    485         PersistenceHelper.add(buf, prefix, ".lifetimeTotalValue",
     496        PersistenceHelper.add(buf, addComments, prefix, ".lifetimeTotalValue",
    486497                              "Total value of data points since this stat was created", _lifetimeTotalValue);
    487         PersistenceHelper.add(buf, prefix, ".lifetimeEventCount",
     498        PersistenceHelper.add(buf, addComments, prefix, ".lifetimeEventCount",
    488499                              "How many events have occurred since this stat was created?", _lifetimeEventCount);
    489         PersistenceHelper.addTime(buf, prefix, ".lifetimeTotalEventTime",
     500        PersistenceHelper.addTime(buf, addComments, prefix, ".lifetimeTotalEventTime",
    490501                              "How much total time was consumed by the events since this stat was created?",
    491502                              _lifetimeTotalEventTime);
  • core/java/src/net/i2p/stat/RateStat.java

    r67e7e45 ra8f11d1  
    178178    }
    179179
     180    /**
     181     * Includes comment lines
     182     */
    180183    public void store(OutputStream out, String prefix) throws IOException {
     184        store(out, prefix, true);
     185    }
     186
     187    /**
     188     * @param addComments add comment lines to the output
     189     * @since 0.9.41
     190     */
     191    public void store(OutputStream out, String prefix, boolean addComments) throws IOException {
    181192        StringBuilder buf = new StringBuilder(1024);
    182         buf.append(NL);
    183         buf.append("################################################################################").append(NL);
    184         buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
    185         buf.append("# ").append(_description).append(NL);
    186         buf.append("# ").append(NL).append(NL);
    187         out.write(buf.toString().getBytes("UTF-8"));
    188         buf.setLength(0);
     193        if (addComments) {
     194            buf.append(NL);
     195            buf.append("################################################################################").append(NL);
     196            buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
     197            buf.append("# ").append(_description).append(NL);
     198            buf.append("# ").append(NL).append(NL);
     199            out.write(buf.toString().getBytes("UTF-8"));
     200            buf.setLength(0);
     201        }
    189202        for (Rate r: _rates){
    190             buf.append("#######").append(NL);
    191             buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
    192                 .append(_groupName).append(" - ").append(_statName).append(NL);
    193             buf.append(NL);
     203            if (addComments) {
     204                buf.append("#######").append(NL);
     205                buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
     206                    .append(_groupName).append(" - ").append(_statName).append(NL);
     207                buf.append(NL);
     208            }
    194209            String curPrefix = prefix + "." + DataHelper.formatDuration(r.getPeriod());
    195             r.store(curPrefix, buf);
     210            r.store(curPrefix, buf, addComments);
    196211            out.write(buf.toString().getBytes("UTF-8"));
    197212            buf.setLength(0);
Note: See TracChangeset for help on using the changeset viewer.