org.bootchart.parser.linux
Class TopParser

java.lang.Object
  extended byorg.bootchart.parser.linux.TopParser

public class TopParser
extends java.lang.Object

TopParser parses log files produced by top. The log files are produced when running top in batch mode.


Nested Class Summary
static class TopParser.TopStats
          Top statistics.
 
Field Summary
static java.util.List EXIT_PROCESS_LIST
          Default boot completion process list.
 
Constructor Summary
TopParser()
           
 
Method Summary
static int correctTimes(Stats stats)
          Corrects sampling times.
static int getState(java.util.Map procInfo)
          Returns the process state.
static TopParser.TopStats parseLog(java.io.BufferedReader reader, java.util.Map pidNameMap, java.util.Map forkMap)
          Parses the top log file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXIT_PROCESS_LIST

public static final java.util.List EXIT_PROCESS_LIST
Default boot completion process list. The top log file is parsed up to the point where one of these processes are running and the system is mostly idle.

Constructor Detail

TopParser

public TopParser()
Method Detail

parseLog

public static TopParser.TopStats parseLog(java.io.BufferedReader reader,
                                          java.util.Map pidNameMap,
                                          java.util.Map forkMap)
                                   throws java.io.IOException,
                                          java.text.ParseException
Parses the top log file. Consecutive top samples are parsed and returned in a list. The top samples are only parsed up to the point where the specified exitProcess is running and the system is idle.

Sensible exitProcess values are "mingetty" (for runlevel 3 boots), "gdmgreeter" (for analyzing till the GDM login) and "gnome-panel" (for analyzing the gnome login as well).

If pidNameMap is set, it is used to map PIDs to command names. This useful when init scripts are sourced, and thus top is unable to report the proper process name. A sysinit modification is necessary to generate the mapping log file.

forkMap is an optional map that provides detailed information on process forking.

Parameters:
reader - the reader to read from
pidNameMap - PID to name mapping map (optional)
forkMap - process forking map (optional)
Returns:
top statistics, which includes CPU statistics and a list of processes
Throws:
java.io.IOException - if an I/O error occurs
java.text.ParseException - if the log file is not properly formatted

getState

public static int getState(java.util.Map procInfo)
Returns the process state. State can be one of:

Parameters:
procInfo - top info map
Returns:
process state

correctTimes

public static int correctTimes(Stats stats)
Corrects sampling times. The system clock might be set *during* sample collection, so time skew is possible (in terms of hours because of time zone correction and in terms of seconds because of out of sync clocks. That's why we use the first few samples to estimate the sampling period and apply it whenever time skew occurs.

The sample time resolution is also increased if necessary.

Parameters:
stats - the statistics to correct times for
Returns:
sampling period estimation