// Path: src/org/bootchart/common/DiskTPutSample.java
// public class DiskTPutSample extends Sample {
// 	/** Read throughput (KB/s). */
// 	public double read;
// 	/** Write throughput (KB/s). */
// 	public double write;
// 	
// 	/**
// 	 * Creates a new sample.
// 	 * 
// 	 * @param time   sample time
// 	 * @param read   read throughput
// 	 * @param write  write throughput
// 	 */
// 	public DiskTPutSample(Date time, double read, double write) {
// 		this.time = time != null ? new Date(time.getTime()) : null;
// 		this.read = read;
// 		this.write = write;
// 	}
// 	
// 	/**
// 	 * Returns the string representation of the sample.
// 	 * 
// 	 * @return  string representation
// 	 */
// 	public String toString() {
// 		return TIME_FORMAT.format(time) + "\t" + read + "\t" + write;
// 	}
// }
// 
// Path: src/org/bootchart/common/NetDevTPutSample.java
// public class NetDevTPutSample extends DiskTPutSample {
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * @see org.bootchart.common.DiskTPutSample#DiskTPutSample(java.util.Date, double, double)
// 	 */
// 	public NetDevTPutSample(Date time, double read, double write) {
// 		super(time, read, write);
// 	}
// }
// 
// Path: src/org/bootchart/common/Stats.java
// public class Stats {
// 	/** A list of statistics samples. */
// 	private List samples;
// 	
// 	/**
// 	 * Creates a new  statistics instance.
// 	 */
// 	public Stats() {
// 		samples = new ArrayList();
// 	}
// 
// 	/**
// 	 * Adds a new statistics sample.
// 	 * 
// 	 * @param sample  statistics sample to add
// 	 */
// 	public void addSample(Sample sample) {
// 		samples.add(sample);
// 	}
// 	
// 	/**
// 	 * Returns a list of statistics samples.
// 	 * 
// 	 * @return  a list statistics samples
// 	 */
// 	public List getSamples() {
// 		return samples;
// 	}
// }


import org.bootchart.common.NetDevTPutSample;
import org.bootchart.common.Stats;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Logger;
import org.bootchart.common.Common;
import org.bootchart.common.DiskTPutSample;
/*
 * Bootchart -- Boot Process Visualization
 *
 * Copyright (C) 2006  Ziga Mahkovec <ziga.mahkovec@klika.si>
 *
 * 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.
 */
package org.bootchart.parser.linux;




/**
 * ProcNetDev parses log files produced by logging the output of
 * <code>/proc/net/dev</code>.  The samples contain information about network
 * interface throughput, which is used for IO throughput on diskless network
 * stations.
 */
public class ProcNetDevParser {
	private static final Logger log = Logger.getLogger(ProcNetDevParser.class.getName());

	/** NetDevSample encapsulates a /proc/net/dev sample. */
	private static class NetDevSample {
		long[] values  = new long[2]; // {rbytes, wbytes}
		long[] changes = new long[2]; // {rbytes, wbytes}
	}
	
