forked from FabricMC/fabric
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hacked up tracy capture during client tests
- Loading branch information
Showing
5 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...t-api-v1/src/client/java/net/fabricmc/fabric/impl/client/gametest/tracy/TracyCapture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.impl.client.gametest.tracy; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class TracyCapture { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(TracyCapture.class); | ||
private final Path output; | ||
|
||
@Nullable | ||
private Process process = null; | ||
|
||
public TracyCapture(Path output) { | ||
this.output = output; | ||
} | ||
|
||
public void startCapture() { | ||
try { | ||
Files.createDirectories(output.getParent()); | ||
LOGGER.info("Starting tracy-capture"); | ||
process = createProcess().start(); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("Failed to start tracy-capture", e); | ||
} | ||
|
||
// Send ctrl+c on shutdown | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
if (process != null) { | ||
LOGGER.info("Stopping tracy-capture"); | ||
|
||
try { | ||
// Send ctrl+c | ||
long pid = process.pid(); // Requires Java 9+ | ||
ProcessBuilder killProcess = new ProcessBuilder("kill", "-SIGINT", String.valueOf(pid)); | ||
killProcess.inheritIO().start(); | ||
|
||
process.waitFor(); | ||
LOGGER.info("tracy-capture finished with exit code {}", process.exitValue()); | ||
LOGGER.info(new String(process.getInputStream().readAllBytes())); | ||
} catch (InterruptedException e) { | ||
LOGGER.error("tracy-capture was interrupted", e); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
})); | ||
} | ||
|
||
private ProcessBuilder createProcess() { | ||
return new ProcessBuilder() | ||
.command( | ||
"tracy-capture", | ||
"-o", output.toAbsolutePath().toString(), | ||
"-a", "127.0.0.1", | ||
"-f" | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...pi-v1/src/client/java/net/fabricmc/fabric/impl/client/gametest/tracy/TracyEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.impl.client.gametest.tracy; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; | ||
|
||
public class TracyEntrypoint implements PreLaunchEntrypoint { | ||
private static final boolean ENABLED = System.getProperty("fabric.client.gametest") != null; | ||
|
||
private static TracyCapture tracyCapture; | ||
|
||
@Override | ||
public void onPreLaunch() { | ||
if (!ENABLED) { | ||
return; | ||
} | ||
|
||
if (!Arrays.asList(FabricLoader.getInstance().getLaunchArguments(true)).contains("--tracy")) { | ||
return; | ||
} | ||
|
||
Path output = FabricLoader.getInstance().getGameDir().resolve("profile.tracy"); | ||
tracyCapture = new TracyCapture(output); | ||
tracyCapture.startCapture(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters