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/test/trace_event_analyzer.h" | 5 #include "base/test/trace_event_analyzer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <math.h> | 8 #include <math.h> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 bool TraceEvent::SetFromJSON(const base::Value* event_value) { | 29 bool TraceEvent::SetFromJSON(const base::Value* event_value) { |
30 if (event_value->GetType() != base::Value::TYPE_DICTIONARY) { | 30 if (event_value->GetType() != base::Value::TYPE_DICTIONARY) { |
31 LOG(ERROR) << "Value must be TYPE_DICTIONARY"; | 31 LOG(ERROR) << "Value must be TYPE_DICTIONARY"; |
32 return false; | 32 return false; |
33 } | 33 } |
34 const base::DictionaryValue* dictionary = | 34 const base::DictionaryValue* dictionary = |
35 static_cast<const base::DictionaryValue*>(event_value); | 35 static_cast<const base::DictionaryValue*>(event_value); |
36 | 36 |
37 std::string phase_str; | 37 std::string phase_str; |
38 base::DictionaryValue* args = NULL; | 38 const base::DictionaryValue* args = NULL; |
39 | 39 |
40 if (!dictionary->GetString("ph", &phase_str)) { | 40 if (!dictionary->GetString("ph", &phase_str)) { |
41 LOG(ERROR) << "ph is missing from TraceEvent JSON"; | 41 LOG(ERROR) << "ph is missing from TraceEvent JSON"; |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 phase = *phase_str.data(); | 45 phase = *phase_str.data(); |
46 | 46 |
47 bool require_origin = (phase != TRACE_EVENT_PHASE_METADATA); | 47 bool require_origin = (phase != TRACE_EVENT_PHASE_METADATA); |
48 bool require_id = (phase == TRACE_EVENT_PHASE_ASYNC_BEGIN || | 48 bool require_id = (phase == TRACE_EVENT_PHASE_ASYNC_BEGIN || |
(...skipping 29 matching lines...) Expand all Loading... |
78 return false; | 78 return false; |
79 } | 79 } |
80 | 80 |
81 // For each argument, copy the type and create a trace_analyzer::TraceValue. | 81 // For each argument, copy the type and create a trace_analyzer::TraceValue. |
82 base::DictionaryValue::key_iterator keyi = args->begin_keys(); | 82 base::DictionaryValue::key_iterator keyi = args->begin_keys(); |
83 for (; keyi != args->end_keys(); ++keyi) { | 83 for (; keyi != args->end_keys(); ++keyi) { |
84 std::string str; | 84 std::string str; |
85 bool boolean = false; | 85 bool boolean = false; |
86 int int_num = 0; | 86 int int_num = 0; |
87 double double_num = 0.0; | 87 double double_num = 0.0; |
88 Value* value = NULL; | 88 const Value* value = NULL; |
89 if (args->GetWithoutPathExpansion(*keyi, &value)) { | 89 if (args->GetWithoutPathExpansion(*keyi, &value)) { |
90 if (value->GetAsString(&str)) | 90 if (value->GetAsString(&str)) |
91 arg_strings[*keyi] = str; | 91 arg_strings[*keyi] = str; |
92 else if (value->GetAsInteger(&int_num)) | 92 else if (value->GetAsInteger(&int_num)) |
93 arg_numbers[*keyi] = static_cast<double>(int_num); | 93 arg_numbers[*keyi] = static_cast<double>(int_num); |
94 else if (value->GetAsBoolean(&boolean)) | 94 else if (value->GetAsBoolean(&boolean)) |
95 arg_numbers[*keyi] = static_cast<double>(boolean ? 1 : 0); | 95 arg_numbers[*keyi] = static_cast<double>(boolean ? 1 : 0); |
96 else if (value->GetAsDouble(&double_num)) | 96 else if (value->GetAsDouble(&double_num)) |
97 arg_numbers[*keyi] = double_num; | 97 arg_numbers[*keyi] = double_num; |
98 else { | 98 else { |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 end_position = (end_position < events.size()) ? end_position : events.size(); | 950 end_position = (end_position < events.size()) ? end_position : events.size(); |
951 size_t count = 0u; | 951 size_t count = 0u; |
952 for (size_t i = begin_position; i < end_position; ++i) { | 952 for (size_t i = begin_position; i < end_position; ++i) { |
953 if (query.Evaluate(*events.at(i))) | 953 if (query.Evaluate(*events.at(i))) |
954 ++count; | 954 ++count; |
955 } | 955 } |
956 return count; | 956 return count; |
957 } | 957 } |
958 | 958 |
959 } // namespace trace_analyzer | 959 } // namespace trace_analyzer |
960 | |
OLD | NEW |