通过python脚本获取TASKING编译的MAP文件中memory的使用情况

import csv
import pandas as pd
# 1 读取文件中特定的数据
def read_specific_data(file_path, output_file_path, line_number=None,line_number_range=None, pattern=None):
    """
    :param file_path: 文件路径
    :param line_number: 读取特定的行号,如果为None,读取所有行
    :param pattern: 读取匹配特定模式的行,如果为None,不使用模式匹配
    :return: 返回特定的数据
    """
    data = []
    with open(file_path, 'r') as file:
        if line_number_range is not None:
            with open(output_file_path, 'w') as outputfile:
                outputfile.write('')
            for number, line in enumerate(file, 1):
                if number >= line_number:
                    print(line)
                    with open(output_file_path, 'a') as outputfile:
                        outputfile.write(line)
                    if number-line_number + 1 == line_number_range:
                        break
        elif line_number is not None:
            # 读取特定行号
            for number, line in enumerate(file, 1):
                if number == line_number:
                    break 
            return line
        elif pattern is not None:
            # 读取匹配特定字符串的行号
            for number, line in enumerate(file, 1):
                if pattern in line:
                    data.append(line)
                    print(f"行号:{number}")
                    return number
        else:
            # 读取所有行
            data = file.readlines()
            return data
    
 
# 使用例子
  # 文件路径

# 1 使用通配符匹配文件路径
import glob
file_path = '**/*.map'  # 匹配../Debug/下所有以.map结尾的文件
outputfile_path = '**/*output.txt'
csv_outputfile_path = '**/*output.csv'

mapFiles = glob.glob(file_path)  
outputFiles = glob.glob(outputfile_path) 
csv_outputFiles = glob.glob(csv_outputfile_path) 
for mapFile in mapFiles:
    print(mapFile)
    for outputFile in outputFiles:
        print(outputFile)    
    for csv_outputFile in csv_outputFiles:
        print(csv_outputFile)

    # 读取包含'search_pattern'的行
    pattern = '| Memory        | Code     | Data     | Reserved | Free     | Total    |'  # 读取包含'search_pattern'的行
    pattern_line_Number1 = read_specific_data(mapFile, outputFile, pattern=pattern)
    # 读取第line_number行
    read_specific_data(mapFile, outputFile, line_number=pattern_line_Number1)
    
    pattern = '* Space usage in bytes'
    pattern_line_Number2 = read_specific_data(mapFile, outputFile, pattern=pattern)
    read_specific_data(mapFile, outputFile, line_number=pattern_line_Number2)
    
    line_range = pattern_line_Number2 - pattern_line_Number1
    coment = read_specific_data(mapFile, outputFile, line_number=pattern_line_Number1, line_number_range=line_range)
     
    # 打开文件,并清空内容
    with open(csv_outputFile, 'w') as file:
        file.write('')
    
    # 文件现在已经被清空

    # 读取文件,并用|作为分隔符
    df = pd.read_csv(outputFile, sep='|')
    
    # 输出DataFrame
    print(df)
    
    # 如果需要将DataFrame保存到CSV文件中
    df.to_csv(csv_outputFile, index=False)


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
tasking 编译warning 是指在使用tasking编译器进行编译时,出现的警告信息。警告信息是编译器根据代码的语法和语义规范来判断可能出现的问题或潜在的错误,并给出相应的建议或提示。 我们可以从以下几个方面来看待tasking 编译warning: 1. 识别警告类型:在编译过程tasking编译器会生成多种类型的警告信息,如未使用的变量、潜在的类型不匹配、可能造成的逻辑错误等。我们可以通过查看警告信息所在的行数和警告类型来确认警告的具体问题。 2. 了解警告的原因:在任务编译,警告可能是由代码的一些不规范或潜在的问题引起的。我们可以仔细阅读警告信息,并与代码进行比对,找到可能存在的问题所在。 3. 判断警告的严重程度:警告信息分为不同的级别,如提示、建议和警告。提示级别的警告通常是一些警示信息,可以引起注意,但不一定会影响程序的正确性。建议级别的警告提供了一些建议的改进方法,但不一定非要立即处理。警告级别的警告则可能会导致程序的逻辑错误或运行异常,需要及时处理。 4. 解决警告问题:根据具体的警告信息,我们可以采取相应的解决措施。常见的方法包括修改代码逻辑、调整变量类型、删除未使用的变量或标识等。在修改代码时,我们应该注意保持程序的正确性,确保对警告的处理不会引入新的问题。 总之,我们需要重视tasking 编译warning,仔细阅读警告信息,了解问题所在,并尽快解决警告引起的潜在问题,确保程序的正确性和稳定性。同时,我们也可以通过规范编码习惯和使用合适的编译选项来减少警告的产生。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值