On Fri, Jun 21, 2002 at 02:58:11AM +0100, Matthew Toseland wrote: > Attached is a patch to Fred to implement a histogram of the bytes, > rather than the number of keys, under each prefix.
Whoops. BTW, my sourceforge nym is 'amphibian'.
? mydiff
? src/freenet/support/KeyBytesHistogram.java
? src/freenet/support/KeySizeHistogram.java
Index: src/freenet/client/http/NodeStatusServlet.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/client/http/NodeStatusServlet.java,v
retrieving revision 1.26
diff -r1.26 NodeStatusServlet.java
43a44
> import freenet.support.KeySizeHistogram;
143a145,149
> if (uri.endsWith("ds_size_histogram.txt")) {
> sendDSSizeHistogram(resp, false);
> return;
> };
>
166a173,177
> if (uri.endsWith("ds_size_histogram_data.txt")) {
> sendDSSizeHistogram(resp, true);
> return;
> }
>
341,342c352,353
< pw.println(" <a href= \"" + baseURL +
< "ds_histogram_data.txt\">" +
---
> pw.println(" <li> <a href= \"" + baseURL +
> "ds_histogram_data.txt\"> " +
343a355,359
> pw.println(" <li> <a href=\"" + baseURL + "ds_size_histogram.txt\">
>" +
> " Histogram of bytes in the local DataStore. </a>");
> pw.println(" <li> <a href= \"" + baseURL +
> "ds_size_histogram_data.txt\">" +
> "<br>(flat ascii)</a><br>");
503a520,531
> }
>
> private void sendDSSizeHistogram(HttpServletResponse resp, boolean justData)
>throws IOException {
>
> FSDataStore ds = (FSDataStore) node.ds;
> KeySizeHistogram histogram = ds.getSizeHistogram();
>
> sendKeyHistogram(resp, justData, histogram.getBins(),
> "Histogram of bytes used by keys in fred's data store",
> "These are the total amounts of bytes used by the data " +
> "in your node's local cache (DataStore)",
> MSG_OOPS /* bins should always be non-null */);
Index: src/freenet/node/ds/FSDataStore.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/node/ds/FSDataStore.java,v
retrieving revision 1.6
diff -r1.6 FSDataStore.java
263a264,284
> public KeySizeHistogram getSizeHistogram() {
> KeySizeHistogram histogram = new KeySizeHistogram();
>
> synchronized (dir.semaphore()) {
> Enumeration keys = dir.keys(true);
> while (keys.hasMoreElements()) {
> FileNumber fn = (FileNumber) keys.nextElement();
> Buffer buffer = dir.fetch(fn);
> try {
> histogram.add( new Key(fn.getByteArray()), buffer.length() );
> }
> finally
> {
> buffer.release();
> };
> };
> };
>
> return histogram;
> };
>
package freenet.support;
import freenet.Key;
public class KeyHistogram {
public synchronized void add(Key key) {
// Most significant nibble of the most
// significant byte
final int binNumber = (((int)key.getVal()[0]) & 0xff) >>> ((byte)4);
bins[binNumber] += key
msg03313/pgp00000.pgp
Description: PGP signature
