summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-24 01:10:50 +0000
committerrbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-24 01:10:50 +0000
commit1f003e13881887ae92f33b56123752a04b315190 (patch)
tree6869691d3a8f4d62511f1606d8468d6108d20ddb
parent6d8528630b4841afa5a9b0c09be17d9f74d779db (diff)
downloadchromium_src-1f003e13881887ae92f33b56123752a04b315190.zip
chromium_src-1f003e13881887ae92f33b56123752a04b315190.tar.gz
chromium_src-1f003e13881887ae92f33b56123752a04b315190.tar.bz2
Update trace file format for NaN/Infinit values to use strings
Turns out my previous fix was inadequate - the trace viewer doesn't expect null values for arguments. Instead just use hard-coded strings (better anyway since it's clearer to the user what happened). BUG=336787 Review URL: https://codereview.chromium.org/135573004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246758 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/debug/trace_event_impl.cc10
-rw-r--r--base/debug/trace_event_unittest.cc20
2 files changed, 21 insertions, 9 deletions
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index abcfff1..f5e3ec6 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -656,10 +656,14 @@ void TraceEvent::AppendValueAsJSON(unsigned char type,
// "-.1" bad "-0.1" good
real.insert(1, "0");
}
- } else {
+ } else if (IsNaN(val)){
// The JSON spec doesn't allow NaN and Infinity (since these are
- // objects in EcmaScript). In practice null is substituted for them.
- real = "null";
+ // objects in EcmaScript). Use strings instead.
+ real = "\"NaN\"";
+ } else if (val < 0) {
+ real = "\"-Infinity\"";
+ } else {
+ real = "\"Infinity\"";
}
StringAppendF(out, "%s", real.c_str());
break;
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index c942bc7..22a3270 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -2001,6 +2001,8 @@ TEST_F(TraceEventTestFixture, PrimitiveArgs) {
TRACE_EVENT1("foo", "event5", "float_neghalf", -.5f);
TRACE_EVENT1("foo", "event6", "float_infinity",
std::numeric_limits<float>::infinity());
+ TRACE_EVENT1("foo", "event6b", "float_neg_infinity",
+ -std::numeric_limits<float>::infinity());
TRACE_EVENT1("foo", "event7", "double_nan",
std::numeric_limits<double>::quiet_NaN());
void* p = 0;
@@ -2063,21 +2065,27 @@ TEST_F(TraceEventTestFixture, PrimitiveArgs) {
EXPECT_TRUE(value->GetAsDouble(&double_value));
EXPECT_EQ(-0.5, double_value);
- // Infinity can only be serlized to JSON as null.
+ // Infinity is serialized to JSON as a string.
dict = FindNamePhase("event6", "X");
ASSERT_TRUE(dict);
dict->GetDictionary("args", &args_dict);
ASSERT_TRUE(args_dict);
- EXPECT_TRUE(args_dict->Get("float_infinity", &value));
- EXPECT_TRUE(value->IsType(Value::TYPE_NULL));
+ EXPECT_TRUE(args_dict->GetString("float_infinity", &str_value));
+ EXPECT_STREQ("Infinity", str_value.c_str());
+ dict = FindNamePhase("event6b", "X");
+ ASSERT_TRUE(dict);
+ dict->GetDictionary("args", &args_dict);
+ ASSERT_TRUE(args_dict);
+ EXPECT_TRUE(args_dict->GetString("float_neg_infinity", &str_value));
+ EXPECT_STREQ("-Infinity", str_value.c_str());
- // NaN can only be serlized to JSON as null.
+ // NaN is serialized to JSON as a string.
dict = FindNamePhase("event7", "X");
ASSERT_TRUE(dict);
dict->GetDictionary("args", &args_dict);
ASSERT_TRUE(args_dict);
- EXPECT_TRUE(args_dict->Get("double_nan", &value));
- EXPECT_TRUE(value->IsType(Value::TYPE_NULL));
+ EXPECT_TRUE(args_dict->GetString("double_nan", &str_value));
+ EXPECT_STREQ("NaN", str_value.c_str());
// NULL pointers should be serialized as "0x0".
dict = FindNamePhase("event8", "X");