From e2ac5f62bd2ae8ce047d74f5c6231f596d5b1037 Mon Sep 17 00:00:00 2001 From: karlchenofhell Date: Sun, 11 Mar 2007 19:53:14 +0000 Subject: [PATCH] =?UTF-8?q?-=20Code=20h=C3=BCbscher=20machen=20[von=20NNs?= =?UTF-8?q?=20TODO]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3471 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/PeerLoadPicture.java | 64 ++++++++++- source/de/anomic/plasma/plasmaGrafics.java | 125 +++++++++------------ 2 files changed, 109 insertions(+), 80 deletions(-) diff --git a/htroot/PeerLoadPicture.java b/htroot/PeerLoadPicture.java index 4633f0e9a..c82e78546 100644 --- a/htroot/PeerLoadPicture.java +++ b/htroot/PeerLoadPicture.java @@ -1,13 +1,19 @@ +import java.awt.Color; import java.awt.Image; +import java.util.HashMap; +import java.util.Iterator; import de.anomic.http.httpHeader; import de.anomic.plasma.plasmaGrafics; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.plasma.plasmaGrafics.CircleThreadPiece; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; +import de.anomic.server.serverThread; public class PeerLoadPicture { - - public static Image respond(httpHeader header, serverObjects post, serverSwitch env) { + + public static Image respond(httpHeader header, serverObjects post, serverSwitch env) { int width = 800; int height = 600; @@ -19,11 +25,59 @@ public class PeerLoadPicture { showidle = post.get("showidle", "true").equals("true"); } - //too small values lead to an error, too big to huge CPU/memory consumption, resulting in possible DOS. - if (width < 400 ) width = 400; + final CircleThreadPiece idle = new CircleThreadPiece("Idle", new Color(170, 255, 170)); + final CircleThreadPiece misc = new CircleThreadPiece("Misc.", new Color(190, 50, 180)); + final HashMap /* */ pieces = new HashMap(); + pieces.put(null, idle); + pieces.put(plasmaSwitchboard.CRAWLSTACK, new CircleThreadPiece("Stacking", new Color(115, 200, 210))); + pieces.put(plasmaSwitchboard.INDEXER, new CircleThreadPiece("Parsing/Indexing", new Color(255, 130, 0))); + pieces.put(plasmaSwitchboard.INDEX_DIST, new CircleThreadPiece("DHT-Distribution", new Color(119, 136, 153))); + pieces.put(plasmaSwitchboard.PEER_PING, new CircleThreadPiece("YaCy Core", new Color(255, 230, 160))); + + Iterator threads = env.threadNames(); + String threadname; + serverThread thread; + + long busy_time = 0; + + //Iterate over threads + while (threads.hasNext()) { + threadname = (String)threads.next(); + thread = env.getThread(threadname); + + //count total times + busy_time += thread.getBlockTime(); + busy_time += thread.getExecTime(); + if (showidle) idle.addExecTime(thread.getSleepTime()); + + //count threadgroup-specific times + CircleThreadPiece piece = (CircleThreadPiece)pieces.get(threadname); + if (piece == null) { + misc.addExecTime(thread.getBlockTime()+thread.getExecTime()); + } else { + piece.addExecTime(thread.getBlockTime()+thread.getExecTime()); + } + } + busy_time += idle.getExecTime(); + + // set respective angles + Iterator it = pieces.values().iterator(); + while (it.hasNext()) { + ((CircleThreadPiece)it.next()).setAngle(busy_time); + } + + // too small values lead to an error, too big to huge CPU/memory consumption, + // resulting in possible DOS. + if (width < 400) width = 400; if (width > 1920) width = 1920; if (height < 300) height = 300; if (height > 1440) height = 1440; - return plasmaGrafics.getPeerLoadPicture(5000, width, height, showidle); + return plasmaGrafics.getPeerLoadPicture( + 5000, + width, + height, + (CircleThreadPiece[])pieces.values().toArray(new CircleThreadPiece[pieces.size()]), + misc + ); } } diff --git a/source/de/anomic/plasma/plasmaGrafics.java b/source/de/anomic/plasma/plasmaGrafics.java index 3f7b6e007..41f161f4c 100644 --- a/source/de/anomic/plasma/plasmaGrafics.java +++ b/source/de/anomic/plasma/plasmaGrafics.java @@ -47,12 +47,12 @@ package de.anomic.plasma; import java.awt.Color; import java.awt.Graphics2D; +import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.util.Date; import java.util.Enumeration; import java.util.Iterator; -import de.anomic.server.serverThread; import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacySearch; import de.anomic.yacy.yacySeed; @@ -84,23 +84,32 @@ public class plasmaGrafics { private static final Color COL_NORMAL_TEXT = new Color( 0, 0, 0); private static final Color COL_LOAD_BG = new Color(247, 247, 247); - private static final int CIRCLE_PIECE_COUNT = 6; - private static final String[] CIRCLE_PIECE_NAMES = { - "Idle", - "Stacking", - "Parsing/Indexing", - "DHT-Distribution", - "YaCy Core", - "Misc." - }; - private static final Color[] CIRCLE_PIECE_COLORS = { - new Color(170, 255, 170), - new Color(115, 200, 210), - new Color(255, 130, 0), - new Color(119, 136, 153), - new Color(255, 230, 160), - new Color(190, 50, 180) - }; + public static class CircleThreadPiece { + private final String pieceName; + private final Color color; + private long execTime = 0; + private int angle = 0; + + public CircleThreadPiece(String pieceName, Color color) { + this.pieceName = pieceName; + this.color = color; + } + + public int getAngle() { return this.angle; } + public Color getColor() { return this.color; } + public long getExecTime() { return this.execTime; } + public String getPieceName() { return this.pieceName; } + + public void addExecTime(long execTime) { this.execTime += execTime; } + public void reset() { + this.execTime = 0; + this.angle = 0; + } + public void setExecTime(long execTime) { this.execTime = execTime; } + public void setAngle(long totalBusyTime) { + this.angle = (int)Math.round(360f * ((float)this.execTime / (float)totalBusyTime)); + } + } private static final int LEGEND_BOX_SIZE = 10; @@ -289,84 +298,50 @@ public class plasmaGrafics { } } - public static BufferedImage getPeerLoadPicture(long maxAge, int width, int height, boolean showidle) { + public static BufferedImage getPeerLoadPicture(long maxAge, int width, int height, CircleThreadPiece[] pieces, CircleThreadPiece fillRest) { if ((peerloadPicture == null) || ((System.currentTimeMillis() - peerloadPictureDate) > maxAge)) { - drawPeerLoadPicture(width, height, showidle); + drawPeerLoadPicture(width, height, pieces, fillRest); } return peerloadPicture; } - private static void drawPeerLoadPicture(int width, int height, boolean showidle) { + private static void drawPeerLoadPicture(int width, int height, CircleThreadPiece[] pieces, CircleThreadPiece fillRest) { //prepare image peerloadPicture = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); - Graphics2D g = peerloadPicture.createGraphics(); - g.setBackground(COL_LOAD_BG); - g.clearRect(0,0,width,height); - - plasmaSwitchboard sb = plasmaSwitchboard.getSwitchboard(); - Iterator threads = sb.threadNames(); - String threadname; - serverThread thread; - - long busy_time = 0; - long[] thread_times = new long[CIRCLE_PIECE_COUNT]; - - //Iterate over threads - while (threads.hasNext()) { - threadname = (String)threads.next(); - thread = sb.getThread(threadname); - - //count total times - busy_time += thread.getBlockTime(); - busy_time += thread.getExecTime(); - if(showidle) thread_times[0] += thread.getSleepTime(); - - //count threadgroup-specific times - if(threadname.equals(plasmaSwitchboard.CRAWLSTACK)) { - thread_times[1] += thread.getBlockTime()+thread.getExecTime(); - } else if(threadname.equals(plasmaSwitchboard.INDEXER)) { - thread_times[2] = thread.getBlockTime()+thread.getExecTime(); - } else if(threadname.equals(plasmaSwitchboard.INDEX_DIST)) { - thread_times[3] = thread.getBlockTime()+thread.getExecTime(); - } else if(threadname.equals(plasmaSwitchboard.PEER_PING)) { - thread_times[4] = thread.getBlockTime()+thread.getExecTime(); - } else { - thread_times[5] += thread.getBlockTime()+thread.getExecTime(); - } - } - - int[] piece_angles = new int[CIRCLE_PIECE_COUNT]; - //calculate angles - for(int i=0;i