Skip to content

Commit

Permalink
use unix line endings, new gradle, prepare kotlin gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn committed Oct 8, 2024
1 parent f61ff1f commit ed89336
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 282 deletions.
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();
}
}
```
116 changes: 58 additions & 58 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
// Copyright 2024 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

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.withType(Jar).configureEach {
def sharedLibraryTasks = project('tracy-jni').tasks.withType(LinkSharedLibrary)
dependsOn sharedLibraryTasks
def sharedLibraryOutputs = sharedLibraryTasks.find { task ->
task.name.toLowerCase().contains("release")
}.outputs.files.asFileTree.files
from(sharedLibraryOutputs) {
include("*.dll")
into("windows")
}
from(sharedLibraryOutputs) {
include("*.so")
into("linux")
}
from(sharedLibraryOutputs) {
include("*.dylib")
into("macosx")
}
from (new 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").getLayout().getBuildDirectory().dir("lib/main/debug").get().asFile.absolutePath
}
// Copyright 2024 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

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.withType(Jar).configureEach {
def sharedLibraryTasks = project("tracy-jni").tasks.withType(LinkSharedLibrary)
dependsOn sharedLibraryTasks
def sharedLibraryOutputs = sharedLibraryTasks.find { task ->
task.name.toLowerCase().contains("release")
}.outputs.files.asFileTree.files
from(sharedLibraryOutputs) {
include("*.dll")
into("windows")
}
from(sharedLibraryOutputs) {
include("*.so")
into("linux")
}
from(sharedLibraryOutputs) {
include("*.dylib")
into("macosx")
}
from (new 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").getLayout().getBuildDirectory().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

0 comments on commit ed89336

Please sign in to comment.