	/**
	 * Parses the <code>proc_netdev.log</code> file.  The output from
	 * <code>/proc/net/dev</code> is used to collect the network interface
	 * statistics, which is returned as disk throughput statistics.
	 * 
	 * @param is      the input stream to read from
	 * @return        disk statistics {@link DiskTPutSample} samples)
	 * @throws IOException  if an I/O error occurs
	 */
	public static Stats parseLog(InputStream is)
		throws IOException {
		BufferedReader reader = Common.getReader(is);
		String line = reader.readLine();

		int numSamples = 0;
		Stats diskStats = new Stats();
		// last time
		Date ltime = null;
		// a map of /proc/diskstat values for each disk
		Map diskStatMap = new HashMap();
		
		while (line != null) {
			// skip empty lines
// Path: src/org/bootchart/common/DiskTPutSample.java
// public class DiskTPutSample extends Sample {
// 	/** Read throughput (KB/s). */
// 	public double read;
// 	/** Write throughput (KB/s). */
// 	public double write;
// 	
// 	/**
// 	 * Creates a new sample.
// 	 * 
// 	 * @param time   sample time
// 	 * @param read   read throughput
// 	 * @param write  write throughput
// 	 */
// 	public DiskTPutSample(Date time, double read, double write) {
// 		this.time = time != null ? new Date(time.getTime()) : null;
// 		this.read = read;
// 		this.write = write;
// 	}
// 	
// 	/**
// 	 * Returns the string representation of the sample.
// 	 * 
// 	 * @return  string representation
// 	 */
// 	public String toString() {
// 		return TIME_FORMAT.format(time) + "\t" + read + "\t" + write;
// 	}
// }
// 
// Path: src/org/bootchart/common/NetDevTPutSample.java
// public class NetDevTPutSample extends DiskTPutSample {
// 
// 	/*
// 	 * (non-Javadoc)
// 	 * @see org.bootchart.common.DiskTPutSample#DiskTPutSample(java.util.Date, double, double)
// 	 */
// 	public NetDevTPutSample(Date time, double read, double write) {
// 		super(time, read, write);
// 	}
// }
// 
// Path: src/org/bootchart/common/Stats.java
// public class Stats {
// 	/** A list of statistics samples. */
// 	private List samples;
// 	
// 	/**
// 	 * Creates a new  statistics instance.
// 	 */
// 	public Stats() {
// 		samples = new ArrayList();
// 	}
// 
// 	/**
// 	 * Adds a new statistics sample.
// 	 * 
// 	 * @param sample  statistics sample to add
// 	 */
// 	public void addSample(Sample sample) {
// 		samples.add(sample);
// 	}
// 	
// 	/**
// 	 * Returns a list of statistics samples.
// 	 * 
// 	 * @return  a list statistics samples
// 	 */
// 	public List getSamples() {
// 		return samples;
// 	}
// }


// Path: src/org/bootchart/parser/linux/ProcNetDevParser.java
import org.bootchart.common.NetDevTPutSample;
import org.bootchart.common.Stats;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Logger;
import org.bootchart.common.Common;
import org.bootchart.common.DiskTPutSample;

/*
 * Bootchart -- Boot Process Visualization
 *
 * Copyright (C) 2006  Ziga Mahkovec <ziga.mahkovec@klika.si>
 *
 * 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.
 */
package org.bootchart.parser.linux;




/**
 * ProcNetDev parses log files produced by logging the output of
 * <code>/proc/net/dev</code>.  The samples contain information about network
 * interface throughput, which is used for IO throughput on diskless network
 * stations.
 */
public class ProcNetDevParser {
	private static final Logger log = Logger.getLogger(ProcNetDevParser.class.getName());

	/** NetDevSample encapsulates a /proc/net/dev sample. */
	private static class NetDevSample {
		long[] values  = new long[2]; // {rbytes, wbytes}
		long[] changes = new long[2]; // {rbytes, wbytes}
	}
	
	/**
	 * Parses the <code>proc_netdev.log</code> file.  The output from
	 * <code>/proc/net/dev</code> is used to collect the network interface
	 * statistics, which is returned as disk throughput statistics.
	 * 
	 * @param is      the input stream to read from
	 * @return        disk statistics {@link DiskTPutSample} samples)
	 * @throws IOException  if an I/O error occurs
	 */
	public static Stats parseLog(InputStream is)
		throws IOException {
		BufferedReader reader = Common.getReader(is);
		String line = reader.readLine();

		int numSamples = 0;
		Stats diskStats = new Stats();
		// last time
		Date ltime = null;
		// a map of /proc/diskstat values for each disk
		Map diskStatMap = new HashMap();
		
		while (line != null) {
			// skip empty lines
			while (line != null && line.trim().length() == 0) {