Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: base/debug/trace_event_impl.cc

Issue 26249002: Non-US OS region generates invalid trace JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add fixme Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // FIXME: base/json/json_writer.cc is using the same code,
515 // should be made into a common method.
516 std::string real = DoubleToString(value.as_double);
517 // Ensure that the number has a .0 if there's no decimal or 'e'. This
518 // makes sure that when we read the JSON back, it's interpreted as a
519 // real rather than an int.
520 if (real.find('.') == std::string::npos &&
521 real.find('e') == std::string::npos &&
522 real.find('E') == std::string::npos) {
523 real.append(".0");
524 }
525 // The JSON spec requires that non-integer values in the range (-1,1)
526 // have a zero before the decimal point - ".52" is not valid, "0.52" is.
527 if (real[0] == '.') {
528 real.insert(0, "0");
529 } else if (real.length() > 1 && real[0] == '-' && real[1] == '.') {
530 // "-.1" bad "-0.1" good
531 real.insert(1, "0");
532 }
533
534 StringAppendF(out, "%s", real.c_str());
514 break; 535 break;
536 }
515 case TRACE_VALUE_TYPE_POINTER: 537 case TRACE_VALUE_TYPE_POINTER:
516 // JSON only supports double and int numbers. 538 // JSON only supports double and int numbers.
517 // So as not to lose bits from a 64-bit pointer, output as a hex string. 539 // So as not to lose bits from a 64-bit pointer, output as a hex string.
518 StringAppendF(out, "\"0x%" PRIx64 "\"", static_cast<uint64>( 540 StringAppendF(out, "\"0x%" PRIx64 "\"", static_cast<uint64>(
519 reinterpret_cast<intptr_t>( 541 reinterpret_cast<intptr_t>(
520 value.as_pointer))); 542 value.as_pointer)));
521 break; 543 break;
522 case TRACE_VALUE_TYPE_STRING: 544 case TRACE_VALUE_TYPE_STRING:
523 case TRACE_VALUE_TYPE_COPY_STRING: 545 case TRACE_VALUE_TYPE_COPY_STRING:
524 *out += "\""; 546 *out += "\"";
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 0, // num_args 2092 0, // num_args
2071 NULL, // arg_names 2093 NULL, // arg_names
2072 NULL, // arg_types 2094 NULL, // arg_types
2073 NULL, // arg_values 2095 NULL, // arg_values
2074 NULL, // convertable values 2096 NULL, // convertable values
2075 TRACE_EVENT_FLAG_NONE); // flags 2097 TRACE_EVENT_FLAG_NONE); // flags
2076 } 2098 }
2077 } 2099 }
2078 2100
2079 } // namespace trace_event_internal 2101 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698