@Override public void open(IPath file) { File statFile = file.toFile(); try (BufferedReader fileReader = new BufferedReader(new FileReader(statFile))) { final StringBuilder contents = new StringBuilder(); final StringBuilder title = new StringBuilder(); String line; // read file contents while ((line = fileReader.readLine()) != null) { // set data title if (title.length() == 0 && line.contains(TITLE_EXCERPT)) { title.append(line); } contents.append(line); contents.append("\n"); // $NON-NLS-1$ } // construct basic title if none was found in the file if (title.length() == 0) { title.append(NLS.bind(Messages.PerfEditorLauncher_stat_title, statFile.getName())); } final String timestamp = DateFormat.getInstance().format(new Date(statFile.lastModified())); PerfPlugin.getDefault() .setStatData( new IPerfData() { @Override public String getTitle() { return title.toString() + " (" + timestamp + ")"; // $NON-NLS-1$ //$NON-NLS-2$ } @Override public String getPerfData() { return contents.toString(); } }); StatView.refreshView(); } catch (FileNotFoundException e) { PerfPlugin.getDefault() .openError(e, NLS.bind(Messages.PerfEditorLauncher_file_dne_error, statFile.getName())); } catch (IOException e) { PerfPlugin.getDefault() .openError(e, NLS.bind(Messages.PerfEditorLauncher_file_read_error, statFile.getName())); } }
/** * Show statistics view. * * @param config launch configuration * @param launch launch * @throws CoreException */ private void showStat(ILaunchConfiguration config, ILaunch launch) throws CoreException { // Build the command line string String arguments[] = getProgramArgumentsArray(config); // Get working directory int runCount = config.getAttribute(PerfPlugin.ATTR_StatRunCount, PerfPlugin.ATTR_StatRunCount_default); StringBuffer args = new StringBuffer(); for (String arg : arguments) { args.append(arg); args.append(" "); // $NON-NLS-1$ } URI binURI = null; try { binURI = new URI(binPath.toPortableString()); } catch (URISyntaxException e) { MessageDialog.openError( Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError); } Object[] titleArgs = new Object[] {binURI.getPath(), args.toString(), String.valueOf(runCount)}; String title = renderProcessLabel( MessageFormat.format(Messages.PerfLaunchConfigDelegate_stat_title, titleArgs)); List<String> configEvents = config.getAttribute(PerfPlugin.ATTR_SelectedEvents, PerfPlugin.ATTR_SelectedEvents_default); String[] statEvents = new String[] {}; if (!config.getAttribute(PerfPlugin.ATTR_DefaultEvent, PerfPlugin.ATTR_DefaultEvent_default)) { // gather selected events statEvents = (configEvents == null) ? statEvents : configEvents.toArray(new String[] {}); } StatData sd = new StatData( title, workingDirPath, binURI.getPath(), arguments, runCount, statEvents, project); sd.setLaunch(launch); sd.parse(); PerfPlugin.getDefault().setStatData(sd); sd.updateStatData(); StatView.refreshView(); }