Changeset 475187f


Ignore:
Timestamp:
Aug 18, 2009 8:33:15 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c537d16
Parents:
a379e36
Message:
  • Stats:
    • Fix BufferedStatsLog? so it works at all
    • Don't instantiate BufferedStatsLog? unless stats.logFilters property is defined (restart now required to enable logging) This eliminates the StatLogWriter? thread and a decent amount of memory.
    • Move two CLI classes out of the lib
    • Commment out places where getStatLog() isn't checked for null
    • Cleanups
Files:
5 edited
2 moved

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/Connection.java

    ra379e36 r475187f  
    334334        }
    335335
    336         _context.statManager().getStatLog().addData(Packet.toId(_sendStreamId), "stream.rtt", _options.getRTT(), _options.getWindowSize());
     336        // warning, getStatLog() can be null
     337        //_context.statManager().getStatLog().addData(Packet.toId(_sendStreamId), "stream.rtt", _options.getRTT(), _options.getWindowSize());
    337338       
    338339        _lastSendTime = _context.clock().now();
  • core/java/src/net/i2p/stat/BufferedStatLog.java

    ra379e36 r475187f  
    1616
    1717/**
    18  *
     18 * Note - if no filter is defined in stat.logFilters at startup, this class will not
     19 * be instantiated - see StatManager.
    1920 */
    2021public class BufferedStatLog implements StatLog {
     
    4748        _statFilters = new ArrayList(10);
    4849        _flushFrequency = 500;
    49         _filtersSpecified = false;
     50        updateFilters();
    5051        I2PThread writer = new I2PThread(new StatLogWriter(), "StatLogWriter");
    5152        writer.setDaemon(true);
     
    9495                    while (tok.hasMoreTokens())
    9596                        _statFilters.add(tok.nextToken().trim());
    96                     if (_statFilters.size() > 0)
    97                         _filtersSpecified = true;
    98                     else
    99                         _filtersSpecified = false;
     97                    _filtersSpecified = _statFilters.size() > 0;
    10098                }
    10199            }
     
    108106        }
    109107       
    110         String filename = _context.getProperty(StatManager.PROP_STAT_FILE);
    111         if (filename == null)
    112             filename = StatManager.DEFAULT_STAT_FILE;
     108        String filename = _context.getProperty(StatManager.PROP_STAT_FILE, StatManager.DEFAULT_STAT_FILE);
    113109        File foo = new File(filename);
    114110        if (!foo.isAbsolute())
  • core/java/src/net/i2p/stat/StatManager.java

    ra379e36 r475187f  
    2626
    2727    /** stat name to FrequencyStat */
    28     private final Map _frequencyStats;
     28    private final Map<String, FrequencyStat> _frequencyStats;
    2929    /** stat name to RateStat */
    30     private final Map _rateStats;
     30    private final Map<String, RateStat> _rateStats;
     31    /** may be null */
    3132    private StatLog _statLog;
    3233
     34    /**
     35     *  Comma-separated stats or * for all.
     36     *  This property must be set at startup, or
     37     *  logging is disabled.
     38     */
    3339    public static final String PROP_STAT_FILTER = "stat.logFilters";
    3440    public static final String PROP_STAT_FILE = "stat.logFile";
     
    6672        _log = context.logManager().getLog(StatManager.class);
    6773        _context = context;
    68         _frequencyStats = Collections.synchronizedMap(new HashMap(128));
     74        _frequencyStats = Collections.synchronizedMap(new HashMap(8));
    6975        _rateStats = new HashMap(128); // synchronized only on add //Collections.synchronizedMap(new HashMap(128));
    70         _statLog = new BufferedStatLog(context);
     76        if (getStatFilter() != null)
     77            _statLog = new BufferedStatLog(context);
    7178    }
    7279   
     80    /** may be null */
    7381    public StatLog getStatLog() { return _statLog; }
    7482    public void setStatLog(StatLog log) {
    7583        _statLog = log;
    7684        synchronized (_rateStats) {
    77             for (Iterator iter = _rateStats.values().iterator(); iter.hasNext(); ) {
    78                 RateStat rs = (RateStat)iter.next();
     85            for (Iterator<RateStat> iter = _rateStats.values().iterator(); iter.hasNext(); ) {
     86                RateStat rs = iter.next();
    7987                rs.setStatLog(log);
    8088            }
     
    123131    /** update the given frequency statistic, taking note that an event occurred (and recalculating all frequencies) */
    124132    public void updateFrequency(String name) {
    125         FrequencyStat freq = (FrequencyStat) _frequencyStats.get(name);
     133        FrequencyStat freq = _frequencyStats.get(name);
    126134        if (freq != null) freq.eventOccurred();
    127135    }
     
    129137    /** update the given rate statistic, taking note that the given data point was received (and recalculating all rates) */
    130138    public void addRateData(String name, long data, long eventDuration) {
    131         RateStat stat = (RateStat) _rateStats.get(name); // unsynchronized
     139        RateStat stat = _rateStats.get(name); // unsynchronized
    132140        if (stat != null) stat.addData(data, eventDuration);
    133141    }
     
    135143    public void coalesceStats() {
    136144        synchronized (_frequencyStats) {
    137             for (Iterator iter = _frequencyStats.values().iterator(); iter.hasNext();) {
    138                 FrequencyStat stat = (FrequencyStat)iter.next();
     145            for (Iterator<FrequencyStat> iter = _frequencyStats.values().iterator(); iter.hasNext();) {
     146                FrequencyStat stat = iter.next();
    139147                if (stat != null) {
    140148                    stat.coalesceStats();
     
    143151        }
    144152        synchronized (_rateStats) {
    145             for (Iterator iter = _rateStats.values().iterator(); iter.hasNext();) {
    146                 RateStat stat = (RateStat)iter.next();
     153            for (Iterator<RateStat> iter = _rateStats.values().iterator(); iter.hasNext();) {
     154                RateStat stat = iter.next();
    147155                if (stat != null) {
    148156                    stat.coalesceStats();
     
    153161
    154162    public FrequencyStat getFrequency(String name) {
    155         return (FrequencyStat) _frequencyStats.get(name);
     163        return _frequencyStats.get(name);
    156164    }
    157165
    158166    public RateStat getRate(String name) {
    159         return (RateStat) _rateStats.get(name);
    160     }
    161 
    162     public Set getFrequencyNames() {
     167        return _rateStats.get(name);
     168    }
     169
     170    public Set<String> getFrequencyNames() {
    163171        return new HashSet(_frequencyStats.keySet());
    164172    }
    165173
    166     public Set getRateNames() {
     174    public Set<String> getRateNames() {
    167175        return new HashSet(_rateStats.keySet());
    168176    }
     
    181189    public Map getStatsByGroup() {
    182190        Map groups = new TreeMap(Collator.getInstance());
    183         for (Iterator iter = _frequencyStats.values().iterator(); iter.hasNext();) {
    184             FrequencyStat stat = (FrequencyStat) iter.next();
     191        for (Iterator<FrequencyStat> iter = _frequencyStats.values().iterator(); iter.hasNext();) {
     192            FrequencyStat stat = iter.next();
    185193            if (!groups.containsKey(stat.getGroupName())) groups.put(stat.getGroupName(), new TreeSet());
    186194            Set names = (Set) groups.get(stat.getGroupName());
    187195            names.add(stat.getName());
    188196        }
    189         for (Iterator iter = _rateStats.values().iterator(); iter.hasNext();) {
    190             RateStat stat = (RateStat) iter.next();
     197        for (Iterator<RateStat> iter = _rateStats.values().iterator(); iter.hasNext();) {
     198            RateStat stat = iter.next();
    191199            if (!groups.containsKey(stat.getGroupName())) groups.put(stat.getGroupName(), new TreeSet());
    192200            Set names = (Set) groups.get(stat.getGroupName());
     
    199207    public String getStatFile() { return _context.getProperty(PROP_STAT_FILE, DEFAULT_STAT_FILE); }
    200208
    201     // Save memory by not creating stats unless they are required for router operation
    202     // Return true if the stat should be ignored.
     209    /**
     210     * Save memory by not creating stats unless they are required for router operation
     211     * @return true if the stat should be ignored.
     212     */
    203213    public boolean ignoreStat(String statName) {
    204214        if (_context.getProperty(PROP_STAT_FULL, DEFAULT_STAT_FULL).equalsIgnoreCase("true"))
  • router/java/src/net/i2p/router/transport/FIFOBandwidthLimiter.java

    ra379e36 r475187f  
    304304                _recvBps = (0.9f)*_recvBps + (0.1f)*((float)recv*1000)/(float)time;
    305305
    306             if (_log.shouldLog(Log.WARN)) {
     306            // warning, getStatLog() can be null
     307            //if (_log.shouldLog(Log.WARN)) {
    307308                //if (_log.shouldLog(Log.INFO))
    308309                //    _log.info("BW: time = " + time + " sent: " + _sendBps + " recv: " + _recvBps);
    309                 _context.statManager().getStatLog().addData("bw", "bw.sendBps1s", (long)_sendBps, sent);
    310                 _context.statManager().getStatLog().addData("bw", "bw.recvBps1s", (long)_recvBps, recv);
    311             }
     310            //    _context.statManager().getStatLog().addData("bw", "bw.sendBps1s", (long)_sendBps, sent);
     311            //    _context.statManager().getStatLog().addData("bw", "bw.recvBps1s", (long)_recvBps, recv);
     312            //}
    312313
    313314            // Maintain an approximate average with a 15-second halflife
     
    324325                _recvBps15s = (0.955f)*_recvBps15s + (0.045f)*((float)recv*1000)/(float)time;
    325326
    326             if (_log.shouldLog(Log.WARN)) {
    327                 if (_log.shouldLog(Log.DEBUG))
    328                     _log.debug("BW15: time = " + time + " sent: " + _sendBps + " recv: " + _recvBps);
    329                 _context.statManager().getStatLog().addData("bw", "bw.sendBps15s", (long)_sendBps15s, sent);
    330                 _context.statManager().getStatLog().addData("bw", "bw.recvBps15s", (long)_recvBps15s, recv);
    331             }
     327            // warning, getStatLog() can be null
     328            //if (_log.shouldLog(Log.WARN)) {
     329            //    if (_log.shouldLog(Log.DEBUG))
     330            //        _log.debug("BW15: time = " + time + " sent: " + _sendBps + " recv: " + _recvBps);
     331            //    _context.statManager().getStatLog().addData("bw", "bw.sendBps15s", (long)_sendBps15s, sent);
     332            //    _context.statManager().getStatLog().addData("bw", "bw.recvBps15s", (long)_recvBps15s, recv);
     333            //}
    332334        }
    333335    }
  • router/java/src/net/i2p/router/transport/udp/UDPFlooder.java

    ra379e36 r475187f  
    9191                            continue;
    9292                        msg.setTarget(to);
    93                         _context.statManager().getStatLog().addData(peer.getRemotePeer().toBase64().substring(0,6), "udp.floodDataSent", 1, 0);
     93                        // warning, getStatLog() can be null
     94                        //_context.statManager().getStatLog().addData(peer.getRemotePeer().toBase64().substring(0,6), "udp.floodDataSent", 1, 0);
    9495
    9596                        _transport.send(msg);
Note: See TracChangeset for help on using the changeset viewer.