001: // plasmaProfiling.java
002: // (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
003: // first published 04.12.2007 on http://yacy.net
004: //
005: // This is a part of YaCy, a peer-to-peer based web search engine
006: //
007: // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
008: // $LastChangedRevision: 1986 $
009: // $LastChangedBy: orbiter $
010: //
011: // LICENSE
012: //
013: // This program is free software; you can redistribute it and/or modify
014: // it under the terms of the GNU General Public License as published by
015: // the Free Software Foundation; either version 2 of the License, or
016: // (at your option) any later version.
017: //
018: // This program is distributed in the hope that it will be useful,
019: // but WITHOUT ANY WARRANTY; without even the implied warranty of
020: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
021: // GNU General Public License for more details.
022: //
023: // You should have received a copy of the GNU General Public License
024: // along with this program; if not, write to the Free Software
025: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
026:
027: package de.anomic.plasma;
028:
029: import java.util.ConcurrentModificationException;
030: import java.util.Iterator;
031:
032: import de.anomic.server.serverProfiling;
033: import de.anomic.server.serverProfiling.Event;
034: import de.anomic.yacy.yacyCore;
035: import de.anomic.ymage.ymageChart;
036: import de.anomic.ymage.ymageMatrix;
037:
038: public class plasmaProfiling {
039:
040: private static ymageChart bufferChart = null;
041:
042: public static long lastPPMUpdate = System.currentTimeMillis() - 30000;
043:
044: public static void updateIndexedPage(
045: plasmaSwitchboardQueue.Entry entry) {
046: if (System.currentTimeMillis() - lastPPMUpdate > 30000) {
047: // we don't want to do this too often
048: yacyCore.peerActions.updateMySeed();
049: serverProfiling.update("ppm", new Long(yacyCore.seedDB
050: .mySeed().getPPM()));
051: lastPPMUpdate = System.currentTimeMillis();
052: }
053: serverProfiling.update("indexed", entry.url().toNormalform(
054: true, false));
055: }
056:
057: public static long maxPayload(String eventname, long min) {
058: Iterator<Event> i = serverProfiling.history(eventname);
059: serverProfiling.Event event;
060: long max = min, l;
061: while (i.hasNext()) {
062: event = i.next();
063: l = ((Long) event.payload).longValue();
064: if (l > max)
065: max = l;
066: }
067: return max;
068: }
069:
070: public static ymageMatrix performanceGraph(int width, int height) {
071: // find maximum values for automatic graph dimension adoption
072: int maxppm = (int) maxPayload("ppm", 25);
073: long maxbytes = maxPayload("memory", 110 * 1024 * 1024);
074:
075: // declare graph and set dimensions
076: int leftborder = 30;
077: int rightborder = 30;
078: int topborder = 20;
079: int bottomborder = 20;
080: int leftscale = 20;
081: int rightscale = 100;
082: int bottomscale = 60;
083: int vspace = height - topborder - bottomborder;
084: int hspace = width - leftborder - rightborder;
085: int maxtime = 600;
086: ymageChart chart = new ymageChart(width, height, "FFFFFF",
087: "000000", leftborder, rightborder, topborder,
088: bottomborder,
089: "PEER PERFORMANCE GRAPH: PAGES/MINUTE and USED MEMORY");
090: chart.declareDimension(ymageChart.DIMENSION_BOTTOM,
091: bottomscale, hspace / (maxtime / bottomscale),
092: -maxtime, "000000", "CCCCCC", "TIME/SECONDS");
093: chart.declareDimension(ymageChart.DIMENSION_LEFT, leftscale,
094: vspace * leftscale / maxppm, 0, "008800", null,
095: "PPM [PAGES/MINUTE]");
096: chart.declareDimension(ymageChart.DIMENSION_RIGHT, rightscale,
097: vspace * rightscale / (int) (maxbytes / 1024 / 1024),
098: 0, "0000FF", "CCCCCC", "MEMORY/MEGABYTE");
099:
100: // draw ppm
101: Iterator<Event> i = serverProfiling.history("ppm");
102: long time, now = System.currentTimeMillis(), bytes;
103: int x0 = 1, x1, y0 = 0, y1, ppm;
104: serverProfiling.Event event;
105: try {
106: while (i.hasNext()) {
107: event = i.next();
108: time = event.time - now;
109: ppm = (int) ((Long) event.payload).longValue();
110: x1 = (int) (time / 1000);
111: y1 = ppm;
112: chart.setColor("228822");
113: chart.chartDot(ymageChart.DIMENSION_BOTTOM,
114: ymageChart.DIMENSION_LEFT, x1, y1, 2);
115: chart.setColor("008800");
116: if (x0 < 0)
117: chart.chartLine(ymageChart.DIMENSION_BOTTOM,
118: ymageChart.DIMENSION_LEFT, x0, y0, x1, y1);
119: x0 = x1;
120: y0 = y1;
121: }
122:
123: // draw memory
124: i = serverProfiling.history("memory");
125: x0 = 1;
126: while (i.hasNext()) {
127: event = (serverProfiling.Event) i.next();
128: time = event.time - now;
129: bytes = ((Long) event.payload).longValue();
130: x1 = (int) (time / 1000);
131: y1 = (int) (bytes / 1024 / 1024);
132: chart.setColor("AAAAFF");
133: chart.chartDot(ymageChart.DIMENSION_BOTTOM,
134: ymageChart.DIMENSION_RIGHT, x1, y1, 2);
135: chart.setColor("0000FF");
136: if (x0 < 0)
137: chart.chartLine(ymageChart.DIMENSION_BOTTOM,
138: ymageChart.DIMENSION_RIGHT, x0, y0, x1, y1);
139: x0 = x1;
140: y0 = y1;
141: }
142: bufferChart = chart;
143: } catch (ConcurrentModificationException cme) {
144: chart = bufferChart;
145: }
146:
147: return chart;
148: }
149:
150: public static class searchEvent {
151: public String queryID, processName;
152: public long duration;
153: public int resultCount;
154:
155: public searchEvent(String queryID, String processName,
156: int resultCount, long duration) {
157: this.queryID = queryID;
158: this.processName = processName;
159: this.resultCount = resultCount;
160: this.duration = duration;
161: }
162: }
163:
164: }
|