• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 6673301747

27 Oct 2023 11:46PM UTC coverage: 91.986% (-1.3%) from 93.327%
6673301747

push

github

mtf90
merge the release and sign-artifacts profiles

10984 of 11941 relevant lines covered (91.99%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/commons/util/src/main/java/de/learnlib/util/statistic/SimpleProfiler.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package de.learnlib.util.statistic;
17

18
import java.util.Map;
19
import java.util.concurrent.ConcurrentHashMap;
20

21
import de.learnlib.api.logging.Category;
22
import de.learnlib.filter.statistic.Counter;
23
import org.checkerframework.checker.nullness.qual.Nullable;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
26

27
/**
28
 * Very rudimentary profiler.
29
 */
30
public final class SimpleProfiler {
31

32
    private static final Map<String, Counter> CUMULATED = new ConcurrentHashMap<>();
2✔
33
    private static final Map<String, Long> PENDING = new ConcurrentHashMap<>();
2✔
34
    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleProfiler.class.getName());
2✔
35
    private static final double MILLISECONDS_PER_SECOND = 1000.0;
36

37
    private SimpleProfiler() {
38
        // prevent initialization
39
    }
40

41
    /**
42
     * Reset internal data.
43
     */
44
    public static void reset() {
45
        CUMULATED.clear();
×
46
        PENDING.clear();
×
47
    }
×
48

49
    /**
50
     * Start the timer identified by the given key.
51
     *
52
     * @param name
53
     *         The name of the timer to be started.
54
     */
55
    public static void start(String name) {
56
        PENDING.put(name, System.currentTimeMillis());
2✔
57
    }
2✔
58

59
    /**
60
     * Stop the timer identified by the given key. After stopping a timer, the time passed from its
61
     * {@link #start(String) initialization} will be added to the cumulated time of the specific timer.
62
     *
63
     * @param name
64
     *         The name of the timer to be stopped.
65
     */
66
    public static void stop(String name) {
67
        Long start = PENDING.remove(name);
2✔
68
        if (start == null) {
2✔
69
            return;
×
70
        }
71
        long duration = System.currentTimeMillis() - start;
2✔
72
        Counter sum = CUMULATED.computeIfAbsent(name, k -> new Counter(k, "ms"));
2✔
73
        sum.increment(duration);
2✔
74
    }
2✔
75

76
    /**
77
     * Return the counter for the cumulated (passed) time of the given timer.
78
     *
79
     * @param name
80
     *         The name of the timer to be returned.
81
     *
82
     * @return The counter for tracking the passed milliseconds of the timer
83
     */
84
    public static @Nullable Counter cumulated(String name) {
85
        return CUMULATED.get(name);
2✔
86
    }
87

88
    /**
89
     * Log results in category PROFILING.
90
     */
91
    public static void logResults() {
92
        for (Counter c : CUMULATED.values()) {
×
93
            LOGGER.info(Category.PROFILING, "{}, ({} s)", c.getSummary(), c.getCount() / MILLISECONDS_PER_SECOND);
×
94
        }
×
95
    }
×
96

97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc