Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use unix line endings, use gradle-10.2.0, use kotlin gradle #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build
out
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
out
tracy-jni/build
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
## TracyJavaBindings – Java bindings for the Tracy Profiler
### Prerequisites
- After cloning the repository, ensure that you have checked-out submodules with `git submodule update --init`.
### Building
#### JNI Bindings
- You can build the JNI bindings with `gradlew jar`
#### Tracy profiler GUI
> _All commands need to be run in the `tracy-jni/tracy` subdirectory._
- Create a new `build` folder under `tracy-jni/tracy/profiler`.
- Configure the profiler using `cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release` (this only needs to be done once).
- Build the profiler using `cmake --build profiler/build --parallel --config Release`.
- The built `tracy-profiler` executable can be found in the `profiler/build/Release` directory.
### Integration
- At runtime, the `java.library.path` system property should contain a path to the native JNI libraries found in `tracy-jni/build/lib/main/release`.
### Usage Example
```java
import io.github.benjaminamos.tracy.Tracy;
public class TracyTest {
public static void main(String[] args) {
// Start profiling
Tracy.startupProfiler();
// Allocate and begin zone
long handle = Tracy.allocSourceLocation(0, "Test.java", "test()", "Test!", 0);
Tracy.ZoneContext zoneContext = Tracy.zoneBegin(handle, 1);
// Do work...
// End zone
Tracy.zoneEnd(zoneContext);
// Begin new frame
Tracy.markFrame();
// Stop profiling
Tracy.shutdownProfiler();
}
}
## TracyJavaBindings – Java bindings for the Tracy Profiler
### Prerequisites
- After cloning the repository, ensure that you have checked-out submodules with `git submodule update --init`.
### Building
#### JNI Bindings
- You can build the JNI bindings with `gradlew jar`
#### Tracy profiler GUI
> _All commands need to be run in the `tracy-jni/tracy` subdirectory._
- Create a new `build` folder under `tracy-jni/tracy/profiler`.
- Configure the profiler using `cmake -B profiler/build -S profiler -DCMAKE_BUILD_TYPE=Release` (this only needs to be done once).
- Build the profiler using `cmake --build profiler/build --parallel --config Release`.
- The built `tracy-profiler` executable can be found in the `profiler/build/Release` directory.

### Integration
- At runtime, the `java.library.path` system property should contain a path to the native JNI libraries found in `tracy-jni/build/lib/main/release`.
### Usage Example
```java
import io.github.benjaminamos.tracy.Tracy;

public class TracyTest {
public static void main(String[] args) {
// Start profiling
Tracy.startupProfiler();

// Allocate and begin zone
long handle = Tracy.allocSourceLocation(0, "Test.java", "test()", "Test!", 0);
Tracy.ZoneContext zoneContext = Tracy.zoneBegin(handle, 1);

// Do work...

// End zone
Tracy.zoneEnd(zoneContext);

// Begin new frame
Tracy.markFrame();

// Stop profiling
Tracy.shutdownProfiler();
}
}
```
58 changes: 0 additions & 58 deletions build.gradle

This file was deleted.

68 changes: 68 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

// the following is possible to build for differing java versions. default is java-17.
// gradle clean build -PjavacRelease=21
val javacRelease = (project.findProperty("javacRelease") ?: "17") as String

plugins {
id("java-library")
}

group "io.github.benjaminamos.TracyJavaBindings"
version "1.0-SNAPSHOT"

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

sourceSets {
main
}

tasks.compileJava {
options.release.set(Integer.parseInt(javacRelease))
}

tasks.withType<Jar>().configureEach {
val sharedLibraryTasks = project(":tracy-jni").tasks.withType<LinkSharedLibrary>()
dependsOn(sharedLibraryTasks)
val sharedLibraryOutputs = sharedLibraryTasks.find { task ->
task.name.toLowerCase().contains("release")
}?.outputs?.files?.asFileTree?.files
sharedLibraryOutputs?.let {
from(it) {
include("*.dll")
into("windows")
}
from(it) {
include("*.so")
into("linux")
}
from(it) {
include("*.dylib")
into("macosx")
}
}
from(File(project(":tracy-jni").projectDir, "tracy")) {
include("LICENSE")
rename("LICENSE", "TRACY_LICENSE")
}
}

tasks.named<Test>("test") {
useJUnitPlatform()

maxHeapSize = "1G"

testLogging {
events("passed")
}

systemProperty("java.library.path", project(":tracy-jni").layout.buildDirectory.dir("lib/main/debug").get().asFile.absolutePath)
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 3 additions & 3 deletions settings.gradle → settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name = "TracyJavaBindings"
include 'tracy-jni'
rootProject.name = "TracyJavaBindings"

include("tracy-jni")
92 changes: 46 additions & 46 deletions src/main/java/io/github/benjaminamos/tracy/Tracy.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// Copyright 2024 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package io.github.benjaminamos.tracy;
import java.io.File;
public final class Tracy {
private Tracy() {
}
static {
String libraryPath = System.getProperty("org.terasology.librarypath");
if (libraryPath == null) {
System.loadLibrary("tracy-jni-" + System.getProperty("os.arch"));
} else {
File libraryDirectory = new File(libraryPath);
if (libraryDirectory.exists() && libraryDirectory.isDirectory()) {
String architecture = System.getProperty("os.arch");
for (File file : libraryDirectory.listFiles()) {
if (file.getName().startsWith("tracy-jni-" + architecture) || file.getName().startsWith("libtracy-jni-" + architecture)) {
System.load(file.getPath());
}
}
}
}
}
public static native void startupProfiler();
public static native void shutdownProfiler();
public static native boolean isConnected();
public static native void markFrame();
public static native long allocSourceLocation(int line, String source, String function, String name, int colour);
public static native ZoneContext zoneBegin(long sourceLocation, int active);
public static native void zoneEnd(ZoneContext zoneContext);
public static final class ZoneContext {
public final int id;
public final int active;
public ZoneContext(int id, int active) {
this.id = id;
this.active = active;
}
}
}
// Copyright 2024 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package io.github.benjaminamos.tracy;

import java.io.File;

public final class Tracy {
private Tracy() {
}

static {
String libraryPath = System.getProperty("org.terasology.librarypath");
if (libraryPath == null) {
System.loadLibrary("tracy-jni-" + System.getProperty("os.arch"));
} else {
File libraryDirectory = new File(libraryPath);
if (libraryDirectory.exists() && libraryDirectory.isDirectory()) {
String architecture = System.getProperty("os.arch");
for (File file : libraryDirectory.listFiles()) {
if (file.getName().startsWith("tracy-jni-" + architecture) || file.getName().startsWith("libtracy-jni-" + architecture)) {
System.load(file.getPath());
}
}
}
}
}

public static native void startupProfiler();
public static native void shutdownProfiler();
public static native boolean isConnected();
public static native void markFrame();
public static native long allocSourceLocation(int line, String source, String function, String name, int colour);
public static native ZoneContext zoneBegin(long sourceLocation, int active);
public static native void zoneEnd(ZoneContext zoneContext);

public static final class ZoneContext {
public final int id;
public final int active;

public ZoneContext(int id, int active) {
this.id = id;
this.active = active;
}
}
}
Loading