Skip to main content
aboutsummaryrefslogblamecommitdiffstats
blob: 3d8c1eeb5b2e69ee96c18dd9f16cca17ca4b0b49 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12











                                                                                 
                    









                                                            
                            

                               
                                 
 

                                                                                                                 
                                 

                                         
                                     



                             
                                                                 



                                                              
                                                                     





                                                                                             





                                                            
                              



                                                   







                                             
 
/*******************************************************************************
 * Copyright (c) 2013 Red Hat Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.perf;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * This class handles the execution of the perf stat command
 * and stores the resulting data.
 */
public class StatData extends AbstractDataManipulator {

	private String prog;
	private String [] args;
	private int runCount;
	private String [] events;

	public StatData(String title, File workDir, String prog, String [] args, int runCount, String[] events) {
		super(title, workDir);
		this.prog = prog;
		this.args = args;
		this.runCount = runCount;
		this.events = events;
	}

	@Override
	public void parse() {
		String [] cmd = getCommand(this.prog, this.args);
		// perf stat prints the data to standard error
		performCommand(cmd, 2);
	}

	protected String [] getCommand(String prog, String [] args) {
		List<String> ret = new ArrayList<String>(Arrays.asList(
				new String[] {"perf", "stat" })); //$NON-NLS-1$ //$NON-NLS-2$
		if (runCount > 1) {
			ret.add("-r"); //$NON-NLS-1$
			ret.add(String.valueOf(runCount));
		}
		if (events != null) {
			for (String event : events) {
				ret.add("-e"); //$NON-NLS-1$
				ret.add(event);
			}
		}
		ret.add(prog);
		ret.addAll(Arrays.asList(args));
		return ret.toArray(new String [0]);
	}

	protected String getProgram () {
		return prog;
	}

	protected String [] getArguments () {
		return args;
	}

}

Back to the top