OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 static_cast<const base::DictionaryValue*>(event_value); | 34 static_cast<const base::DictionaryValue*>(event_value); |
35 | 35 |
36 std::string phase_str; | 36 std::string phase_str; |
37 base::DictionaryValue* args = NULL; | 37 base::DictionaryValue* args = NULL; |
38 | 38 |
39 if (!dictionary->GetString("ph", &phase_str)) { | 39 if (!dictionary->GetString("ph", &phase_str)) { |
40 LOG(ERROR) << "ph is missing from TraceEvent JSON"; | 40 LOG(ERROR) << "ph is missing from TraceEvent JSON"; |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 phase = base::debug::TraceEvent::GetPhase(phase_str.c_str()); | 44 phase = *phase_str.data(); |
45 | 45 |
46 bool require_origin = (phase != TRACE_EVENT_PHASE_METADATA); | 46 bool require_origin = (phase != TRACE_EVENT_PHASE_METADATA); |
47 bool require_id = (phase == TRACE_EVENT_PHASE_START || | 47 bool require_id = (phase == TRACE_EVENT_PHASE_START || |
48 phase == TRACE_EVENT_PHASE_FINISH); | 48 phase == TRACE_EVENT_PHASE_FINISH); |
49 | 49 |
50 if (require_origin && !dictionary->GetInteger("pid", &thread.process_id)) { | 50 if (require_origin && !dictionary->GetInteger("pid", &thread.process_id)) { |
51 LOG(ERROR) << "pid is missing from TraceEvent JSON"; | 51 LOG(ERROR) << "pid is missing from TraceEvent JSON"; |
52 return false; | 52 return false; |
53 } | 53 } |
54 if (require_origin && !dictionary->GetInteger("tid", &thread.thread_id)) { | 54 if (require_origin && !dictionary->GetInteger("tid", &thread.thread_id)) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 } | 222 } |
223 | 223 |
224 Query Query::Uint(uint32 num) { | 224 Query Query::Uint(uint32 num) { |
225 return Query(static_cast<double>(num)); | 225 return Query(static_cast<double>(num)); |
226 } | 226 } |
227 | 227 |
228 Query Query::Bool(bool boolean) { | 228 Query Query::Bool(bool boolean) { |
229 return Query(boolean ? 1.0 : 0.0); | 229 return Query(boolean ? 1.0 : 0.0); |
230 } | 230 } |
231 | 231 |
232 Query Query::Phase(base::debug::TraceEventPhase phase) { | 232 Query Query::Phase(char phase) { |
233 return Query(static_cast<double>(phase)); | 233 return Query(static_cast<double>(phase)); |
234 } | 234 } |
235 | 235 |
236 Query Query::Pattern(const std::string& pattern) { | 236 Query Query::Pattern(const std::string& pattern) { |
237 Query query(pattern); | 237 Query query(pattern); |
238 query.is_pattern_ = true; | 238 query.is_pattern_ = true; |
239 return query; | 239 return query; |
240 } | 240 } |
241 | 241 |
242 bool Query::Evaluate(const TraceEvent& event) const { | 242 bool Query::Evaluate(const TraceEvent& event) const { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 case OP_NEGATE: | 386 case OP_NEGATE: |
387 *num = -lhs; | 387 *num = -lhs; |
388 return true; | 388 return true; |
389 default: | 389 default: |
390 NOTREACHED(); | 390 NOTREACHED(); |
391 return false; | 391 return false; |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 bool Query::GetAsDouble(const TraceEvent& event, double* num) const { | 395 bool Query::GetAsDouble(const TraceEvent& event, double* num) const { |
396 base::debug::TraceValue value; | |
397 switch (type_) { | 396 switch (type_) { |
398 case QUERY_ARITHMETIC_OPERATOR: | 397 case QUERY_ARITHMETIC_OPERATOR: |
399 return EvaluateArithmeticOperator(event, num); | 398 return EvaluateArithmeticOperator(event, num); |
400 case QUERY_EVENT_MEMBER: | 399 case QUERY_EVENT_MEMBER: |
401 value = GetMemberValue(event); | 400 return GetMemberValueAsDouble(event, num); |
402 if (value.type() == base::debug::TraceValue::TRACE_TYPE_DOUBLE) { | |
403 *num = value.as_double(); | |
404 return true; | |
405 } | |
406 return false; | |
407 case QUERY_NUMBER: | 401 case QUERY_NUMBER: |
408 *num = number_; | 402 *num = number_; |
409 return true; | 403 return true; |
410 default: | 404 default: |
411 return false; | 405 return false; |
412 } | 406 } |
413 } | 407 } |
414 | 408 |
415 bool Query::GetAsString(const TraceEvent& event, std::string* str) const { | 409 bool Query::GetAsString(const TraceEvent& event, std::string* str) const { |
416 base::debug::TraceValue value; | |
417 switch (type_) { | 410 switch (type_) { |
418 case QUERY_EVENT_MEMBER: | 411 case QUERY_EVENT_MEMBER: |
419 value = GetMemberValue(event); | 412 return GetMemberValueAsString(event, str); |
420 if (value.is_string()) { | |
421 *str = value.as_string(); | |
422 return true; | |
423 } | |
424 return false; | |
425 case QUERY_STRING: | 413 case QUERY_STRING: |
426 *str = string_; | 414 *str = string_; |
427 return true; | 415 return true; |
428 default: | 416 default: |
429 return false; | 417 return false; |
430 } | 418 } |
431 } | 419 } |
432 | 420 |
433 base::debug::TraceValue Query::GetMemberValue(const TraceEvent& event) const { | 421 bool Query::GetMemberValueAsDouble(const TraceEvent& event, |
422 double* num) const { | |
434 DCHECK(type_ == QUERY_EVENT_MEMBER); | 423 DCHECK(type_ == QUERY_EVENT_MEMBER); |
435 | 424 |
436 // This could be a request for a member of |event| or a member of |event|'s | 425 // This could be a request for a member of |event| or a member of |event|'s |
437 // associated event. Store the target event in the_event: | 426 // associated event. Store the target event in the_event: |
438 const TraceEvent* the_event = (member_ < OTHER_PID) ? | 427 const TraceEvent* the_event = (member_ < OTHER_PID) ? |
439 &event : event.other_event; | 428 &event : event.other_event; |
440 | 429 |
441 // Request for member of associated event, but there is no associated event. | 430 // Request for member of associated event, but there is no associated event. |
442 if (!the_event) | 431 if (!the_event) |
443 return base::debug::TraceValue(); | 432 return false; |
444 | 433 |
445 switch (member_) { | 434 switch (member_) { |
446 case EVENT_PID: | 435 case EVENT_PID: |
447 case OTHER_PID: | 436 case OTHER_PID: |
448 return static_cast<double>(the_event->thread.process_id); | 437 *num = static_cast<double>(the_event->thread.process_id); |
438 return true; | |
449 case EVENT_TID: | 439 case EVENT_TID: |
450 case OTHER_TID: | 440 case OTHER_TID: |
451 return static_cast<double>(the_event->thread.thread_id); | 441 *num = static_cast<double>(the_event->thread.thread_id); |
442 return true; | |
452 case EVENT_TIME: | 443 case EVENT_TIME: |
453 case OTHER_TIME: | 444 case OTHER_TIME: |
454 return the_event->timestamp; | 445 *num = the_event->timestamp; |
446 return true; | |
455 case EVENT_DURATION: | 447 case EVENT_DURATION: |
456 { | 448 { |
jar (doing other things)
2012/01/12 00:15:36
nit: open curly should come at the end of line 447
jbates
2012/01/12 00:52:20
Done.
| |
457 if (the_event->has_other_event()) | 449 if (the_event->has_other_event()) { |
458 return the_event->GetAbsTimeToOtherEvent(); | 450 *num = the_event->GetAbsTimeToOtherEvent(); |
459 else | 451 return true; |
460 return base::debug::TraceValue(); | 452 } |
453 return false; | |
461 } | 454 } |
462 case EVENT_PHASE: | 455 case EVENT_PHASE: |
463 case OTHER_PHASE: | 456 case OTHER_PHASE: |
464 return static_cast<double>(the_event->phase); | 457 *num = static_cast<double>(the_event->phase); |
465 case EVENT_CATEGORY: | 458 return true; |
466 case OTHER_CATEGORY: | |
467 return the_event->category; | |
468 case EVENT_NAME: | |
469 case OTHER_NAME: | |
470 return the_event->name; | |
471 case EVENT_ID: | |
472 case OTHER_ID: | |
473 return the_event->id; | |
474 case EVENT_HAS_STRING_ARG: | 459 case EVENT_HAS_STRING_ARG: |
475 case OTHER_HAS_STRING_ARG: | 460 case OTHER_HAS_STRING_ARG: |
476 return (the_event->HasStringArg(string_) ? 1.0 : 0.0); | 461 *num = (the_event->HasStringArg(string_) ? 1.0 : 0.0); |
462 return true; | |
477 case EVENT_HAS_NUMBER_ARG: | 463 case EVENT_HAS_NUMBER_ARG: |
478 case OTHER_HAS_NUMBER_ARG: | 464 case OTHER_HAS_NUMBER_ARG: |
479 return (the_event->HasNumberArg(string_) ? 1.0 : 0.0); | 465 *num = (the_event->HasNumberArg(string_) ? 1.0 : 0.0); |
466 return true; | |
480 case EVENT_ARG: | 467 case EVENT_ARG: |
481 case OTHER_ARG: | 468 case OTHER_ARG: |
482 { | 469 { |
483 // Search for the argument name and return its value if found. | 470 // Search for the argument name and return its value if found. |
484 | |
485 std::map<std::string, std::string>::const_iterator str_i = | |
486 the_event->arg_strings.find(string_); | |
487 if (str_i != the_event->arg_strings.end()) | |
488 return str_i->second; | |
489 | |
490 std::map<std::string, double>::const_iterator num_i = | 471 std::map<std::string, double>::const_iterator num_i = |
491 the_event->arg_numbers.find(string_); | 472 the_event->arg_numbers.find(string_); |
492 if (num_i != the_event->arg_numbers.end()) | 473 if (num_i != the_event->arg_numbers.end()) { |
493 return num_i->second; | 474 *num = num_i->second; |
494 | 475 return true; |
495 return base::debug::TraceValue(); | 476 } |
477 return false; | |
496 } | 478 } |
497 case EVENT_HAS_OTHER: | 479 case EVENT_HAS_OTHER: |
498 { | 480 { |
499 // return 1.0 (true) if the other event exists | 481 // return 1.0 (true) if the other event exists |
500 double result = event.other_event ? 1.0 : 0.0; | 482 *num = event.other_event ? 1.0 : 0.0; |
501 return result; | 483 return true; |
502 } | 484 } |
503 default: | 485 default: |
504 NOTREACHED(); | 486 return false; |
505 return base::debug::TraceValue(); | |
506 } | 487 } |
507 } | 488 } |
508 | 489 |
490 bool Query::GetMemberValueAsString(const TraceEvent& event, | |
491 std::string* str) const { | |
492 DCHECK(type_ == QUERY_EVENT_MEMBER); | |
493 | |
494 // This could be a request for a member of |event| or a member of |event|'s | |
495 // associated event. Store the target event in the_event: | |
496 const TraceEvent* the_event = (member_ < OTHER_PID) ? | |
497 &event : event.other_event; | |
498 | |
499 // Request for member of associated event, but there is no associated event. | |
500 if (!the_event) | |
501 return false; | |
502 | |
503 switch (member_) { | |
504 case EVENT_CATEGORY: | |
505 case OTHER_CATEGORY: | |
506 *str = the_event->category; | |
507 return true; | |
508 case EVENT_NAME: | |
509 case OTHER_NAME: | |
510 *str = the_event->name; | |
511 return true; | |
512 case EVENT_ID: | |
513 case OTHER_ID: | |
514 *str = the_event->id; | |
515 return true; | |
516 case EVENT_ARG: | |
517 case OTHER_ARG: | |
518 { | |
jar (doing other things)
2012/01/12 00:15:36
nit: indent on curlies throughout this file in cas
jbates
2012/01/12 00:52:20
Done.
| |
519 // Search for the argument name and return its value if found. | |
520 std::map<std::string, std::string>::const_iterator str_i = | |
521 the_event->arg_strings.find(string_); | |
522 if (str_i != the_event->arg_strings.end()) { | |
523 *str = str_i->second; | |
524 return true; | |
525 } | |
526 return false; | |
527 } | |
528 default: | |
529 return false; | |
530 } | |
531 } | |
532 | |
509 Query::Query(const std::string& str) | 533 Query::Query(const std::string& str) |
510 : type_(QUERY_STRING), | 534 : type_(QUERY_STRING), |
511 operator_(OP_INVALID), | 535 operator_(OP_INVALID), |
512 member_(EVENT_INVALID), | 536 member_(EVENT_INVALID), |
513 number_(0), | 537 number_(0), |
514 string_(str), | 538 string_(str), |
515 is_pattern_(false) { | 539 is_pattern_(false) { |
516 } | 540 } |
517 | 541 |
518 Query::Query(double num) | 542 Query::Query(double num) |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 size_t count = 0u; | 928 size_t count = 0u; |
905 for (size_t i = begin_position; i < end_position; ++i) { | 929 for (size_t i = begin_position; i < end_position; ++i) { |
906 if (query.Evaluate(*events.at(i))) | 930 if (query.Evaluate(*events.at(i))) |
907 ++count; | 931 ++count; |
908 } | 932 } |
909 return count; | 933 return count; |
910 } | 934 } |
911 | 935 |
912 } // namespace trace_analyzer | 936 } // namespace trace_analyzer |
913 | 937 |
OLD | NEW |