#!/usr/bin/env python3 """ 分析当前的日志片段 从终端选中的日志中分析性能 """ # 当前终端日志 log_content = """ [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 开始接收音频数据 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 启动流式STT识别 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT连接已打开 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT识别会话已启动 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT实时结果: 您 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT实时结果: 你好,你 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 音频录制结束 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 停止STT识别 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT实时结果: 你好,你好,今天 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT实时结果: 你好你好,今天天气怎么样? [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT连接已关闭 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT识别已停止 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] STT识别结果: 你好你好,今天天气怎么样? [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 步骤 2/3: LLM 生成回复 ========== LLM 开始 ========== 用户输入: 你好你好,今天天气怎么样? 调用 LLM: qwen-plus LLM 原始响应: Hello! It's great to hear from you! I can't check the actual weather, but if you tell me where you are, I can help describe what the weather might feel like or how to talk about it in English! ☀️🌧️⛅ For example, you could say: "It's sunny and warm today!" or "It's a bit cloudy but nice outside." Keep up the good work practicing English! [EMOTION:encouraging] 回复文本: Hello! It's great to hear from you! I can't check the actual weather, but if you tell me where you are, I can help describe what the weather might feel like or how to talk about it in English! ☀️🌧️⛅ For example, you could say: "It's sunny and warm today!" or "It's a bit cloudy but nice outside." Keep up the good work practicing English! 情感: encouraging ========== LLM 成功 ========== [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 步骤 3/3: TTS 文本转语音 ========== TTS 开始 ========== 要合成的文本: Hello! It's great to hear from you! I can't check the actual weather, but if you tell me where you are, I can help describe what the weather might feel like or how to talk about it in English! ☀️🌧️⛅ For example, you could say: "It's sunny and warm today!" or "It's a bit cloudy but nice outside." Keep up the good work practicing English! 情感: encouraging 使用音色: Cherry TTS模型: qwen3-tts-flash 调用 DashScope TTS API... TTS API 响应类型: output 类型: finish_reason: stop 从URL下载音频: http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/a0/20251015/d2033070/6ecda767-06ca-45fa-a312-fc391c32265c.wav?Expires=1760609218&OSSAccessKeyId=LTAI5tKPD3TMqf2Lna1fASuh&Signature=1%2FJLVFPvrvh2rqUTv2YZEQSeR6g%3D 音频下载成功,大小: 1105964 字节 将分为 346 个数据块发送 ========== TTS 成功 ========== [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 请求处理完成 [85c570c0-2346-44d2-8a6b-49aed1aa0b67] 资源已清理 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 开始接收音频数据 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 启动流式STT识别 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT连接已打开 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT识别会话已启动 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT实时结果: 你 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT实时结果: 你好,你 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT实时结果: 你好,你好。你今 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 音频录制结束 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 停止STT识别 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT实时结果: 你好,你好。你今年多 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT实时结果: 你好你好,你今年多大了? [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT连接已关闭 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT识别已停止 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] STT识别结果: 你好你好,你今年多大了? [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 步骤 2/3: LLM 生成回复 ========== LLM 开始 ========== 用户输入: 你好你好,你今年多大了? 调用 LLM: qwen-plus LLM 原始响应: 你好呀!我是AI助手,没有具体的年龄哦~但我很年轻有活力呢!✨ 很高兴认识你! [EMOTION:happy] 回复文本: 你好呀!我是AI助手,没有具体的年龄哦~但我很年轻有活力呢!✨ 很高兴认识你! 情感: happy ========== LLM 成功 ========== [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 步骤 3/3: TTS 文本转语音 ========== TTS 开始 ========== 要合成的文本: 你好呀!我是AI助手,没有具体的年龄哦~但我很年轻有活力呢!✨ 很高兴认识你! 情感: happy 使用音色: Cherry TTS模型: qwen3-tts-flash 调用 DashScope TTS API... TTS API 响应类型: output 类型: finish_reason: stop 从URL下载音频: http://dashscope-result-bj.oss-cn-beijing.aliyuncs.com/1d/aa/20251015/d2033070/e32c33e7-91df-4088-8fa2-e998898e82d2.wav?Expires=1760609249&OSSAccessKeyId=LTAI5tKPD3TMqf2Lna1fASuh&Signature=I%2F2MWpKZf5piIIg%2B%2BPoy%2BWSCmwM%3D 音频下载成功,大小: 345644 字节 将分为 109 个数据块发送 ========== TTS 成功 ========== [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 请求处理完成 [72ee5620-33f3-4d99-b56c-bbf17bf186d7] 资源已清理 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 开始接收音频数据 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 启动流式STT识别 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT连接已打开 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT识别会话已启动 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT实时结果: 你 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT实时结果: 您好,你好 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 音频录制结束 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 停止STT识别 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT实时结果: 您好,你好。今天星 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT实时结果: 您好,你好,今天星期几? [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT实时结果: 你好你好,今天星期几呀? [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT连接已关闭 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT识别已停止 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] STT识别结果: 你好你好,今天星期几呀? [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 步骤 2/3: LLM 生成回复 ========== LLM 开始 ========== 用户输入: 你好你好,今天星期几呀? 调用 LLM: qwen-plus LLM 原始响应: Hello! Today is Tuesday. How can I help you today? [EMOTION:happy] 回复文本: Hello! Today is Tuesday. How can I help you today? 情感: happy ========== LLM 成功 ========== [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 步骤 3/3: TTS 文本转语音 ========== TTS 开始 ========== 要合成的文本: Hello! Today is Tuesday. How can I help you today? 情感: happy 使用音色: Cherry TTS模型: qwen3-tts-flash 调用 DashScope TTS API... TTS API 响应类型: output 类型: finish_reason: stop 从URL下载音频: http://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/1d/8e/20251015/e9ee724c/038ed2c1-7065-4e17-9b3f-07f069128486.wav?Expires=1760609263&OSSAccessKeyId=LTAI5tKPD3TMqf2Lna1fASuh&Signature=Lil%2FuwlWgpGA3sKvxFqIrYO7nq4%3D 音频下载成功,大小: 222764 字节 将分为 70 个数据块发送 ========== TTS 成功 ========== [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 请求处理完成 [068fdf74-2c2d-48ee-8455-72d5c73cc9bf] 资源已清理 """ import re from datetime import datetime def analyze_manual_log(): """手动分析当前日志(无时间戳版本)""" print("\n" + "=" * 70) print("当前日志分析 (基于日志内容估算)".center(70)) print("=" * 70) # 按请求ID分组 requests = {} current_request = None lines = log_content.strip().split('\n') for line in lines: # 提取请求ID match = re.search(r'\[([a-f0-9\-]{36})\]', line) if match: request_id = match.group(1) if request_id not in requests: requests[request_id] = { 'id': request_id[:8], 'user_input': '', 'response': '', 'emotion': '', 'audio_size': 0, 'chunks': 0, 'lines': [] } current_request = requests[request_id] current_request['lines'].append(line) elif current_request and ('用户输入:' in line or '要合成的文本:' in line or '情感:' in line): current_request['lines'].append(line) # 提取关键信息 if '用户输入:' in line: current_request['user_input'] = line.split('用户输入:')[1].strip() elif '回复文本:' in line: current_request['response'] = line.split('回复文本:')[1].strip() elif re.match(r'^情感:', line): current_request['emotion'] = line.split('情感:')[1].strip() elif '音频下载成功,大小:' in line: size_match = re.search(r'(\d+)\s*字节', line) if size_match: current_request['audio_size'] = int(size_match.group(1)) elif '将分为' in line and '个数据块发送' in line: chunks_match = re.search(r'(\d+)\s*个数据块', line) if chunks_match: current_request['chunks'] = int(chunks_match.group(1)) # 打印每个请求的分析 print(f"\n发现 {len(requests)} 个完整请求\n") total_audio_size = 0 total_chunks = 0 for i, req in enumerate(requests.values(), 1): print(f"\n{'=' * 70}") print(f"请求 #{i} [{req['id']}...]") print(f"{'=' * 70}") print(f"📝 用户输入: {req['user_input'][:60]}..." if len(req['user_input']) > 60 else f"📝 用户输入: {req['user_input']}") print(f"💬 AI回复: {req['response'][:60]}..." if len(req['response']) > 60 else f"💬 AI回复: {req['response']}") print(f"😊 情感: {req['emotion']}") print(f"🎵 音频大小: {req['audio_size']:,} 字节 ({req['audio_size']/1024:.1f} KB)") print(f"📦 数据块数: {req['chunks']}") total_audio_size += req['audio_size'] total_chunks += req['chunks'] # 流程分析 print(f"\n流程分析:") print(f" ✓ STT: 流式识别成功") print(f" ✓ LLM: 生成回复成功") print(f" ✓ TTS: 合成音频成功") # 汇总统计 print(f"\n{'=' * 70}") print("汇总统计".center(70)) print(f"{'=' * 70}") print(f"总请求数: {len(requests)}") print(f"总音频大小: {total_audio_size:,} 字节 ({total_audio_size/1024:.1f} KB)") print(f"总数据块数: {total_chunks}") print(f"平均音频大小: {total_audio_size/len(requests):,.0f} 字节 ({total_audio_size/len(requests)/1024:.1f} KB)") print(f"平均数据块数: {total_chunks/len(requests):.0f}") print(f"\n{'=' * 70}") print("⚠️ 注意事项".center(70)) print(f"{'=' * 70}") print("当前日志没有时间戳,无法统计各阶段精确耗时。") print("请重新运行测试,使用更新后的代码,将获得详细的性能统计。") print(f"\n新代码已添加以下时间统计:") print(" - STT 识别耗时") print(" - LLM 生成耗时") print(" - TTS 合成耗时") print(" - 总体处理耗时") print(f"\n重新测试后,运行以下命令分析:") print(" python analyze_performance.py backend.log") print(f"{'=' * 70}\n") if __name__ == "__main__": analyze_manual_log()