|
| 1 | +# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import argparse |
| 16 | +import re |
| 17 | +from collections import defaultdict |
| 18 | + |
| 19 | +gpu_time_categories = { |
| 20 | + "within_1%": 0, |
| 21 | + "increase_1_to_5%": 0, |
| 22 | + "increase_above_5_to_10%": 0, |
| 23 | + "increase_above_10%": 0, |
| 24 | + "decrease_1_to_5%": 0, |
| 25 | + "decrease_above_5%": 0, |
| 26 | +} |
| 27 | + |
| 28 | +total_time_categories = { |
| 29 | + "within_1%": 0, |
| 30 | + "increase_1_to_5%": 0, |
| 31 | + "increase_above_5_to_10%": 0, |
| 32 | + "increase_above_10%": 0, |
| 33 | + "decrease_1_to_5%": 0, |
| 34 | + "decrease_above_5%": 0, |
| 35 | +} |
| 36 | + |
| 37 | +parser = argparse.ArgumentParser( |
| 38 | + description="Analyze time changes in log files" |
| 39 | +) |
| 40 | +parser.add_argument('file_name', type=str, help='The name of the log file') |
| 41 | +args = parser.parse_args() |
| 42 | + |
| 43 | +gpu_time_pattern = re.compile(r"GPU time change: ([\d.-]*)") |
| 44 | +total_time_pattern = re.compile(r"Total time change: ([\d.-]+)%") |
| 45 | +error_pattern = re.compile(r'Check speed result with case "(.*?)"') |
| 46 | + |
| 47 | +gpu_time_lines = 0 |
| 48 | +error_cases = defaultdict(int) |
| 49 | + |
| 50 | +with open(args.file_name, 'r') as file: |
| 51 | + for line in file: |
| 52 | + if "GPU time change" in line: |
| 53 | + gpu_time_lines += 1 |
| 54 | + gpu_time_match = gpu_time_pattern.search(line) |
| 55 | + if gpu_time_match: |
| 56 | + gpu_time_change_str = gpu_time_match.group(1) |
| 57 | + gpu_time_change = ( |
| 58 | + float(gpu_time_change_str) if gpu_time_change_str else 0.0 |
| 59 | + ) |
| 60 | + |
| 61 | + if -1 < gpu_time_change < 1: |
| 62 | + gpu_time_categories["within_1%"] += 1 |
| 63 | + elif 1 <= gpu_time_change < 5: |
| 64 | + gpu_time_categories["increase_1_to_5%"] += 1 |
| 65 | + elif 5 <= gpu_time_change < 10: |
| 66 | + gpu_time_categories["increase_above_5_to_10%"] += 1 |
| 67 | + elif gpu_time_change >= 10: |
| 68 | + gpu_time_categories["increase_above_10%"] += 1 |
| 69 | + elif -5 < gpu_time_change <= -1: |
| 70 | + gpu_time_categories["decrease_1_to_5%"] += 1 |
| 71 | + elif gpu_time_change <= -5: |
| 72 | + gpu_time_categories["decrease_above_5%"] += 1 |
| 73 | + |
| 74 | + elif "Total time change" in line: |
| 75 | + total_time_match = total_time_pattern.search(line) |
| 76 | + if total_time_match: |
| 77 | + total_time_change = float(total_time_match.group(1)) |
| 78 | + |
| 79 | + if -1 < total_time_change < 1: |
| 80 | + total_time_categories["within_1%"] += 1 |
| 81 | + elif 1 <= total_time_change < 5: |
| 82 | + total_time_categories["increase_1_to_5%"] += 1 |
| 83 | + elif 5 <= total_time_change < 10: |
| 84 | + total_time_categories["increase_above_5_to_10%"] += 1 |
| 85 | + elif total_time_change >= 10: |
| 86 | + total_time_categories["increase_above_10%"] += 1 |
| 87 | + elif -5 < total_time_change <= -1: |
| 88 | + total_time_categories["decrease_1_to_5%"] += 1 |
| 89 | + elif total_time_change <= -5: |
| 90 | + total_time_categories["decrease_above_5%"] += 1 |
| 91 | + |
| 92 | + elif error_pattern.search(line): |
| 93 | + error_match = error_pattern.search(line) |
| 94 | + if error_match: |
| 95 | + case_name = error_match.group(1) |
| 96 | + error_cases[case_name] += 1 |
| 97 | + |
| 98 | + |
| 99 | +def print_categories(categories, title): |
| 100 | + total = sum(categories.values()) |
| 101 | + print(f"\n{title} Categories:") |
| 102 | + for category, count in categories.items(): |
| 103 | + percentage = (count / total * 100) if total > 0 else 0 |
| 104 | + print(f"{category}: {count} ({percentage:.2f}%)") |
| 105 | + |
| 106 | + |
| 107 | +print_categories(gpu_time_categories, "GPU Time Change") |
| 108 | +print_categories(total_time_categories, "Total Time Change") |
| 109 | + |
| 110 | +total_errors = sum(error_cases.values()) |
| 111 | +error_percentage = ( |
| 112 | + (total_errors / gpu_time_lines * 100) if gpu_time_lines > 0 else 0 |
| 113 | +) |
| 114 | +unique_errors = len(error_cases) |
| 115 | + |
| 116 | +print(f"\nError Cases Total: {total_errors}") |
| 117 | +print(f"Error Lines Percentage: {error_percentage:.2f}%") |
| 118 | +print(f"Unique Error OP: {unique_errors}\n") |
| 119 | + |
| 120 | +for case, count in error_cases.items(): |
| 121 | + print(f"OP '{case}': {count} occurrences") |
0 commit comments