|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
|
44 | 44 |
|
45 | 45 | import java.util.ArrayList;
|
46 | 46 | import java.util.Arrays;
|
| 47 | +import java.util.concurrent.atomic.AtomicLong; |
47 | 48 | import java.util.stream.Stream;
|
48 | 49 |
|
49 | 50 | import org.graalvm.nativeimage.ImageInfo;
|
@@ -78,8 +79,8 @@ private static final class TimingStack {
|
78 | 79 |
|
79 | 80 | private final String name;
|
80 | 81 | private final boolean fromJava;
|
81 |
| - private long time; |
82 |
| - private long count; |
| 82 | + private final AtomicLong time = new AtomicLong(); |
| 83 | + private final AtomicLong count = new AtomicLong(); |
83 | 84 |
|
84 | 85 | private CApiTiming(boolean fromJava, String name) {
|
85 | 86 | this.fromJava = fromJava;
|
@@ -127,18 +128,18 @@ private static void dumpCallStatistics() {
|
127 | 128 | sorted.sort((a, b) -> Boolean.compare(a.fromJava, b.fromJava) * 100 + a.name.compareTo(b.name));
|
128 | 129 | System.out.println("======================================================================");
|
129 | 130 | System.out.printf("%70s %8s %10s\n", "Name:", "Count:", "Time:");
|
130 |
| - long totalCount = sorted.stream().collect(summingLong(e -> e.count)); |
131 |
| - long totalTime = sorted.stream().collect(summingLong(e -> e.time)); |
132 |
| - long cutoffTime = getCutoff(totalTime, sorted.stream().map(e -> e.time)); |
133 |
| - long cutoffCount = getCutoff(totalCount, sorted.stream().map(e -> e.count)); |
| 131 | + long totalCount = sorted.stream().collect(summingLong(e -> e.count.get())); |
| 132 | + long totalTime = sorted.stream().collect(summingLong(e -> e.time.get())); |
| 133 | + long cutoffTime = getCutoff(totalTime, sorted.stream().map(e -> e.time.get())); |
| 134 | + long cutoffCount = getCutoff(totalCount, sorted.stream().map(e -> e.count.get())); |
134 | 135 | long percent = totalTime / 100;
|
135 | 136 | long visibleCount = 0;
|
136 | 137 | long visibleTime = 0;
|
137 | 138 | for (var e : sorted) {
|
138 |
| - if (e.time >= cutoffTime || e.count >= cutoffCount) { |
139 |
| - System.out.printf("%70s %8s %8sms %s\n", e.name, e.count, e.time / 1000000, stars(percent, e.time)); |
140 |
| - visibleCount += e.count; |
141 |
| - visibleTime += e.time; |
| 139 | + if (e.time.get() >= cutoffTime || e.count.get() >= cutoffCount) { |
| 140 | + System.out.printf("%70s %8s %8sms %s\n", e.name, e.count, e.time.get() / 1000000, stars(percent, e.time.get())); |
| 141 | + visibleCount += e.count.get(); |
| 142 | + visibleTime += e.time.get(); |
142 | 143 | }
|
143 | 144 | }
|
144 | 145 | System.out.printf("%70s %8s %8sms %s\n", "Others:", (totalCount - visibleCount), (totalTime - visibleTime) / 1000000, stars(percent, totalTime - visibleTime));
|
@@ -201,10 +202,10 @@ private static void exitInternal(CApiTiming t) {
|
201 | 202 | TimingStack stack = STACK.get();
|
202 | 203 | long startTime = stack.startTimes[--stack.sp];
|
203 | 204 | long delta = System.nanoTime() - startTime;
|
204 |
| - t.time += delta - stack.subTimes[stack.sp]; |
| 205 | + t.time.addAndGet(delta - stack.subTimes[stack.sp]); |
205 | 206 | if (stack.sp > 0) {
|
206 | 207 | stack.subTimes[stack.sp - 1] += delta;
|
207 | 208 | }
|
208 |
| - t.count++; |
| 209 | + t.count.getAndIncrement(); |
209 | 210 | }
|
210 | 211 | }
|
0 commit comments