Package org.h2.util

Examples of org.h2.util.Profiler


            field.set(b);
        }
    }

    private void testByteOperations() {
        BitField used = new BitField();
        testSetFast(used, false);
        testSetFast(used, true);
    }
View Full Code Here


            }
        }
    }

    private void testRandom() {
        BitField bits = new BitField();
        BitSet set = new BitSet();
        int max = 300;
        int count = 100000;
        Random random = new Random(1);
        for (int i = 0; i < count; i++) {
            int idx = random.nextInt(max);
            if (random.nextBoolean()) {
                if (random.nextBoolean()) {
                    bits.set(idx);
                    set.set(idx);
                } else {
                    bits.clear(idx);
                    set.clear(idx);
                }
            } else {
                assertEquals(set.get(idx), bits.get(idx));
                assertEquals(set.nextClearBit(idx), bits.nextClearBit(idx));
                assertEquals(set.length(), bits.length());
            }
        }
    }
View Full Code Here

            }
        }
    }

    private void testGetSet() {
        BitField bits = new BitField();
        for (int i = 0; i < 10000; i++) {
            bits.set(i);
            if (!bits.get(i)) {
                fail("not set: " + i);
            }
            if (bits.get(i + 1)) {
                fail("set: " + i);
            }
        }
        for (int i = 0; i < 10000; i++) {
            if (!bits.get(i)) {
                fail("not set: " + i);
            }
        }
        for (int i = 0; i < 1000; i++) {
            int k = bits.nextClearBit(0);
            if (k != 10000) {
                fail("" + k);
            }
        }
    }
View Full Code Here

            }
        }
    }

    private void testRandomSetRange() {
        BitField bits = new BitField();
        BitSet set = new BitSet();
        Random random = new Random(1);
        int maxOffset = 500;
        int maxLen = 500;
        int total = maxOffset + maxLen;
        int count = 10000;
        for (int i = 0; i < count; i++) {
            int offset = random.nextInt(maxOffset);
            int len = random.nextInt(maxLen);
            boolean val = random.nextBoolean();
            set.set(offset, offset + len, val);
            bits.set(offset, offset + len, val);
            for (int j = 0; j < total; j++) {
                assertEquals(set.get(j), bits.get(j));
            }
        }
    }
View Full Code Here

            } else if ("timer".equals(args[0])) {
                new TestTimer().runTest(test);
            }
        } else {
            test.runTests();
            Profiler prof = new Profiler();
            prof.depth = 4;
            prof.interval = 1;
            prof.startCollecting();
            TestPerformance.main("-init", "-db", "1");
            prof.stopCollecting();
            System.out.println(prof.getTop(3));
//            Recover.execute("data", null);
//            RunScript.execute("jdbc:h2:data/test2",
//                 "sa1", "sa1", "data/test.h2.sql", null, false);
//            Recover.execute("data", null);
        }
View Full Code Here

        RecordingFileSystem.register();
        RecordingFileSystem.setRecorder(this);
        config.record = true;

        long time = System.currentTimeMillis();
        Profiler p = new Profiler();
        p.startCollecting();
        new TestPageStoreCoverage().init(config).test();
        System.out.println(p.getTop(3));
        System.out.println(System.currentTimeMillis() - time);
        System.out.println("counter: " + writeCount);
    }
View Full Code Here

        session.put("user", user);
        boolean isH2 = url.startsWith("jdbc:h2:");
        try {
            long start = System.currentTimeMillis();
            String profOpen = "", profClose = "";
            Profiler prof = new Profiler();
            prof.startCollecting();
            Connection conn;
            try {
                conn = server.getConnection(driver, url, user, password);
            } finally {
                prof.stopCollecting();
                profOpen = prof.getTop(3);
            }
            prof = new Profiler();
            prof.startCollecting();
            try {
                JdbcUtils.closeSilently(conn);
            } finally {
                prof.stopCollecting();
                profClose = prof.getTop(3);
            }
            long time = System.currentTimeMillis() - start;
            String success;
            if (time > 1000) {
                success = "<a class=\"error\" href=\"#\" " +
View Full Code Here

                return StringUtils.convertBytesToHex(SHA256.getKeyPasswordHash(p[0], p[1].toCharArray()));
            } else if (isBuiltIn(sql, "@prof_start")) {
                if (profiler != null) {
                    profiler.stopCollecting();
                }
                profiler = new Profiler();
                profiler.startCollecting();
                return "Ok";
            } else if (isBuiltIn(sql, "@sleep")) {
                String s = sql.substring("@sleep".length()).trim();
                int sleep = 1;
View Full Code Here

       
        // to test with more nodes, use:
        // int count = 1000000;
        int count = 10;
       
        Profiler prof = null;
        String nodeType = "oak:Unstructured";
        if (session.getRootNode().hasNode("many")) {
            session.getRootNode().getNode("many").remove();
            session.save();
        }
        Node many = session.getRootNode().addNode("many", nodeType);
        for (int i = 0; i < count; i++) {
            Node n = many.addNode("test" + i, nodeType);
            n.setProperty("prop", i);
            if (i % 100 == 0) {
                session.save();
            }
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
       
        start = System.currentTimeMillis();
        last = start;

        for (int i = 0; i < count; i++) {
            Node n = many.getNode("test" + i);
            long x = n.getProperty("prop").getValue().getLong();
            assertEquals(i, x);
            long now = System.currentTimeMillis();
            if (now - last > 5000) {
                int opsPerSecond = (int) (i * 1000 / (now - start));
                System.out.println(i + " read ops; " + opsPerSecond + " op/s");
                last = now;
                if (prof != null) {
                    System.out.println(prof.getTop(5));
                }
                if (opsPerSecond < 1000 && i % 100 == 0) {
                    prof = new Profiler();
                    prof.startCollecting();
                }
            }
        }
    }
View Full Code Here

    public static void run(String message, final Task task, int threadCount, int millis) throws Exception {
        final AtomicBoolean stopped = new AtomicBoolean();
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
        ArrayList<Thread> threads = new ArrayList<Thread>();
        final AtomicInteger counter = new AtomicInteger();
        Profiler p = new Profiler();
        if (PROFILE) {
            p.interval = 1;
            p.startCollecting();
        }
        for (int i = 0; i < threadCount; i++) {
            Thread t = new Thread("Task " + i) {
                @Override
                public void run() {
                    while (!stopped.get()) {
                        try {
                            task.call();
                            counter.incrementAndGet();
                        } catch (Error e) {
                            exception.set(e);
                            stopped.set(true);
                        } catch (Exception e) {
                            exception.set(e);
                            stopped.set(true);
                        }
                    }
                }
            };
            if (threadCount == 1) {
                long stop = millis + System.currentTimeMillis();
                while (System.currentTimeMillis() < stop) {
                    task.call();
                    counter.incrementAndGet();
                }
                millis = 0;
            } else {
                t.start();
                threads.add(t);
            }
        }
        Throwable e = null;
        while (e == null && millis > 0) {
            Thread.sleep(10);
            millis -= 10;
            e = exception.get();
        }
        stopped.set(true);
        for (Thread t : threads) {
            t.join();
        }
        if (e != null) {
            if (e instanceof Exception) {
                throw (Exception) e;
            }
            throw (Error) e;
        }
        if (PROFILE) {
            System.out.println(p.getTop(5));
        }

    }
View Full Code Here

TOP

Related Classes of org.h2.util.Profiler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.