From bd992e2e922b4a5f0df7f819f958d69ba6878302 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Mon, 25 Apr 2011 03:12:05 +0000 Subject: [PATCH] - added stats collecting code --- .../internal/core/CheckersTimeStats.java | 135 ++++++++++++++++++ .../cdt/codan/internal/core/CodanBuilder.java | 20 +-- 2 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersTimeStats.java diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersTimeStats.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersTimeStats.java new file mode 100644 index 00000000000..61d3c4dae25 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersTimeStats.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * Copyright (c) 2009,2010 QNX Software Systems + * 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: + * QNX Software Systems (Alena Laskavaia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.internal.core; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * Class to collect time states for checkers runs + */ +public class CheckersTimeStats { + public static final String ALL = "ALL"; //$NON-NLS-1$ + public static final String ELAPSED = "ELAPSED"; //$NON-NLS-1$ + private static CheckersTimeStats instance = new CheckersTimeStats(); + + /** + * @return global instance of stats + */ + public static CheckersTimeStats getInstance() { + return instance; + } + + private static class TimeRecord { + private long duration; + private long current; + private int count; + + public void start() { + current = System.currentTimeMillis(); + } + + public void stop() { + count++; + duration += System.currentTimeMillis() - current; + current = 0; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + if (count != 0) + return duration + " " + count + " " + duration / count; //$NON-NLS-1$//$NON-NLS-2$ + return ""; //$NON-NLS-1$ + } + } + private Map records = new HashMap(); + + /** + * @param id - checker id + * @return + */ + private TimeRecord getTimeRecord(String id) { + TimeRecord record = records.get(id); + if (record == null) { + record = new TimeRecord(); + records.put(id, record); + } + return record; + } + + /** + * Start measuring elapsed time for checker with given id + * + * @param id + */ + public void checkerStart(String id) { + checkerStart(id, ELAPSED); + } + + /** + * Start measuring elapsed time for checker with given id and counter + * + * @param id + * @param counter + */ + public void checkerStart(String id, String counter) { + TimeRecord record = getTimeRecord(id + ":" + counter); //$NON-NLS-1$ + record.start(); + } + + /** + * @param id + * @param counter + */ + public void checkerStop(String id, String counter) { + getTimeRecord(id + ":" + counter).stop(); //$NON-NLS-1$ + } + + /** + * @param id + */ + public void checkerStop(String id) { + checkerStop(id, ELAPSED); + } + + /** + * + */ + public void traceStats() { + // TODO: add check for trace flags + printStats(); + } + + /** + * + */ + public void printStats() { + System.out.println("---"); //$NON-NLS-1$ + for (Iterator iterator = records.keySet().iterator(); iterator.hasNext();) { + String id = iterator.next(); + TimeRecord timeRecord = getTimeRecord(id); + System.out.println(timeRecord.toString() + " " + id); //$NON-NLS-1$ + } + } + + /** + * + */ + public void reset() { + records.clear(); + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java index 1aa940b9c19..fa8725da9c9 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java @@ -129,6 +129,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui // System.err.println("processing " + resource); monitor.beginTask(Messages.CodanBuilder_Code_Analysis_On + resource, checkers + memsize * tick); try { + CheckersTimeStats.getInstance().checkerStart(CheckersTimeStats.ALL); ICheckerInvocationContext context = new CheckerInvocationContext(resource); try { for (IChecker checker : chegistry) { @@ -142,15 +143,16 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui try { checker.before(resource); if (chegistry.isCheckerEnabled(checker, resource)) { - //long time = System.currentTimeMillis(); - if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) { - ((IRunnableInEditorChecker) checker).processModel(model, context); - } else { - checker.processResource(resource, context); + try { + CheckersTimeStats.getInstance().checkerStart(checker.getClass().getName()); + if (checkerLaunchMode == CheckerLaunchMode.RUN_AS_YOU_TYPE) { + ((IRunnableInEditorChecker) checker).processModel(model, context); + } else { + checker.processResource(resource, context); + } + } finally { + CheckersTimeStats.getInstance().checkerStop(checker.getClass().getName()); } - // System.err.println("Checker " - // + checker.getClass() + " worked " - // + (System.currentTimeMillis() - time)); } } finally { checker.after(resource); @@ -166,6 +168,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui } } finally { context.dispose(); + CheckersTimeStats.getInstance().checkerStop(CheckersTimeStats.ALL); + //CheckersTimeStats.getInstance().printStats(); } if (resource instanceof IContainer && (checkerLaunchMode == CheckerLaunchMode.RUN_ON_FULL_BUILD || checkerLaunchMode == CheckerLaunchMode.RUN_ON_DEMAND)) {