package BoxTools; /* A PAPI wrapper class that also works on non-PAPI systems */ public class PAPIWrapper { private PAPICounter c; private void disable(PAPIException exn) { Util.printErrMsg("PAPIWrapper counter failure ("+exn+")- counter disabled"); c = null; } public PAPIWrapper(int event) { try { c = new PAPICounter(event); c.start(); c.stop(); c.clear(); } catch (PAPIException exn) { disable(exn); } } public inline long getCounterValue() { if (c != null) { try { return c.getCounterValue(); } catch (PAPIException exn) { disable(exn); } } return 0; } public inline void start() { if (c != null) { try { c.start(); } catch (PAPIException exn) { disable(exn); } } } public inline void stop() { if (c != null) { try { c.stop(); } catch (PAPIException exn) { disable(exn); } } } public inline void clear() { if (c != null) { try { c.clear(); } catch (PAPIException exn) { disable(exn); } } } }