Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Dec 8, 2024
1 parent 4a66333 commit 604d7d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion OpenDreamRuntime/DreamThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public DreamValue ReentrantResume(ProcState? untilState, out ProcStatus resultSt
try {
if (_current.TracyZoneId is null && _current.Proc != null) {
var location =_current.TracyLocationId;
_current.TracyZoneId = Profiler.BeginZone((_current.Proc.OwningType.Path.Equals("/") ? "/proc/" : _current.Proc.OwningType.Path+"/") +_current.Proc.Name, filePath: location.SourceFile, lineNumber:(uint)location.Line);
_current.TracyZoneId = Profiler.BeginZone((_current.Proc.OwningType.Path.Equals("/") ? "/proc/" : _current.Proc.OwningType.Path+"/") +_current.Proc.Name, filePath: location.SourceFile, lineNumber: location.Line);

Check warning

Code scanning / InspectCode

Explicit argument passed to parameter with caller info attribute Warning

Explicit argument passed to parameter with caller info attribute
}

Check warning

Code scanning / InspectCode

Explicit argument passed to parameter with caller info attribute Warning

Explicit argument passed to parameter with caller info attribute
// _current.Resume may mutate our state!!!
status = _current.Resume();
Expand Down
1 change: 1 addition & 0 deletions OpenDreamRuntime/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public override void Init() {
_configManager.SetCVar(OpenDreamCVars.JsonPath, arg);
break;
}

if(_configManager.GetCVar(OpenDreamCVars.TracyEnable))
Profiler.ActivateTracy();

Expand Down
78 changes: 37 additions & 41 deletions OpenDreamRuntime/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace OpenDreamRuntime;

public static class Profiler
{
//whether these procs are NOPs or not
private static bool _tracyActvated = false;
public static class Profiler{
//whether these procs are NOPs or not. Defaults to false. Use ActivateTracy() to set true
private static bool _tracyActivated;

// Plot names need to be cached for the lifetime of the program
// seealso Tracy docs section 3.1
private static readonly Dictionary<string, CString> PlotNameCache = new();

public static void ActivateTracy() {
_tracyActvated = true;
_tracyActivated = true;
}

/// <summary>
Expand Down Expand Up @@ -44,17 +44,17 @@ public static void ActivateTracy() {
bool active = true,
uint color = 0,
string? text = null,
[CallerLineNumber] uint lineNumber = 0,
[CallerLineNumber] int lineNumber = 0,
[CallerFilePath] string? filePath = null,
[CallerMemberName] string? memberName = null)
{
if(!_tracyActvated)
if(!_tracyActivated)
return null;

using var filestr = GetCString(filePath, out var fileln);
using var memberstr = GetCString(memberName, out var memberln);
using var namestr = GetCString(zoneName, out var nameln);
var srcLocId = TracyAllocSrclocName(lineNumber, filestr, fileln, memberstr, memberln, namestr, nameln, color);
var srcLocId = TracyAllocSrclocName((uint)lineNumber, filestr, fileln, memberstr, memberln, namestr, nameln, color);
var context = TracyEmitZoneBeginAlloc(srcLocId, active ? 1 : 0);

if (text != null)
Expand Down Expand Up @@ -84,41 +84,44 @@ public static void ActivateTracy() {
/// <param name="color">
/// An <c>RRGGBB</c> color code that Tracy will use to color the plot in the profiler.
/// </param>
public static void PlotConfig(string name, PlotType type = PlotType.Number, bool step = false, bool fill = true, uint color = 0)
{
public static void PlotConfig(string name, PlotType type = PlotType.Number, bool step = false, bool fill = true, uint color = 0){
if(!_tracyActivated)
return;
var namestr = GetPlotCString(name);
TracyEmitPlotConfig(namestr, (int)type, step ? 1 : 0, fill ? 1 : 0, color);
}

/// <summary>
/// Add a <see langword="double"/> value to a plot.
/// </summary>
public static void Plot(string name, double val)
{
public static void Plot(string name, double val){
if(!_tracyActivated)
return;
var namestr = GetPlotCString(name);
TracyEmitPlot(namestr, val);
}

/// <summary>
/// Add a <see langword="float"/> value to a plot.
/// </summary>
public static void Plot(string name, int val)
{
public static void Plot(string name, int val){
if(!_tracyActivated)
return;
var namestr = GetPlotCString(name);
TracyEmitPlotInt(namestr, val);
}

/// <summary>
/// Add a <see langword="float"/> value to a plot.
/// </summary>
public static void Plot(string name, float val)
{
public static void Plot(string name, float val){
if(!_tracyActivated)
return;
var namestr = GetPlotCString(name);
TracyEmitPlotFloat(namestr, val);
}

private static CString GetPlotCString(string name)
{
private static CString GetPlotCString(string name){
if(!PlotNameCache.TryGetValue(name, out var plotCString))
{
plotCString = CString.FromString(name);
Expand All @@ -134,8 +137,9 @@ private static CString GetPlotCString(string name)
/// <remarks>
/// Viewable in the Info tab in the profiler.
/// </remarks>
public static void AppInfo(string appInfo)
{
public static void AppInfo(string appInfo){
if(!_tracyActivated)
return;
using var infostr = GetCString(appInfo, out var infoln);
TracyEmitMessageAppinfo(infostr, infoln);
}
Expand All @@ -146,9 +150,8 @@ public static void AppInfo(string appInfo)
/// <remarks>
/// Tracy Cpp API and docs refer to this as the <c>FrameMark</c> macro.
/// </remarks>
public static void EmitFrameMark()
{
if(!_tracyActvated)
public static void EmitFrameMark(){
if(!_tracyActivated)
return;
TracyEmitFrameMark(null);
}
Expand All @@ -157,17 +160,17 @@ public static void EmitFrameMark()
/// Is the app connected to the external profiler?
/// </summary>
/// <returns></returns>
public static bool IsConnected()
{
public static bool IsConnected(){
if(!_tracyActivated)
return false;
return TracyConnected() != 0;
}

/// <summary>
/// Creates a <seealso cref="CString"/> for use by Tracy. Also returns the
/// length of the string for interop convenience.
/// </summary>
public static CString GetCString(string? fromString, out ulong clength)
{
public static CString GetCString(string? fromString, out ulong clength){
if (fromString == null)
{
clength = 0;
Expand All @@ -178,8 +181,7 @@ public static CString GetCString(string? fromString, out ulong clength)
return CString.FromString(fromString);
}

public enum PlotType
{
public enum PlotType{
/// <summary>
/// Values will be displayed as plain numbers.
/// </summary>
Expand All @@ -197,38 +199,32 @@ public enum PlotType
}
}

public readonly struct ProfilerZone : IDisposable
{
public readonly struct ProfilerZone : IDisposable{
public readonly TracyCZoneCtx Context;

public uint Id => Context.Data.Id;

public int Active => Context.Data.Active;

internal ProfilerZone(TracyCZoneCtx context)
{
internal ProfilerZone(TracyCZoneCtx context){
Context = context;
}

public void EmitName(string name)
{
public void EmitName(string name){
using var namestr = Profiler.GetCString(name, out var nameln);
TracyEmitZoneName(Context, namestr, nameln);
}

public void EmitColor(uint color)
{
public void EmitColor(uint color){
TracyEmitZoneColor(Context, color);
}

public void EmitText(string text)
{
public void EmitText(string text){
using var textstr = Profiler.GetCString(text, out var textln);
TracyEmitZoneText(Context, textstr, textln);
}

public void Dispose()
{
public void Dispose(){
TracyEmitZoneEnd(Context);
}
}
3 changes: 2 additions & 1 deletion OpenDreamShared/OpenDreamCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Robust.Shared.Configuration;

namespace OpenDreamShared;

[CVarDefs]
public abstract class OpenDreamCVars {
public static readonly CVarDef<string> JsonPath =

Check notice

Code scanning / InspectCode

Replace built-in type reference with a CLR type name or a keyword in static member access expressions Note

Built-in type reference is inconsistent with code style settings
Expand All @@ -26,7 +27,7 @@ public abstract class OpenDreamCVars {
CVarDef.Create<ushort>("opendream.topic_port", 25567, CVar.SERVERONLY);

public static readonly CVarDef<bool> TracyEnable =
CVarDef.Create<bool>("opendream.enable_tracy", false, CVar.SERVERONLY);
CVarDef.Create("opendream.enable_tracy", false, CVar.SERVERONLY);

/*
* INFOLINKS
Expand Down

0 comments on commit 604d7d6

Please sign in to comment.