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

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

Issue 1076443002: Removed obsolete float_util.h as VS2013 supports standards well enough. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fixed mistake in value converter. Created 5 years, 8 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 | « base/time/time.cc ('k') | base/values.cc » ('j') | 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/trace_event/trace_event_impl.h" 5 #include "base/trace_event/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath>
8 9
9 #include "base/base_switches.h" 10 #include "base/base_switches.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/debug/leak_annotations.h" 13 #include "base/debug/leak_annotations.h"
13 #include "base/float_util.h"
14 #include "base/format_macros.h" 14 #include "base/format_macros.h"
15 #include "base/json/string_escape.h" 15 #include "base/json/string_escape.h"
16 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
17 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/process/process_metrics.h" 19 #include "base/process/process_metrics.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/strings/string_tokenizer.h" 23 #include "base/strings/string_tokenizer.h"
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint)); 640 StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint));
641 break; 641 break;
642 case TRACE_VALUE_TYPE_INT: 642 case TRACE_VALUE_TYPE_INT:
643 StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int)); 643 StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int));
644 break; 644 break;
645 case TRACE_VALUE_TYPE_DOUBLE: { 645 case TRACE_VALUE_TYPE_DOUBLE: {
646 // FIXME: base/json/json_writer.cc is using the same code, 646 // FIXME: base/json/json_writer.cc is using the same code,
647 // should be made into a common method. 647 // should be made into a common method.
648 std::string real; 648 std::string real;
649 double val = value.as_double; 649 double val = value.as_double;
650 if (IsFinite(val)) { 650 if (std::isfinite(val)) {
651 real = DoubleToString(val); 651 real = DoubleToString(val);
652 // Ensure that the number has a .0 if there's no decimal or 'e'. This 652 // Ensure that the number has a .0 if there's no decimal or 'e'. This
653 // makes sure that when we read the JSON back, it's interpreted as a 653 // makes sure that when we read the JSON back, it's interpreted as a
654 // real rather than an int. 654 // real rather than an int.
655 if (real.find('.') == std::string::npos && 655 if (real.find('.') == std::string::npos &&
656 real.find('e') == std::string::npos && 656 real.find('e') == std::string::npos &&
657 real.find('E') == std::string::npos) { 657 real.find('E') == std::string::npos) {
658 real.append(".0"); 658 real.append(".0");
659 } 659 }
660 // The JSON spec requires that non-integer values in the range (-1,1) 660 // The JSON spec requires that non-integer values in the range (-1,1)
661 // have a zero before the decimal point - ".52" is not valid, "0.52" is. 661 // have a zero before the decimal point - ".52" is not valid, "0.52" is.
662 if (real[0] == '.') { 662 if (real[0] == '.') {
663 real.insert(0, "0"); 663 real.insert(0, "0");
664 } else if (real.length() > 1 && real[0] == '-' && real[1] == '.') { 664 } else if (real.length() > 1 && real[0] == '-' && real[1] == '.') {
665 // "-.1" bad "-0.1" good 665 // "-.1" bad "-0.1" good
666 real.insert(1, "0"); 666 real.insert(1, "0");
667 } 667 }
668 } else if (IsNaN(val)){ 668 } else if (std::isnan(val)){
669 // The JSON spec doesn't allow NaN and Infinity (since these are 669 // The JSON spec doesn't allow NaN and Infinity (since these are
670 // objects in EcmaScript). Use strings instead. 670 // objects in EcmaScript). Use strings instead.
671 real = "\"NaN\""; 671 real = "\"NaN\"";
672 } else if (val < 0) { 672 } else if (val < 0) {
673 real = "\"-Infinity\""; 673 real = "\"-Infinity\"";
674 } else { 674 } else {
675 real = "\"Infinity\""; 675 real = "\"Infinity\"";
676 } 676 }
677 StringAppendF(out, "%s", real.c_str()); 677 StringAppendF(out, "%s", real.c_str());
678 break; 678 break;
(...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after
2634 } 2634 }
2635 2635
2636 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2636 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2637 if (*category_group_enabled_) { 2637 if (*category_group_enabled_) {
2638 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2638 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2639 name_, event_handle_); 2639 name_, event_handle_);
2640 } 2640 }
2641 } 2641 }
2642 2642
2643 } // namespace trace_event_internal 2643 } // namespace trace_event_internal
OLDNEW
« no previous file with comments | « base/time/time.cc ('k') | base/values.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698