mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
build: remove tracy completely
This commit is contained in:
25
build.zig
25
build.zig
@ -35,7 +35,6 @@ comptime {
|
|||||||
const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
|
const app_version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };
|
||||||
|
|
||||||
/// Build options, see the build options help for more info.
|
/// Build options, see the build options help for more info.
|
||||||
var tracy: bool = false;
|
|
||||||
var flatpak: bool = false;
|
var flatpak: bool = false;
|
||||||
var app_runtime: apprt.Runtime = .none;
|
var app_runtime: apprt.Runtime = .none;
|
||||||
var renderer_impl: renderer.Impl = .opengl;
|
var renderer_impl: renderer.Impl = .opengl;
|
||||||
@ -62,15 +61,6 @@ pub fn build(b: *std.Build) !void {
|
|||||||
var env = try std.process.getEnvMap(b.allocator);
|
var env = try std.process.getEnvMap(b.allocator);
|
||||||
defer env.deinit();
|
defer env.deinit();
|
||||||
|
|
||||||
// Note: Our tracy usage has a huge memory leak currently so only enable
|
|
||||||
// this if you really want tracy integration and don't mind the memory leak.
|
|
||||||
// Or, please contribute a fix because I don't know where it is.
|
|
||||||
tracy = b.option(
|
|
||||||
bool,
|
|
||||||
"tracy",
|
|
||||||
"Enable Tracy integration (default true in Debug on Linux)",
|
|
||||||
) orelse false;
|
|
||||||
|
|
||||||
flatpak = b.option(
|
flatpak = b.option(
|
||||||
bool,
|
bool,
|
||||||
"flatpak",
|
"flatpak",
|
||||||
@ -206,7 +196,6 @@ pub fn build(b: *std.Build) !void {
|
|||||||
"{}",
|
"{}",
|
||||||
.{version},
|
.{version},
|
||||||
));
|
));
|
||||||
exe_options.addOption(bool, "tracy_enabled", tracy);
|
|
||||||
exe_options.addOption(bool, "flatpak", flatpak);
|
exe_options.addOption(bool, "flatpak", flatpak);
|
||||||
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);
|
exe_options.addOption(apprt.Runtime, "app_runtime", app_runtime);
|
||||||
exe_options.addOption(font.Backend, "font_backend", font_backend);
|
exe_options.addOption(font.Backend, "font_backend", font_backend);
|
||||||
@ -743,10 +732,6 @@ fn addDeps(
|
|||||||
.cpu = cpu_opts,
|
.cpu = cpu_opts,
|
||||||
.optimize = step.root_module.optimize.?,
|
.optimize = step.root_module.optimize.?,
|
||||||
});
|
});
|
||||||
const tracy_dep = b.dependency("tracy", .{
|
|
||||||
.target = target_triple,
|
|
||||||
.optimize = step.root_module.optimize.?,
|
|
||||||
});
|
|
||||||
const zlib_dep = b.dependency("zlib", .{
|
const zlib_dep = b.dependency("zlib", .{
|
||||||
.target = target_triple,
|
.target = target_triple,
|
||||||
.cpu = cpu_opts,
|
.cpu = cpu_opts,
|
||||||
@ -767,9 +752,6 @@ fn addDeps(
|
|||||||
|
|
||||||
// Wasm we do manually since it is such a different build.
|
// Wasm we do manually since it is such a different build.
|
||||||
if (step.rootModuleTarget().cpu.arch == .wasm32) {
|
if (step.rootModuleTarget().cpu.arch == .wasm32) {
|
||||||
// We link this package but its a no-op since Tracy
|
|
||||||
// never actually WORKS with wasm.
|
|
||||||
step.root_module.addImport("tracy", tracy_dep.module("tracy"));
|
|
||||||
step.root_module.addImport("zig-js", js_dep.module("zig-js"));
|
step.root_module.addImport("zig-js", js_dep.module("zig-js"));
|
||||||
|
|
||||||
return static_libs;
|
return static_libs;
|
||||||
@ -827,13 +809,6 @@ fn addDeps(
|
|||||||
step.linkLibrary(cimgui_dep.artifact("cimgui"));
|
step.linkLibrary(cimgui_dep.artifact("cimgui"));
|
||||||
try static_libs.append(cimgui_dep.artifact("cimgui").getEmittedBin());
|
try static_libs.append(cimgui_dep.artifact("cimgui").getEmittedBin());
|
||||||
|
|
||||||
// Tracy
|
|
||||||
step.root_module.addImport("tracy", tracy_dep.module("tracy"));
|
|
||||||
if (tracy) {
|
|
||||||
step.linkLibrary(tracy_dep.artifact("tracy"));
|
|
||||||
try static_libs.append(tracy_dep.artifact("tracy").getEmittedBin());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Glslang
|
// Glslang
|
||||||
step.linkLibrary(glslang_dep.artifact("glslang"));
|
step.linkLibrary(glslang_dep.artifact("glslang"));
|
||||||
try static_libs.append(glslang_dep.artifact("glslang").getEmittedBin());
|
try static_libs.append(glslang_dep.artifact("glslang").getEmittedBin());
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
|
||||||
const target = b.standardTargetOptions(.{});
|
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
|
||||||
|
|
||||||
_ = b.addModule("tracy", .{ .root_source_file = .{ .path = "tracy.zig" } });
|
|
||||||
|
|
||||||
const upstream = b.dependency("tracy", .{});
|
|
||||||
const lib = b.addStaticLibrary(.{
|
|
||||||
.name = "tracy",
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
|
||||||
lib.linkLibC();
|
|
||||||
lib.linkLibCpp();
|
|
||||||
if (target.result.os.tag == .windows) {
|
|
||||||
lib.linkSystemLibrary("Advapi32");
|
|
||||||
lib.linkSystemLibrary("User32");
|
|
||||||
lib.linkSystemLibrary("Ws2_32");
|
|
||||||
lib.linkSystemLibrary("DbgHelp");
|
|
||||||
}
|
|
||||||
|
|
||||||
lib.addIncludePath(upstream.path(""));
|
|
||||||
|
|
||||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
|
||||||
defer flags.deinit();
|
|
||||||
try flags.appendSlice(&.{
|
|
||||||
"-DTRACY_ENABLE",
|
|
||||||
"-fno-sanitize=undefined",
|
|
||||||
});
|
|
||||||
if (target.result.os.tag == .windows) {
|
|
||||||
try flags.appendSlice(&.{
|
|
||||||
"-D_WIN32_WINNT=0x601",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
lib.addCSourceFile(.{
|
|
||||||
.file = upstream.path("TracyClient.cpp"),
|
|
||||||
.flags = flags.items,
|
|
||||||
});
|
|
||||||
|
|
||||||
lib.installHeadersDirectoryOptions(.{
|
|
||||||
.source_dir = upstream.path(""),
|
|
||||||
.install_dir = .header,
|
|
||||||
.install_subdir = "",
|
|
||||||
.include_extensions = &.{ ".h", ".hpp" },
|
|
||||||
});
|
|
||||||
|
|
||||||
b.installArtifact(lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
const headers = &.{
|
|
||||||
"TracyC.h",
|
|
||||||
"TracyOpenGL.hpp",
|
|
||||||
"Tracy.hpp",
|
|
||||||
"TracyD3D11.hpp",
|
|
||||||
"TracyD3D12.hpp",
|
|
||||||
"TracyOpenCL.hpp",
|
|
||||||
"TracyVulkan.hpp",
|
|
||||||
"client/TracyCallstack.h",
|
|
||||||
"client/TracyScoped.hpp",
|
|
||||||
"client/TracyStringHelpers.hpp",
|
|
||||||
"client/TracySysTrace.hpp",
|
|
||||||
"client/TracyDxt1.hpp",
|
|
||||||
"client/TracyRingBuffer.hpp",
|
|
||||||
"client/tracy_rpmalloc.hpp",
|
|
||||||
"client/TracyDebug.hpp",
|
|
||||||
"client/TracyLock.hpp",
|
|
||||||
"client/TracyThread.hpp",
|
|
||||||
"client/TracyArmCpuTable.hpp",
|
|
||||||
"client/TracyProfiler.hpp",
|
|
||||||
"client/TracyCallstack.hpp",
|
|
||||||
"client/TracySysTime.hpp",
|
|
||||||
"client/TracyFastVector.hpp",
|
|
||||||
"common/TracyApi.h",
|
|
||||||
"common/TracyYield.hpp",
|
|
||||||
"common/tracy_lz4hc.hpp",
|
|
||||||
"common/TracySystem.hpp",
|
|
||||||
"common/TracyProtocol.hpp",
|
|
||||||
"common/TracyQueue.hpp",
|
|
||||||
"common/TracyUwp.hpp",
|
|
||||||
"common/TracyAlloc.hpp",
|
|
||||||
"common/TracyAlign.hpp",
|
|
||||||
"common/TracyForceInline.hpp",
|
|
||||||
"common/TracyColor.hpp",
|
|
||||||
"common/tracy_lz4.hpp",
|
|
||||||
"common/TracyStackFrames.hpp",
|
|
||||||
"common/TracySocket.hpp",
|
|
||||||
"common/TracyMutex.hpp",
|
|
||||||
};
|
|
@ -1,10 +0,0 @@
|
|||||||
.{
|
|
||||||
.name = "tracy",
|
|
||||||
.version = "0.8.2",
|
|
||||||
.dependencies = .{
|
|
||||||
.tracy = .{
|
|
||||||
.url = "https://github.com/wolfpld/tracy/archive/refs/tags/v0.8.2.1.tar.gz",
|
|
||||||
.hash = "1220289ca424ec488316b75c992b9f02846caaa70287f958b3966e02d5ca81789d27",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,271 +0,0 @@
|
|||||||
//! Tracy API.
|
|
||||||
//!
|
|
||||||
//! Forked and modified from https://github.com/SpexGuy/Zig-Tracy
|
|
||||||
const std = @import("std");
|
|
||||||
const builtin = @import("builtin");
|
|
||||||
const root = @import("root");
|
|
||||||
const SourceLocation = std.builtin.SourceLocation;
|
|
||||||
|
|
||||||
// Tracy is enabled if the root function tracy_enabled returns true.
|
|
||||||
pub const enabled = @hasDecl(root, "tracy_enabled") and root.tracy_enabled();
|
|
||||||
|
|
||||||
// Bring in the correct implementation depending on if we're enabled or not.
|
|
||||||
// See Impl for all the real doc comments.
|
|
||||||
pub usingnamespace if (enabled) Impl else Noop;
|
|
||||||
|
|
||||||
const Impl = struct {
|
|
||||||
const c = @cImport({
|
|
||||||
//uncomment to enable callstacks, very slow
|
|
||||||
//@cDefine("TRACY_CALLSTACK", "");
|
|
||||||
|
|
||||||
@cDefine("TRACY_ENABLE", "");
|
|
||||||
@cInclude("TracyC.h");
|
|
||||||
});
|
|
||||||
|
|
||||||
const has_callstack_support = @hasDecl(c, "TRACY_HAS_CALLSTACK") and @hasDecl(c, "TRACY_CALLSTACK");
|
|
||||||
const callstack_enabled: c_int = if (has_callstack_support) c.TRACY_CALLSTACK else 0;
|
|
||||||
const callstack_depth = 10; // TODO configurable
|
|
||||||
|
|
||||||
/// A zone represents the lifetime of a special on-stack profiler variable.
|
|
||||||
/// Typically it would exist for the duration of a whole scope of the
|
|
||||||
/// profiled function, but you also can measure time spent in scopes of a
|
|
||||||
/// for-loop or an if-branch.
|
|
||||||
pub const Zone = struct {
|
|
||||||
zone: c.___tracy_c_zone_context,
|
|
||||||
|
|
||||||
/// Text description of a zone.
|
|
||||||
pub inline fn text(self: Zone, val: []const u8) void {
|
|
||||||
c.___tracy_emit_zone_text(self.zone, val.ptr, val.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Name of the zone.
|
|
||||||
pub inline fn name(self: Zone, val: []const u8) void {
|
|
||||||
c.___tracy_emit_zone_name(self.zone, val.ptr, val.len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Color of the zone in the UI. Specify the value as RGB
|
|
||||||
/// using hex: 0xRRGGBB.
|
|
||||||
pub inline fn color(self: Zone, val: u32) void {
|
|
||||||
c.___tracy_emit_zone_color(self.zone, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A value associated with the zone.
|
|
||||||
pub inline fn value(self: Zone, val: u64) void {
|
|
||||||
c.___tracy_emit_zone_value(self.zone, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// End the zone.
|
|
||||||
pub inline fn end(self: Zone) void {
|
|
||||||
c.___tracy_emit_zone_end(self.zone);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Tracy profiles within the context of a frame. This represents
|
|
||||||
/// a single frame.
|
|
||||||
pub fn Frame(comptime name: [:0]const u8) type {
|
|
||||||
return struct {
|
|
||||||
pub fn end(_: @This()) void {
|
|
||||||
c.___tracy_emit_frame_mark_end(name.ptr);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// allocator returns an allocator that tracks allocs/frees.
|
|
||||||
pub fn allocator(
|
|
||||||
parent: std.mem.Allocator,
|
|
||||||
comptime name: ?[:0]const u8,
|
|
||||||
) Allocator(name) {
|
|
||||||
return Allocator(name).init(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns an allocator type with the given name.
|
|
||||||
pub fn Allocator(comptime name: ?[:0]const u8) type {
|
|
||||||
return struct {
|
|
||||||
parent: std.mem.Allocator,
|
|
||||||
|
|
||||||
const Self = @This();
|
|
||||||
|
|
||||||
pub fn init(parent: std.mem.Allocator) Self {
|
|
||||||
return .{ .parent = parent };
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn allocator(self: *Self) std.mem.Allocator {
|
|
||||||
return .{
|
|
||||||
.ptr = self,
|
|
||||||
.vtable = &.{
|
|
||||||
.alloc = allocFn,
|
|
||||||
.resize = resizeFn,
|
|
||||||
.free = freeFn,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn allocFn(
|
|
||||||
ctx: *anyopaque,
|
|
||||||
len: usize,
|
|
||||||
log2_ptr_align: u8,
|
|
||||||
ret_addr: usize,
|
|
||||||
) ?[*]u8 {
|
|
||||||
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
|
|
||||||
const result = self.parent.rawAlloc(len, log2_ptr_align, ret_addr);
|
|
||||||
if (result) |data| {
|
|
||||||
if (len != 0) {
|
|
||||||
if (name) |n| {
|
|
||||||
allocNamed(data.ptr, len, n);
|
|
||||||
} else {
|
|
||||||
alloc(data, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn resizeFn(
|
|
||||||
ctx: *anyopaque,
|
|
||||||
buf: []u8,
|
|
||||||
log2_buf_align: u8,
|
|
||||||
new_len: usize,
|
|
||||||
ret_addr: usize,
|
|
||||||
) bool {
|
|
||||||
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
|
|
||||||
if (self.parent.rawResize(buf, log2_buf_align, new_len, ret_addr)) {
|
|
||||||
if (name) |n| {
|
|
||||||
freeNamed(buf.ptr, n);
|
|
||||||
allocNamed(buf.ptr, new_len, n);
|
|
||||||
} else {
|
|
||||||
free(buf.ptr);
|
|
||||||
alloc(buf.ptr, new_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// during normal operation the compiler hits this case thousands of times due to this
|
|
||||||
// emitting messages for it is both slow and causes clutter
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn freeFn(
|
|
||||||
ctx: *anyopaque,
|
|
||||||
buf: []u8,
|
|
||||||
log2_buf_align: u8,
|
|
||||||
ret_addr: usize,
|
|
||||||
) void {
|
|
||||||
const self = @as(*Self, @ptrCast(@alignCast(ctx)));
|
|
||||||
self.parent.rawFree(buf, log2_buf_align, ret_addr);
|
|
||||||
|
|
||||||
if (buf.len != 0) {
|
|
||||||
if (name) |n| {
|
|
||||||
freeNamed(buf.ptr, n);
|
|
||||||
} else {
|
|
||||||
free(buf.ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start a trace. Defer calling end() to end the trace.
|
|
||||||
pub inline fn trace(comptime src: SourceLocation) Zone {
|
|
||||||
const static = struct {
|
|
||||||
var loc: c.___tracy_source_location_data = undefined;
|
|
||||||
};
|
|
||||||
static.loc = .{
|
|
||||||
.name = null,
|
|
||||||
.function = src.fn_name.ptr,
|
|
||||||
.file = src.file.ptr,
|
|
||||||
.line = src.line,
|
|
||||||
.color = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const zone = if (has_callstack_support)
|
|
||||||
c.___tracy_emit_zone_begin_callstack(&static.loc, callstack_depth, 1)
|
|
||||||
else
|
|
||||||
c.___tracy_emit_zone_begin(&static.loc, 1);
|
|
||||||
|
|
||||||
return Zone{ .zone = zone };
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mark the boundary of a frame. Good for continuous frames. For
|
|
||||||
/// discontinuous frames, use frame() and defer end().
|
|
||||||
pub inline fn frameMark() void {
|
|
||||||
c.___tracy_emit_frame_mark(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start a discontinuous frame.
|
|
||||||
pub inline fn frame(comptime name: [:0]const u8) Frame(name) {
|
|
||||||
c.___tracy_emit_frame_mark_start(name.ptr);
|
|
||||||
return .{};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Name the current thread.
|
|
||||||
pub inline fn setThreadName(comptime name: [:0]const u8) void {
|
|
||||||
c.___tracy_set_thread_name(name.ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fn alloc(ptr: [*]u8, len: usize) void {
|
|
||||||
if (has_callstack_support) {
|
|
||||||
c.___tracy_emit_memory_alloc_callstack(ptr, len, callstack_depth, 0);
|
|
||||||
} else {
|
|
||||||
c.___tracy_emit_memory_alloc(ptr, len, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fn allocNamed(ptr: [*]u8, len: usize, comptime name: [:0]const u8) void {
|
|
||||||
if (has_callstack_support) {
|
|
||||||
c.___tracy_emit_memory_alloc_callstack_named(ptr, len, callstack_depth, 0, name.ptr);
|
|
||||||
} else {
|
|
||||||
c.___tracy_emit_memory_alloc_named(ptr, len, 0, name.ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fn free(ptr: [*]u8) void {
|
|
||||||
if (has_callstack_support) {
|
|
||||||
c.___tracy_emit_memory_free_callstack(ptr, callstack_depth, 0);
|
|
||||||
} else {
|
|
||||||
c.___tracy_emit_memory_free(ptr, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fn freeNamed(ptr: [*]u8, comptime name: [:0]const u8) void {
|
|
||||||
if (has_callstack_support) {
|
|
||||||
c.___tracy_emit_memory_free_callstack_named(ptr, callstack_depth, 0, name.ptr);
|
|
||||||
} else {
|
|
||||||
c.___tracy_emit_memory_free_named(ptr, 0, name.ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const Noop = struct {
|
|
||||||
pub const Zone = struct {
|
|
||||||
pub inline fn text(_: Zone, _: []const u8) void {}
|
|
||||||
pub inline fn name(_: Zone, _: []const u8) void {}
|
|
||||||
pub inline fn color(_: Zone, _: u32) void {}
|
|
||||||
pub inline fn value(_: Zone, _: u64) void {}
|
|
||||||
pub inline fn end(_: Zone) void {}
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn Frame(comptime _: [:0]const u8) type {
|
|
||||||
return struct {
|
|
||||||
pub fn end(_: @This()) void {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn trace(comptime src: SourceLocation) Zone {
|
|
||||||
_ = src;
|
|
||||||
return .{};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn frameMark() void {}
|
|
||||||
|
|
||||||
pub inline fn frame(comptime name: [:0]const u8) Frame(name) {
|
|
||||||
return .{};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub inline fn setThreadName(comptime name: [:0]const u8) void {
|
|
||||||
_ = name;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test {}
|
|
@ -105,11 +105,6 @@ pub fn main() !MainReturn {
|
|||||||
try app_runtime.run();
|
try app_runtime.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Required by tracy/tracy.zig to enable/disable tracy support.
|
|
||||||
pub fn tracy_enabled() bool {
|
|
||||||
return options.tracy_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const std_options = struct {
|
pub const std_options = struct {
|
||||||
// Our log level is always at least info in every build mode.
|
// Our log level is always at least info in every build mode.
|
||||||
pub const log_level: std.log.Level = switch (builtin.mode) {
|
pub const log_level: std.log.Level = switch (builtin.mode) {
|
||||||
|
Reference in New Issue
Block a user