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

Camelcade / Perl5-IDEA / #525521559

30 May 2025 06:24AM UTC coverage: 82.248% (-0.03%) from 82.275%
#525521559

push

github

hurricup
Suppressed SameParameterValue warning

30866 of 37528 relevant lines covered (82.25%)

0.82 hits per line

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

72.22
/plugin/core/src/main/java/com/perl5/lang/perl/util/PerlTimeLogger.java
1
/*
2
 * Copyright 2015-2025 Alexandr Evstigneev
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

17
package com.perl5.lang.perl.util;
18

19
import com.intellij.openapi.diagnostic.Logger;
20
import org.jetbrains.annotations.NotNull;
21
import org.jetbrains.annotations.Nullable;
22

23
import java.util.HashMap;
24
import java.util.Map;
25

26
public class PerlTimeLogger {
27
  private static final PerlTimeLogger EMPTY_LOGGER = new PerlTimeLogger("") {
1✔
28
    @Override
29
    public void debug(@NotNull Object... data) {
30
    }
×
31

32
    @Override
33
    public @NotNull Counter getCounter(@NotNull String name) {
34
      return Counter.EMPTY_COUNTER;
×
35
    }
36
  };
37

38
  private final Logger myLogger;
39
  long myLastTime = System.currentTimeMillis();
1✔
40
  private Map<String, Counter> myCounters;
41

42
  public PerlTimeLogger(@NotNull Class<?> clazz) {
×
43
    myLogger = Logger.getInstance(clazz);
×
44
  }
×
45

46
  public PerlTimeLogger(@NotNull String id) {
1✔
47
    myLogger = Logger.getInstance(id);
1✔
48
  }
1✔
49

50
  public PerlTimeLogger(@NotNull Logger logger) {
1✔
51
    myLogger = logger;
1✔
52
  }
1✔
53

54
  public void debug(@NotNull Object... data) {
55
    if (myLogger.isDebugEnabled()) {
1✔
56
      long newLastTime = System.currentTimeMillis();
1✔
57
      //noinspection LoggingSimilarMessage
58
      myLogger.debug((newLastTime - myLastTime) + " ms. ", data);
1✔
59
      myLastTime = newLastTime;
1✔
60
    }
61
  }
1✔
62

63
  public void trace(@NotNull Object... data) {
64
    if (myLogger.isTraceEnabled()) {
1✔
65
      long newLastTime = System.currentTimeMillis();
×
66
      //noinspection LoggingSimilarMessage
67
      myLogger.debug((newLastTime - myLastTime) + " ms. ", data);
×
68
      myLastTime = newLastTime;
×
69
    }
70
  }
1✔
71

72
  public @NotNull Counter getCounter(@NotNull String name) {
73
    if (myCounters == null) {
1✔
74
      myCounters = new HashMap<>();
1✔
75
    }
76
    return myCounters.computeIfAbsent(name, it -> new Counter());
1✔
77
  }
78

79
  public static class Counter {
1✔
80
    private static final Counter EMPTY_COUNTER = new Counter() {
1✔
81
      @Override
82
      public void inc() {
83
      }
×
84

85
      @Override
86
      public int get() {
87
        return 0;
×
88
      }
89
    };
90

91
    private int myCounter = 0;
1✔
92

93
    public void inc() {
94
      myCounter++;
1✔
95
    }
1✔
96

97
    public int get() {
98
      return myCounter;
1✔
99
    }
100
  }
101

102
  public static @NotNull String kb(int bytes) {
103
    return String.format("%.2f", (float)bytes / 1024);
1✔
104
  }
105

106
  public static @NotNull PerlTimeLogger create(@Nullable Logger logger) {
107
    return logger != null && logger.isDebugEnabled() ? new PerlTimeLogger(logger) : EMPTY_LOGGER;
1✔
108
  }
109
}
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

© 2026 Coveralls, Inc