Permalink
Browse files

json: Optimize writing a bit.

This improves the responsiveness of certain APIs.
  • Loading branch information...
unknownbrackets committed May 1, 2018
1 parent ccea863 commit fc8ad3b47b77be43ab569845b93861d8c878a11f
@@ -91,7 +91,7 @@ void WebSocketCPUStatus(DebuggerRequest &req) {
json.writeBool("stepping", PSP_IsInited() && Core_IsStepping() && coreState != CORE_POWERDOWN);
json.writeBool("paused", GetUIState() != UISTATE_INGAME);
// Avoid NULL deference.
json.writeFloat("pc", PSP_IsInited() ? currentMIPS->pc : 0);
json.writeUint("pc", PSP_IsInited() ? currentMIPS->pc : 0);
// A double ought to be good enough for a 156 day debug session.
json.writeFloat("ticks", PSP_IsInited() ? CoreTiming::GetTicks() : 0);
}
@@ -131,11 +131,11 @@ void WebSocketCPUGetAllRegs(DebuggerRequest &req) {
json.pushArray("uintValues");
// Writing as floating point to avoid negatives. Actually double, so safe.
for (int r = 0; r < total; ++r)
json.writeFloat(currentDebugMIPS->GetRegValue(c, r));
json.writeUint(currentDebugMIPS->GetRegValue(c, r));
if (c == 0) {
json.writeFloat(currentDebugMIPS->GetPC());
json.writeFloat(currentDebugMIPS->GetHi());
json.writeFloat(currentDebugMIPS->GetLo());
json.writeUint(currentDebugMIPS->GetPC());
json.writeUint(currentDebugMIPS->GetHi());
json.writeUint(currentDebugMIPS->GetLo());
}
json.pop();
@@ -267,7 +267,7 @@ void WebSocketCPUGetReg(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
json.writeInt("category", cat);
json.writeInt("register", reg);
json.writeFloat("uintValue", val);
json.writeUint("uintValue", val);
json.writeString("floatValue", RegValueAsFloat(val));
}
@@ -335,7 +335,7 @@ void WebSocketCPUSetReg(DebuggerRequest &req) {
// Repeat it back just to avoid confusion on how it parsed.
json.writeInt("category", cat);
json.writeInt("register", reg);
json.writeFloat("uintValue", val);
json.writeUint("uintValue", val);
json.writeString("floatValue", RegValueAsFloat(val));
}
@@ -368,6 +368,6 @@ void WebSocketCPUEvaluate(DebuggerRequest &req) {
}
JsonWriter &json = req.Respond();
json.writeFloat("uintValue", val);
json.writeUint("uintValue", val);
json.writeString("floatValue", RegValueAsFloat(val));
}
@@ -63,17 +63,17 @@ void WebSocketDisasmState::WriteDisasmLine(JsonWriter &json, const DisassemblyLi
else if (l.type == DISTYPE_OTHER)
json.writeString("type", "other");
json.writeFloat("address", addr);
json.writeUint("address", addr);
json.writeInt("addressSize", l.totalSize);
json.writeFloat("encoding", Memory::IsValidAddress(addr) ? Memory::Read_Instruction(addr).encoding : 0);
json.writeUint("encoding", Memory::IsValidAddress(addr) ? Memory::Read_Instruction(addr).encoding : 0);
if (l.totalSize >= 8 && Memory::IsValidRange(addr, l.totalSize)) {
json.pushArray("macroEncoding");
for (u32 off = 0; off < l.totalSize; off += 4) {
json.writeFloat(Memory::Read_Instruction(addr + off).encoding);
json.writeUint(Memory::Read_Instruction(addr + off).encoding);
}
json.pop();
} else {
json.writeRaw("macroEncoding", "null");
json.writeNull("macroEncoding");
}
int c = currentDebugMIPS->getColor(addr) & 0x00FFFFFF;
json.writeString("backgroundColor", StringFromFormat("#%02x%02x%02x", c & 0xFF, (c >> 8) & 0xFF, c >> 16));
@@ -82,7 +82,7 @@ void WebSocketDisasmState::WriteDisasmLine(JsonWriter &json, const DisassemblyLi
const std::string addressSymbol = g_symbolMap->GetLabelString(addr);
if (addressSymbol.empty())
json.writeRaw("symbol", "null");
json.writeNull("symbol");
else
json.writeString("symbol", addressSymbol);
@@ -95,10 +95,10 @@ void WebSocketDisasmState::WriteDisasmLine(JsonWriter &json, const DisassemblyLi
if (cond)
json.writeString("expression", cond->expressionString);
else
json.writeRaw("expression", "null");
json.writeNull("expression");
json.pop();
} else {
json.writeRaw("breakpoint", "null");
json.writeNull("breakpoint");
}
json.writeBool("isCurrentPC", currentDebugMIPS->GetPC() == addr);
@@ -107,79 +107,79 @@ void WebSocketDisasmState::WriteDisasmLine(JsonWriter &json, const DisassemblyLi
std::string targetSymbol;
if (!l.info.isBranchToRegister) {
targetSymbol = g_symbolMap->GetLabelString(l.info.branchTarget);
json.writeFloat("targetAddress", l.info.branchTarget);
json.writeRaw("register", "null");
json.writeUint("targetAddress", l.info.branchTarget);
json.writeNull("register");
} else {
json.writeRaw("targetAddress", "null");
json.writeNull("targetAddress");
json.writeInt("register", l.info.branchRegisterNum);
}
json.writeBool("isLinked", l.info.isLinkedBranch);
json.writeBool("isLikely", l.info.isLikelyBranch);
if (targetSymbol.empty())
json.writeRaw("symbol", "null");
json.writeNull("symbol");
else
json.writeString("symbol", targetSymbol);
json.pop();
} else {
json.writeRaw("branch", "null");
json.writeNull("branch");
}
if (l.info.hasRelevantAddress) {
json.pushDict("relevantData");
json.writeFloat("address", l.info.relevantAddress);
json.writeUint("address", l.info.relevantAddress);
if (Memory::IsValidRange(l.info.relevantAddress, 4))
json.writeFloat("uintValue", Memory::ReadUnchecked_U32(l.info.relevantAddress));
json.writeUint("uintValue", Memory::ReadUnchecked_U32(l.info.relevantAddress));
else
json.writeRaw("uintValue", "null");
json.writeNull("uintValue");
json.pop();
} else {
json.writeRaw("relevantData", "null");
json.writeNull("relevantData");
}
if (l.info.isConditional)
json.writeBool("conditionMet", l.info.conditionMet);
else
json.writeRaw("conditionMet", "null");
json.writeNull("conditionMet");
if (l.info.isDataAccess) {
json.pushDict("dataAccess");
json.writeFloat("address", l.info.dataAddress);
json.writeUint("address", l.info.dataAddress);
json.writeInt("size", l.info.dataSize);
std::string dataSymbol = g_symbolMap->GetLabelString(l.info.dataAddress);
std::string valueSymbol;
if (!Memory::IsValidRange(l.info.dataAddress, l.info.dataSize))
json.writeRaw("uintValue", "null");
json.writeNull("uintValue");
else if (l.info.dataSize == 1)
json.writeFloat("uintValue", Memory::ReadUnchecked_U8(l.info.dataAddress));
json.writeUint("uintValue", Memory::ReadUnchecked_U8(l.info.dataAddress));
else if (l.info.dataSize == 2)
json.writeFloat("uintValue", Memory::ReadUnchecked_U16(l.info.dataAddress));
json.writeUint("uintValue", Memory::ReadUnchecked_U16(l.info.dataAddress));
else if (l.info.dataSize >= 4) {
u32 data = Memory::ReadUnchecked_U32(l.info.dataAddress);
valueSymbol = g_symbolMap->GetLabelString(data);
json.writeFloat("uintValue", data);
json.writeUint("uintValue", data);
}
if (!dataSymbol.empty())
json.writeString("symbol", dataSymbol);
else
json.writeRaw("symbol", "null");
json.writeNull("symbol");
if (!valueSymbol.empty())
json.writeString("valueSymbol", valueSymbol);
else
json.writeRaw("valueSymbol", "null");
json.writeNull("valueSymbol");
json.pop();
} else {
json.writeRaw("dataAccess", "null");
json.writeNull("dataAccess");
}
json.pop();
}
void WebSocketDisasmState::WriteBranchGuide(JsonWriter &json, const BranchLine &l) {
json.pushDict();
json.writeFloat("top", l.first);
json.writeFloat("bottom", l.second);
json.writeUint("top", l.first);
json.writeUint("bottom", l.second);
if (l.type == LINE_UP)
json.writeString("direction", "up");
else if (l.type == LINE_DOWN)
@@ -279,8 +279,8 @@ void WebSocketDisasmState::Disasm(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
json.pushDict("range");
json.writeFloat("start", start);
json.writeFloat("end", end);
json.writeUint("start", start);
json.writeUint("end", end);
json.pop();
json.pushArray("lines");
@@ -34,7 +34,7 @@ struct GameStatusEvent {
j.writeString("title", g_paramSFO.GetValueString("TITLE"));
j.pop();
} else {
j.writeRaw("game", "null");
j.writeNull("game");
}
j.end();
return j.str();
@@ -46,7 +46,7 @@ void WebSocketGameStatus(DebuggerRequest &req) {
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
json.pop();
} else {
json.writeRaw("game", "null");
json.writeNull("game");
}
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
}
@@ -27,7 +27,7 @@ struct CPUSteppingEvent {
JsonWriter j;
j.begin();
j.writeString("event", "cpu.stepping");
j.writeFloat("pc", currentMIPS->pc);
j.writeUint("pc", currentMIPS->pc);
// A double ought to be good enough for a 156 day debug session.
j.writeFloat("ticks", CoreTiming::GetTicks());
j.end();
Oops, something went wrong.

0 comments on commit fc8ad3b

Please sign in to comment.