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

LearnLib / learnlib / 6605620268

22 Oct 2023 06:53PM UTC coverage: 93.218% (+0.9%) from 92.296%
6605620268

push

github

mtf90
cleanup passive integration tests

11546 of 12386 relevant lines covered (93.22%)

1.68 hits per line

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

55.17
/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.Map.Entry;
20
import java.util.concurrent.ConcurrentHashMap;
21

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

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

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

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

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

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

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

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

89
    /**
90
     * Get profiling results as string.
91
     */
92
    public static String getResults() {
93
        StringBuilder sb = new StringBuilder();
×
94
        for (Entry<String, Counter> e : CUMULATED.entrySet()) {
×
95
            sb.append(e.getValue().getSummary())
×
96
              .append(", (")
×
97
              .append(e.getValue().getCount() / MILLISECONDS_PER_SECOND)
×
98
              .append(" s)")
×
99
              .append(System.lineSeparator());
×
100
        }
×
101
        return sb.toString();
×
102
    }
103

104
    /**
105
     * Log results in category PROFILING.
106
     */
107
    public static void logResults() {
108
        for (Entry<String, Counter> e : CUMULATED.entrySet()) {
1✔
109
            LOGGER.info(Category.PROFILING, e.getValue().toString());
1✔
110
        }
1✔
111
    }
1✔
112

113
}
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