2007-12-04 21:19:13 +01:00
// plasmaProfiling.java
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 04.12.2007 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
// $LastChangedRevision: 1986 $
// $LastChangedBy: orbiter $
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2009-07-19 22:37:44 +02:00
package de.anomic.ymage ;
2007-12-04 21:19:13 +01:00
2007-12-18 16:59:35 +01:00
import java.util.ConcurrentModificationException ;
2007-12-04 21:19:13 +01:00
import java.util.Iterator ;
import de.anomic.server.serverProfiling ;
2008-01-19 01:40:19 +01:00
import de.anomic.server.serverProfiling.Event ;
2007-12-04 21:19:13 +01:00
2009-07-19 22:37:44 +02:00
public class ProfilingGraph {
2007-12-18 16:59:35 +01:00
private static ymageChart bufferChart = null ;
2007-12-04 21:19:13 +01:00
2008-08-02 14:12:04 +02:00
public static long maxPayload ( final String eventname , final long min ) {
final Iterator < Event > i = serverProfiling . history ( eventname ) ;
2007-12-04 21:19:13 +01:00
serverProfiling . Event event ;
long max = min , l ;
while ( i . hasNext ( ) ) {
2008-01-19 01:40:19 +01:00
event = i . next ( ) ;
2007-12-04 21:19:13 +01:00
l = ( ( Long ) event . payload ) . longValue ( ) ;
if ( l > max ) max = l ;
}
return max ;
}
2008-08-02 14:12:04 +02:00
public static ymageMatrix performanceGraph ( final int width , final int height , final String subline ) {
2007-12-04 21:19:13 +01:00
// find maximum values for automatic graph dimension adoption
2008-08-02 14:12:04 +02:00
final int maxppm = ( int ) maxPayload ( " ppm " , 25 ) ;
2008-10-03 20:57:02 +02:00
final int maxwords = ( int ) maxPayload ( " wordcache " , 12000 ) ;
2008-08-02 14:12:04 +02:00
final long maxbytes = maxPayload ( " memory " , 110 * 1024 * 1024 ) ;
2009-01-30 19:53:51 +01:00
final int maxmbytes = ( int ) ( maxbytes / 1024 / 1024 ) ;
2007-12-04 21:19:13 +01:00
// declare graph and set dimensions
2008-08-02 14:12:04 +02:00
final int leftborder = 30 ;
final int rightborder = 30 ;
final int topborder = 20 ;
final int bottomborder = 20 ;
2009-02-15 18:36:13 +01:00
final int leftscale ; if ( maxwords > 150000 ) leftscale = maxwords / 150000 * 20000 ; else leftscale = 10000 ;
final int rightscale ; if ( maxmbytes > 1500 ) rightscale = maxmbytes / 1500 * 200 ; else rightscale = 100 ;
2009-04-24 15:18:20 +02:00
final int anotscale = 1000 ;
2008-08-02 14:12:04 +02:00
final int bottomscale = 60 ;
final int vspace = height - topborder - bottomborder ;
final int hspace = width - leftborder - rightborder ;
final int maxtime = 600 ;
2008-08-04 12:47:26 +02:00
ymageChart chart = new ymageChart ( width , height , " FFFFFF " , " 000000 " , " AAAAAA " , leftborder , rightborder , topborder , bottomborder , " YACY PEER PERFORMANCE: MAIN MEMORY, WORD CACHE AND PAGES/MINUTE (PPM) " , subline ) ;
2007-12-07 03:15:12 +01:00
chart . declareDimension ( ymageChart . DIMENSION_BOTTOM , bottomscale , hspace / ( maxtime / bottomscale ) , - maxtime , " 000000 " , " CCCCCC " , " TIME/SECONDS " ) ;
2008-10-03 20:57:02 +02:00
chart . declareDimension ( ymageChart . DIMENSION_LEFT , leftscale , vspace * leftscale / maxwords , 0 , " 008800 " , null , " INDEXING, WORDS IN CACHE " ) ;
2009-01-30 19:53:51 +01:00
chart . declareDimension ( ymageChart . DIMENSION_RIGHT , rightscale , vspace * rightscale / maxmbytes , 0 , " 0000FF " , " CCCCCC " , " MEMORY/MEGABYTE " ) ;
2008-10-10 00:31:43 +02:00
chart . declareDimension ( ymageChart . DIMENSION_ANOT0 , anotscale , vspace * anotscale / maxppm , 0 , " 008800 " , null , " PPM [PAGES/MINUTE] " ) ;
chart . declareDimension ( ymageChart . DIMENSION_ANOT1 , vspace / 6 , vspace / 6 , 0 , " 888800 " , null , " URL " ) ;
2007-12-04 21:19:13 +01:00
2008-08-04 12:47:26 +02:00
// draw chart
2008-08-02 14:12:04 +02:00
long time ;
2008-08-02 15:57:00 +02:00
final long now = System . currentTimeMillis ( ) ;
long bytes ;
2008-10-10 00:31:43 +02:00
int x0 , x1 , y0 , y1 , ppm , words ;
2007-12-04 21:19:13 +01:00
serverProfiling . Event event ;
2007-12-18 16:59:35 +01:00
try {
2008-10-10 00:31:43 +02:00
// draw urls
/ *
Iterator < Event > i = serverProfiling . history ( " indexed " ) ;
x0 = 1 ; y0 = 0 ;
while ( i . hasNext ( ) ) {
event = i . next ( ) ;
time = event . time - now ;
x1 = ( int ) ( time / 1000 ) ;
y1 = ppm ;
chart . setColor ( " AA8888 " ) ;
if ( x0 < 0 ) chart . chartLine ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_ANOT0 , x0 , y0 , x1 , y1 ) ;
chart . setColor ( " AA2222 " ) ;
chart . chartDot ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_ANOT0 , x1 , y1 , 2 , ( ( String ) event . payload ) , 315 ) ;
x0 = x1 ; y0 = y1 ;
}
* /
2008-08-04 12:47:26 +02:00
// draw memory
Iterator < Event > i = serverProfiling . history ( " memory " ) ;
2008-10-10 00:31:43 +02:00
x0 = 1 ; y0 = 0 ;
2007-12-18 16:59:35 +01:00
while ( i . hasNext ( ) ) {
2008-01-19 01:40:19 +01:00
event = i . next ( ) ;
2007-12-18 16:59:35 +01:00
time = event . time - now ;
2008-08-04 12:47:26 +02:00
bytes = ( ( Long ) event . payload ) . longValue ( ) ;
2007-12-18 16:59:35 +01:00
x1 = ( int ) ( time / 1000 ) ;
2008-08-04 12:47:26 +02:00
y1 = ( int ) ( bytes / 1024 / 1024 ) ;
chart . setColor ( " AAAAFF " ) ;
2008-10-10 00:31:43 +02:00
chart . chartDot ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_RIGHT , x1 , y1 , 2 , null , 0 ) ;
2008-08-04 12:47:26 +02:00
chart . setColor ( " 0000FF " ) ;
if ( x0 < 0 ) chart . chartLine ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_RIGHT , x0 , y0 , x1 , y1 ) ;
x0 = x1 ; y0 = y1 ;
}
// draw wordcache
i = serverProfiling . history ( " wordcache " ) ;
x0 = 1 ; y0 = 0 ;
while ( i . hasNext ( ) ) {
event = i . next ( ) ;
time = event . time - now ;
words = ( int ) ( ( Long ) event . payload ) . longValue ( ) ;
x1 = ( int ) ( time / 1000 ) ;
y1 = words ;
2007-12-18 16:59:35 +01:00
chart . setColor ( " 228822 " ) ;
2008-10-10 00:31:43 +02:00
chart . chartDot ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_LEFT , x1 , y1 , 2 , null , 315 ) ;
2007-12-18 16:59:35 +01:00
chart . setColor ( " 008800 " ) ;
if ( x0 < 0 ) chart . chartLine ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_LEFT , x0 , y0 , x1 , y1 ) ;
x0 = x1 ; y0 = y1 ;
}
2008-08-04 12:47:26 +02:00
// draw ppm
i = serverProfiling . history ( " ppm " ) ;
x0 = 1 ; y0 = 0 ;
2007-12-18 16:59:35 +01:00
while ( i . hasNext ( ) ) {
2008-06-06 18:01:27 +02:00
event = i . next ( ) ;
2007-12-18 16:59:35 +01:00
time = event . time - now ;
2008-08-04 12:47:26 +02:00
ppm = ( int ) ( ( Long ) event . payload ) . longValue ( ) ;
2007-12-18 16:59:35 +01:00
x1 = ( int ) ( time / 1000 ) ;
2008-08-04 12:47:26 +02:00
y1 = ppm ;
chart . setColor ( " AA8888 " ) ;
2008-10-10 00:31:43 +02:00
if ( x0 < 0 ) chart . chartLine ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_ANOT0 , x0 , y0 , x1 , y1 ) ;
2008-08-04 12:47:26 +02:00
chart . setColor ( " AA2222 " ) ;
2008-10-10 00:31:43 +02:00
chart . chartDot ( ymageChart . DIMENSION_BOTTOM , ymageChart . DIMENSION_ANOT0 , x1 , y1 , 2 , ppm + " PPM " , 0 ) ;
2007-12-18 16:59:35 +01:00
x0 = x1 ; y0 = y1 ;
}
2008-08-04 12:47:26 +02:00
2007-12-18 16:59:35 +01:00
bufferChart = chart ;
2008-08-02 14:12:04 +02:00
} catch ( final ConcurrentModificationException cme ) {
2007-12-18 16:59:35 +01:00
chart = bufferChart ;
2007-12-04 21:19:13 +01:00
}
2007-12-07 03:15:12 +01:00
return chart ;
2007-12-04 21:19:13 +01:00
}
public static class searchEvent {
public String queryID , processName ;
public long duration ;
public int resultCount ;
2008-08-02 14:12:04 +02:00
public searchEvent ( final String queryID , final String processName , final int resultCount , final long duration ) {
2007-12-04 21:19:13 +01:00
this . queryID = queryID ;
this . processName = processName ;
this . resultCount = resultCount ;
this . duration = duration ;
}
}
}