Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/leak_annotations.h" | 12 #include "base/debug/leak_annotations.h" |
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
| 14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_tokenizer.h" | 22 #include "base/strings/string_tokenizer.h" |
| 22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/synchronization/cancellation_flag.h" | 26 #include "base/synchronization/cancellation_flag.h" |
| 26 #include "base/synchronization/waitable_event.h" | 27 #include "base/synchronization/waitable_event.h" |
| 27 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
| 28 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 29 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 29 #include "base/threading/platform_thread.h" | 30 #include "base/threading/platform_thread.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 switch (type) { | 503 switch (type) { |
| 503 case TRACE_VALUE_TYPE_BOOL: | 504 case TRACE_VALUE_TYPE_BOOL: |
| 504 *out += value.as_bool ? "true" : "false"; | 505 *out += value.as_bool ? "true" : "false"; |
| 505 break; | 506 break; |
| 506 case TRACE_VALUE_TYPE_UINT: | 507 case TRACE_VALUE_TYPE_UINT: |
| 507 StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint)); | 508 StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint)); |
| 508 break; | 509 break; |
| 509 case TRACE_VALUE_TYPE_INT: | 510 case TRACE_VALUE_TYPE_INT: |
| 510 StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int)); | 511 StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int)); |
| 511 break; | 512 break; |
| 512 case TRACE_VALUE_TYPE_DOUBLE: | 513 case TRACE_VALUE_TYPE_DOUBLE: { |
| 513 StringAppendF(out, "%f", value.as_double); | 514 std::string real = DoubleToString(value.as_double); |
|
dsinclair
2013/10/07 14:26:51
Can we add a TODO in here since this is the same a
Erik Dahlström (inactive)
2013/10/07 15:00:52
Done.
| |
| 515 // Ensure that the number has a .0 if there's no decimal or 'e'. This | |
| 516 // makes sure that when we read the JSON back, it's interpreted as a | |
| 517 // real rather than an int. | |
| 518 if (real.find('.') == std::string::npos && | |
| 519 real.find('e') == std::string::npos && | |
| 520 real.find('E') == std::string::npos) { | |
| 521 real.append(".0"); | |
| 522 } | |
| 523 // The JSON spec requires that non-integer values in the range (-1,1) | |
| 524 // have a zero before the decimal point - ".52" is not valid, "0.52" is. | |
| 525 if (real[0] == '.') { | |
| 526 real.insert(0, "0"); | |
| 527 } else if (real.length() > 1 && real[0] == '-' && real[1] == '.') { | |
| 528 // "-.1" bad "-0.1" good | |
| 529 real.insert(1, "0"); | |
| 530 } | |
| 531 | |
| 532 StringAppendF(out, "%s", real.c_str()); | |
| 514 break; | 533 break; |
| 534 } | |
| 515 case TRACE_VALUE_TYPE_POINTER: | 535 case TRACE_VALUE_TYPE_POINTER: |
| 516 // JSON only supports double and int numbers. | 536 // JSON only supports double and int numbers. |
| 517 // So as not to lose bits from a 64-bit pointer, output as a hex string. | 537 // So as not to lose bits from a 64-bit pointer, output as a hex string. |
| 518 StringAppendF(out, "\"0x%" PRIx64 "\"", static_cast<uint64>( | 538 StringAppendF(out, "\"0x%" PRIx64 "\"", static_cast<uint64>( |
| 519 reinterpret_cast<intptr_t>( | 539 reinterpret_cast<intptr_t>( |
| 520 value.as_pointer))); | 540 value.as_pointer))); |
| 521 break; | 541 break; |
| 522 case TRACE_VALUE_TYPE_STRING: | 542 case TRACE_VALUE_TYPE_STRING: |
| 523 case TRACE_VALUE_TYPE_COPY_STRING: | 543 case TRACE_VALUE_TYPE_COPY_STRING: |
| 524 *out += "\""; | 544 *out += "\""; |
| (...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2070 0, // num_args | 2090 0, // num_args |
| 2071 NULL, // arg_names | 2091 NULL, // arg_names |
| 2072 NULL, // arg_types | 2092 NULL, // arg_types |
| 2073 NULL, // arg_values | 2093 NULL, // arg_values |
| 2074 NULL, // convertable values | 2094 NULL, // convertable values |
| 2075 TRACE_EVENT_FLAG_NONE); // flags | 2095 TRACE_EVENT_FLAG_NONE); // flags |
| 2076 } | 2096 } |
| 2077 } | 2097 } |
| 2078 | 2098 |
| 2079 } // namespace trace_event_internal | 2099 } // namespace trace_event_internal |
| OLD | NEW |