get_ut_mem_map.py 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import json
Z
zhangchunle 已提交
17
import sys
18 19 20 21 22 23 24 25 26 27


def get_ut_mem(rootPath):
    case_dic = {}
    for parent, dirs, files in os.walk(rootPath):
        for f in files:
            if f.endswith('$-gpu.log'):
                continue
            ut = f.replace('^', '').replace('$.log', '')
            case_dic[ut] = {}
Z
zhangchunle 已提交
28
            filename = '%s/%s' % (parent, f)
29 30 31 32 33 34 35 36 37
            fi = open(filename)
            lines = fi.readlines()
            mem_reserved1 = -1
            mem_nvidia1 = -1
            caseTime = -1
            for line in lines:
                if '[Memory Usage (Byte)] gpu' in line:
                    mem_reserved = round(
                        float(
38 39
                            line.split(' : Reserved = ')[1].split(
                                ', Allocated = ')[0]), 2)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
                    if mem_reserved > mem_reserved1:
                        mem_reserved1 = mem_reserved
                if 'MAX_GPU_MEMORY_USE=' in line:
                    mem_nvidia = round(
                        float(
                            line.split('MAX_GPU_MEMORY_USE=')[1].split('\\n')[0]
                            .strip()), 2)
                    if mem_nvidia > mem_nvidia1:
                        mem_nvidia1 = mem_nvidia
                if 'Total Test time (real)' in line:
                    caseTime = float(
                        line.split('Total Test time (real) =')[1].split('sec')[
                            0].strip())
            if mem_reserved1 != -1:
                case_dic[ut]['mem_reserved'] = mem_reserved1
            if mem_nvidia1 != -1:
                case_dic[ut]['mem_nvidia'] = mem_nvidia1
            if caseTime != -1:
                case_dic[ut]['time'] = caseTime

Z
zhangchunle 已提交
60
    ut_mem_map_file = "/pre_test/ut_mem_map.json"
61 62 63 64 65 66 67
    with open(ut_mem_map_file, "w") as f:
        json.dump(case_dic, f)


if __name__ == "__main__":
    rootPath = sys.argv[1]
    get_ut_mem(rootPath)