OLD | NEW |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2014 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 import os | 5 import os |
6 from threading import Lock, Thread | 6 from threading import Lock, Thread |
7 | 7 |
8 import blame | 8 import blame |
9 from common import utils | 9 from common import utils |
10 import component_dictionary | 10 import component_dictionary |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 for i in range(len(match_by_priority)): | 449 for i in range(len(match_by_priority)): |
450 (priority, crashed_line_numbers, file_name, stack_frame_indices, | 450 (priority, crashed_line_numbers, file_name, stack_frame_indices, |
451 function_list) = match_by_priority[i] | 451 function_list) = match_by_priority[i] |
452 | 452 |
453 # If the file in the match is a line change, append a explanation. | 453 # If the file in the match is a line change, append a explanation. |
454 if priority == LINE_CHANGE_PRIORITY: | 454 if priority == LINE_CHANGE_PRIORITY: |
455 crashed_line_numbers = [crashed_line_number | 455 crashed_line_numbers = [crashed_line_number |
456 for lines in crashed_line_numbers | 456 for lines in crashed_line_numbers |
457 for crashed_line_number in lines] | 457 for crashed_line_number in lines] |
458 reason.append( | 458 reason.append( |
459 'Line %s of file %s which potentially caused the crash ' | 459 'Lines %s of file %s which potentially caused crash ' |
460 'according to the stacktrace, is changed in this cl' | 460 'are changed in this cl (%s).\n' % |
461 ' (From stack frame %s, function %s).' % | 461 (utils.JoinLineNumbers(crashed_line_numbers, accepted_gap=4), |
462 (crash_utils.PrettifyList(crashed_line_numbers), | |
463 file_name, | 462 file_name, |
464 crash_utils.PrettifyList(stack_frame_indices), | 463 crash_utils.PrettifyFrameInfo(stack_frame_indices, function_list))) |
465 crash_utils.PrettifyList(function_list))) | |
466 | 464 |
467 else: | 465 else: |
468 # Get all the files that are not line change. | 466 # Get all the files that are not line change. |
469 rest_of_the_files = match_by_priority[i:] | 467 rest_of_the_files = match_by_priority[i:] |
470 | 468 |
471 if len(rest_of_the_files) == 1: | 469 if len(rest_of_the_files) == 1: |
472 file_string = 'File %s is changed in this cl ' | 470 file_string = 'File %s is changed in this cl ' |
473 else: | 471 else: |
474 file_string = 'Files %s are changed in this cl ' | 472 file_string = 'Files %s are changed in this cl ' |
475 | 473 |
476 # Create a list of file names, and prettify the list. | 474 # Create a list of file names, and prettify the list. |
477 file_names = [ | 475 file_names = [ |
478 file_name for (_, _, file_name, _, _) in rest_of_the_files] | 476 file_name for (_, _, file_name, _, _) in rest_of_the_files] |
479 pretty_file_names = crash_utils.PrettifyList(file_names) | 477 pretty_file_names = crash_utils.PrettifyList(file_names) |
480 | 478 |
481 # Add the reason, break because we took care of the rest of the files. | 479 # Add the reason, break because we took care of the rest of the files. |
482 file_string += ('(From stack frames %s, functions %s)' % | 480 file_string += '(%s)' % crash_utils.PrettifyFrameInfo( |
483 (crash_utils.PrettifyList(stack_frame_indices), | 481 stack_frame_indices, function_list) |
484 crash_utils.PrettifyList(function_list))) | |
485 reason.append(file_string % pretty_file_names) | 482 reason.append(file_string % pretty_file_names) |
486 break | 483 break |
487 | 484 |
488 # Set the reason as string. | 485 # Set the reason as string. |
489 match.reason = '\n'.join(reason) | 486 match.reason = '\n'.join(reason) |
490 | 487 |
491 | 488 |
492 def CombineMatches(matches): | 489 def CombineMatches(matches): |
493 """Combine possible duplicates in matches. | 490 """Combine possible duplicates in matches. |
494 | 491 |
(...skipping 23 matching lines...) Expand all Loading... |
518 # Combine the reason if the current match is already in there. | 515 # Combine the reason if the current match is already in there. |
519 found_match.reason += match.reason | 516 found_match.reason += match.reason |
520 if match.min_distance < found_match.min_distance: | 517 if match.min_distance < found_match.min_distance: |
521 found_match.min_distance = match.min_distance | 518 found_match.min_distance = match.min_distance |
522 found_match.min_distance_info = match.min_distance_info | 519 found_match.min_distance_info = match.min_distance_info |
523 | 520 |
524 for stack_index, cl, match in combined_matches: | 521 for stack_index, cl, match in combined_matches: |
525 if match.min_distance_info: | 522 if match.min_distance_info: |
526 file_name, min_crashed_line, min_changed_line = match.min_distance_info | 523 file_name, min_crashed_line, min_changed_line = match.min_distance_info |
527 match.reason += \ | 524 match.reason += \ |
528 ('\nMininimum distance from crashed line to changed line: %d. ' | 525 ('Minimum distance from crashed line to changed line: %d. ' |
529 '(File: %s, Crashed on: %d, Changed: %d).' % | 526 '(File: %s, Crashed on: %d, Changed: %d).\n' % |
530 (match.min_distance, file_name, min_crashed_line, min_changed_line)) | 527 (match.min_distance, file_name, min_crashed_line, min_changed_line)) |
531 | 528 |
532 return combined_matches | 529 return combined_matches |
533 | 530 |
534 | 531 |
535 def FilterAndGenerateReasonForMatches(result): | 532 def FilterAndGenerateReasonForMatches(result): |
536 """A wrapper function. | 533 """A wrapper function. |
537 | 534 |
538 It generates reasons for the matches and returns string representation | 535 It generates reasons for the matches and returns string representation |
539 of filtered results. | 536 of filtered results. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 'the blame information.') | 672 'the blame information.') |
676 | 673 |
677 # When findit could not find any CL that changes file in stacktrace or if | 674 # When findit could not find any CL that changes file in stacktrace or if |
678 # if cannot get any blame information, return a message saying that no | 675 # if cannot get any blame information, return a message saying that no |
679 # results are available. | 676 # results are available. |
680 else: | 677 else: |
681 return_message = ('Findit could not find any suspected CLs.') | 678 return_message = ('Findit could not find any suspected CLs.') |
682 | 679 |
683 return (return_message, result) | 680 return (return_message, result) |
684 | 681 |
OLD | NEW |