Re: [freenet-dev] [PATCH] More node status info: histogram by bytes

2002-06-20 Thread Matthew Toseland

On Fri, Jun 21, 2002 at 03:05:38AM +0100, Matthew Toseland wrote:
> 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'.
Slightly better version attached. The second file is
src/freenet/support/KeyBytesHistogram.java.


? 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;
>   };
> 
152c158
<  MSG_NO_REQUEST_DIST);
---
>  MSG_NO_REQUEST_DIST, "keys");
166a173,177
>   if (uri.endsWith("ds_size_histogram_data.txt")) {
>   sendDSSizeHistogram(resp, true);
>   return;
>   }
> 
176c187
<  MSG_NO_REQUEST_DIST); 
---
>  MSG_NO_REQUEST_DIST, "keys"); 
341,342c352,353
< pw.println("" +
---
> pw.println(" "ds_histogram_data.txt\"> " +
343a355,359
>   pw.println("  
>" +
>   " Histogram of bytes in the local DataStore. ");
>   pw.println("   "ds_size_histogram_data.txt\">" +
>  "(flat ascii)");
489c505,506
<  MSG_OOPS /* bins should always be non-null */);
---
>  MSG_OOPS /* bins should always be non-null */,
>"keys");
502c519,520
<  MSG_OOPS /* bins should always be non-null */);
---
>  MSG_OOPS /* bins should always be non-null */,
>"keys");
505a524,535
> 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 */, "bytes");
> }
> 
508c538
<   String complaint) throws IOException {
---
>   String complaint, String commodity) throws 
>IOException {
529c559
< float scale = 1.0f;
---
> double scale = 1.0f;
546c576
< pw.println("# keys: " + count);
---
> pw.println("# " + commodity + ": " + count);
553c583
< pw.println("keys: " + count);
---
> pw.println(commodity + ": " + count);
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 KeySizeHistogram {

public synchronized void add(Key key, long len) {
// Most significant nibble of the most 
// significant byte.
final int binNumber = (((int)key.getVal()[0]) & 0xff)  >>> ((byte)4);
bins[binNumber] += len;
}

// Distribution of keys with most significant nibbles 0-f.
public synchronized int[] getBins() {
int[] ret = new int[bins.length];
System.arraycopy(bins, 0, ret, 0, bins.length);
return ret;
}

private int bins[] = new int[16];
}



msg03314/pgp0.pgp
Description: PGP signature


Re: [freenet-dev] [PATCH] More node status info: histogram by bytes

2002-06-20 Thread Matthew Toseland

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("" +
---
> pw.println(" "ds_histogram_data.txt\"> " +
343a355,359
>   pw.println("  
>" +
>   " Histogram of bytes in the local DataStore. ");
>   pw.println("   "ds_size_histogram_data.txt\">" +
>  "(flat ascii)");
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/pgp0.pgp
Description: PGP signature


[freenet-dev] [PATCH] More node status info: histogram by bytes

2002-06-20 Thread Matthew Toseland

Attached is a patch to Fred to implement a histogram of the bytes,
rather than the number of keys, under each prefix.



msg03312/pgp0.pgp
Description: PGP signature