Skip to content

Commit

Permalink
Output bool values as JSON booleans, not strings
Browse files Browse the repository at this point in the history
Summary:
Initially, we were outputting boolean values as strings (`"True"`/`"False"`, sometimes lowercase). For easier processing of the resulting JSON, we should output these as JSON booleans (`true`/`false`).

Also, noticed that when logging boolean command line arguments, we didn't output the `"kind"` field. Added that for consistency.

Differential Revision: D54421694

fbshipit-source-id: da5c047442933b6925ff51db684544404b59ab1d
  • Loading branch information
elliekorn authored and facebook-github-bot committed Mar 1, 2024
1 parent 6af59e3 commit 8e03cd9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions AbstractMemorySnapshot/IStructuredOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IStructuredOutput

void AddProperty(string key, long value);

void AddProperty(string key, bool value);

void AddDisplayString(string message);

void AddDisplayString(string format, params object[] args);
Expand Down
4 changes: 4 additions & 0 deletions AnalysisTests/MockStructuredOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public void AddProperty(string key, long value)
{
}

public void AddProperty(string key, bool value)
{
}

public void AddDisplayString(string message)
{
}
Expand Down
4 changes: 2 additions & 2 deletions CommandInfrastructure/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void DescribeAddress(NativeWord addressOfValue, StringBuilder sb)
MemoryView memoryView = segmentedHeap.GetMemoryViewForAddress(addressOfValue);
if (!memoryView.IsValid)
{
Output.AddProperty("addressMapped", "false");
Output.AddProperty("addressMapped", false);
sb.AppendFormat("{0}: not in mapped memory", addressOfValue);
return;
}
Expand All @@ -175,7 +175,7 @@ public void DescribeAddress(NativeWord addressOfValue, StringBuilder sb)
postorderIndex = CurrentTracedHeap.ObjectAddressToPostorderIndex(nativeValue);
if (postorderIndex != -1)
{
Output.AddProperty("pointerTo", "True");
Output.AddProperty("pointerTo", true);
sb.Append("pointer to ");
DescribeObject(postorderIndex, nativeValue, sb);
return;
Expand Down
12 changes: 6 additions & 6 deletions CommandInfrastructure/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,20 @@ public void DumpToStructuredOutput(IStructuredOutput output)

output.BeginChild("traceableHeap");
output.AddProperty("kind", m_traceableHeap_kind.ToString());
output.AddProperty("fuseObjectPairs", m_traceableHeap_fuseObjectPairs.ToString());
output.AddProperty("fuseObjectPairs", m_traceableHeap_fuseObjectPairs);
DumpReferenceClassifiersToStructuredOutput(output);
if (m_currentTraceableHeap != null)
{
output.AddProperty("description", m_currentTraceableHeap.Description);
output.AddProperty("numberOfTypeIndices", m_currentTraceableHeap.TypeSystem.NumberOfTypeIndices);
output.AddProperty("numberOfObjectPairs", m_currentTraceableHeap.NumberOfObjectPairs);
output.AddProperty("withMemory", (m_currentTraceableHeap.SegmentedHeapOpt != null).ToString());
output.AddProperty("withMemory", m_currentTraceableHeap.SegmentedHeapOpt != null);
}
output.EndChild();

output.BeginChild("rootSet");
output.AddProperty("singleRootAddress", m_rootSet_singletonRootAddress.ToString());
output.AddProperty("weakGChandles", m_rootSet_weakGCHandles.ToString());
output.AddProperty("weakGChandles", m_rootSet_weakGCHandles);
if (m_currentRootSet != null)
{
output.AddProperty("numberOfRoots", m_currentRootSet.NumberOfRoots);
Expand All @@ -238,10 +238,10 @@ public void DumpToStructuredOutput(IStructuredOutput output)
output.EndChild();

output.BeginChild("backtracer");
output.AddProperty("groupStatics", m_backtracer_groupStatics.ToString());
output.AddProperty("groupStatics", m_backtracer_groupStatics);
Backtracer_ReferencesToIgnore_DumpToStructuredOutput(output);
output.AddProperty("fuseRoots", m_backtracer_fuseRoots.ToString());
output.AddProperty("computed", (m_currentBacktracer != null).ToString());
output.AddProperty("fuseRoots", m_backtracer_fuseRoots);
output.AddProperty("computed", m_currentBacktracer != null);
output.EndChild();

output.BeginChild("heapDom");
Expand Down
6 changes: 6 additions & 0 deletions CommandInfrastructure/JsonStructuredOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void AddProperty(string key, long value)
m_chainedStructuredOutput?.AddProperty(key, value);
}

public void AddProperty(string key, bool value)
{
m_cursor.AsObject().Add(key, value);
m_chainedStructuredOutput?.AddProperty(key, value);
}

public void AddDisplayString(string message)
{
CurrentDisplayString?.Append(message);
Expand Down
4 changes: 4 additions & 0 deletions CommandInfrastructure/PassthroughStructuredOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public void AddProperty(string key, long value)
{
}

public void AddProperty(string key, bool value)
{
}

public void AddDisplayString(string message)
{
m_output.Write(message);
Expand Down
3 changes: 2 additions & 1 deletion CommandInfrastructure/Repl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ void AssignArgumentValues(Command command, CommandLine commandLine)
field.SetValue(command, value ? 1 : 0);
}
m_structuredOutput.BeginChild(field.Name);
m_structuredOutput.AddProperty("value", value.ToString());
m_structuredOutput.AddProperty("kind", "boolean");
m_structuredOutput.AddProperty("value", value);
m_structuredOutput.EndChild();
}
}
Expand Down
4 changes: 2 additions & 2 deletions Commands/DumpTypeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void DumpType(int typeIndex, int indent)
int fieldTypeIndex = typeSystem.FieldType(typeIndex, fieldNumber);
if (Statics && isStatic || !Statics && !isStatic)
{
Output.AddProperty("isStatic", typeSystem.FieldIsStatic(typeIndex, fieldNumber).ToString());
Output.AddProperty("isStatic", typeSystem.FieldIsStatic(typeIndex, fieldNumber));
Output.AddProperty("fieldName", typeSystem.FieldName(typeIndex, fieldNumber));
Output.AddProperty("fieldNumber", fieldNumber);
Output.AddProperty("fieldOffset", typeSystem.FieldOffset(typeIndex, fieldNumber, withHeader: true));
Expand All @@ -125,7 +125,7 @@ void DumpType(int typeIndex, int indent)
}
else
{
Output.AddProperty("isInitialized", "false");
Output.AddProperty("isInitialized", false);
Output.AddDisplayStringLineIndented(indent + 2, "Uninitialized");
}
}
Expand Down

0 comments on commit 8e03cd9

Please sign in to comment.