Skip to content

Commit 95f9fb6

Browse files
committed
Use atomic long for CApiTiming's time/count fields
1 parent 0ef05f8 commit 95f9fb6

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/transitions/CApiTiming.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
4444

4545
import java.util.ArrayList;
4646
import java.util.Arrays;
47+
import java.util.concurrent.atomic.AtomicLong;
4748
import java.util.stream.Stream;
4849

4950
import org.graalvm.nativeimage.ImageInfo;
@@ -78,8 +79,8 @@ private static final class TimingStack {
7879

7980
private final String name;
8081
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();
8384

8485
private CApiTiming(boolean fromJava, String name) {
8586
this.fromJava = fromJava;
@@ -127,18 +128,18 @@ private static void dumpCallStatistics() {
127128
sorted.sort((a, b) -> Boolean.compare(a.fromJava, b.fromJava) * 100 + a.name.compareTo(b.name));
128129
System.out.println("======================================================================");
129130
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()));
134135
long percent = totalTime / 100;
135136
long visibleCount = 0;
136137
long visibleTime = 0;
137138
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();
142143
}
143144
}
144145
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) {
201202
TimingStack stack = STACK.get();
202203
long startTime = stack.startTimes[--stack.sp];
203204
long delta = System.nanoTime() - startTime;
204-
t.time += delta - stack.subTimes[stack.sp];
205+
t.time.addAndGet(delta - stack.subTimes[stack.sp]);
205206
if (stack.sp > 0) {
206207
stack.subTimes[stack.sp - 1] += delta;
207208
}
208-
t.count++;
209+
t.count.getAndIncrement();
209210
}
210211
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceDelItemNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
@GenerateInline(false) // One lazy usage, one eager usage => not worth it
7676
@GenerateUncached
7777
public abstract class PySequenceDelItemNode extends Node {
78-
// todo: fa [GR-51456]
7978
private static final NativeCAPISymbol SYMBOL = NativeCAPISymbol.FUN_PY_SEQUENCE_DEL_ITEM;
8079
private static final CApiTiming C_API_TIMING = CApiTiming.create(true, SYMBOL.getName());
8180

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceGetItemNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
@GenerateInline(false) // One lazy usage, one eager usage => not worth it
7676
@GenerateUncached
7777
public abstract class PySequenceGetItemNode extends Node {
78-
// todo: fa [GR-51456]
7978
private static final NativeCAPISymbol SYMBOL = NativeCAPISymbol.FUN_PY_SEQUENCE_GET_ITEM;
8079
private static final CApiTiming C_API_TIMING = CApiTiming.create(true, SYMBOL.getName());
8180

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSetItemNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
@GenerateInline(false) // One lazy usage, one eager usage => not worth it
7676
@GenerateUncached
7777
public abstract class PySequenceSetItemNode extends Node {
78-
// todo: fa [GR-51456]
7978
private static final NativeCAPISymbol SYMBOL = NativeCAPISymbol.FUN_PY_SEQUENCE_SET_ITEM;
8079
private static final CApiTiming C_API_TIMING = CApiTiming.create(true, SYMBOL.getName());
8180

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PySequenceSizeNode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
@GenerateInline(value = false)
8080
@GenerateUncached
8181
public abstract class PySequenceSizeNode extends Node {
82-
// todo: fa [GR-51456]
8382
private static final NativeCAPISymbol SYMBOL = NativeCAPISymbol.FUN_PY_SEQUENCE_SIZE;
8483
private static final CApiTiming C_API_TIMING = CApiTiming.create(true, SYMBOL.getName());
8584

0 commit comments

Comments
 (0)