Skip to content

Commit

Permalink
more ifdef
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Dec 11, 2024
1 parent 27db5de commit 51b46fe
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions OpenDreamRuntime/DreamThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ public DMError(string message)
public abstract class ProcState : IDisposable {
private static int _idCounter = 0;
public int Id { get; } = ++_idCounter;
#if TOOLS
public abstract (string SourceFile, int Line) TracyLocationId { get; }
public ProfilerZone? TracyZoneId { get; set; }
#endif
public DreamThread Thread { get; set; }

[Access(typeof(ProcScheduler))]
Expand Down
4 changes: 4 additions & 0 deletions OpenDreamRuntime/Objects/DreamObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
namespace OpenDreamRuntime.Objects {
[Virtual]
public class DreamObject {
#if TOOLS
protected ProfilerMemory? _tracyMemoryId;

Check warning

Code scanning / InspectCode

Inconsistent Naming Warning

Name '_tracyMemoryId' does not match rule 'Instance fields (not private)'. Suggested name is 'TracyMemoryId'.
#endif
public DreamObjectDefinition ObjectDefinition;

[Access(typeof(DreamObject))]
Expand Down Expand Up @@ -111,7 +113,9 @@ protected virtual void HandleDeletion(bool possiblyThreaded) {
Variables = null;

ObjectDefinition = null!;
#if TOOLS
_tracyMemoryId?.ReleaseMemory();
#endif
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ namespace OpenDreamRuntime.Objects.Types;
public class DreamList : DreamObject {
private readonly List<DreamValue> _values;
private Dictionary<DreamValue, DreamValue>? _associativeValues;
#if TOOLS
private ProfilerMemory? _tracyContentsMemoryId;
#endif
public override bool ShouldCallNew => false;

public virtual bool IsAssociative => (_associativeValues != null && _associativeValues.Count > 0);
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamRuntime/Procs/AsyncNativeProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public sealed class State : ProcState {

private AsyncNativeProc? _proc;
public override DreamProc? Proc => _proc;

#if TOOLS
public override (string SourceFile, int Line) TracyLocationId => ("Async Native Proc", 0);

#endif
private Func<State, Task<DreamValue>> _taskFunc;
private Task? _task;

Expand Down
8 changes: 4 additions & 4 deletions OpenDreamRuntime/Procs/DMProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ public sealed class NullProcState : ProcState {
public static readonly Stack<NullProcState> Pool = new();

public override DreamProc? Proc => _proc;

#if TOOLS
public override (string SourceFile, int Line) TracyLocationId => ("<NO-OP>",0);

#endif
private DreamProc? _proc;

public override ProcStatus Resume() {
Expand Down Expand Up @@ -357,9 +357,9 @@ public sealed class DMProcState : ProcState {

private DMProc _proc;
public override DMProc Proc => _proc;

#if TOOLS
public override (string SourceFile, int Line) TracyLocationId => _proc.GetSourceAtOffset(_pc+1);

#endif

/// Static initializer for maintainer friendly OpcodeHandlers to performance friendly _opcodeHandlers
static unsafe DMProcState() {
Expand Down
4 changes: 2 additions & 2 deletions OpenDreamRuntime/Procs/InitDreamObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void Initialize(DreamThread thread, DreamObject dreamObject, DreamObject?
private Stage _stage = Stage.Init;

public override DreamProc? Proc => null;

#if TOOLS
public override (string SourceFile, int Line) TracyLocationId => ($"new {_dreamObject.ObjectDefinition.Type}",0);

#endif
public override void AppendStackFrame(StringBuilder builder) {
builder.AppendLine($"new {_dreamObject.ObjectDefinition.Type}");
}
Expand Down
6 changes: 6 additions & 0 deletions OpenDreamRuntime/Resources/DreamResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ public byte[]? ResourceData {

private readonly string? _filePath;
private byte[]? _resourceData;
#if TOOLS
private ProfilerMemory? _tracyMemoryId;

Check warning

Code scanning / InspectCode

Non-accessed field: Private accessibility Warning

Field '_tracyMemoryId' is assigned but its value is never used
#endif

public DreamResource(int id, string? filePath, string? resourcePath) {
Id = id;
ResourcePath = resourcePath;

Check notice

Code scanning / InspectCode

Merge conditional ?: expression into conditional access Note

Merge conditional expression
_filePath = filePath;
#if TOOLS
_tracyMemoryId = Profiler.BeginMemoryZone((ulong)(Unsafe.SizeOf<DreamResource>() + (ResourceData?.Length ?? 0)), "resource");
#endif
}

public DreamResource(int id, byte[] data) {
Id = id;
_resourceData = data;
#if TOOLS
_tracyMemoryId = Profiler.BeginMemoryZone((ulong)(Unsafe.SizeOf<DreamResource>() + (ResourceData is null? 0 : ResourceData.Length)), "resource");
#endif
}

public virtual string? ReadAsString() {
Expand Down

0 comments on commit 51b46fe

Please sign in to comment.