用python进行图形化的log分析

log分析使用python等脚本语言更方便可定制,使用正则提取需要的数据,使用matplotlib绘制出图形,以进行分析。


下图是示例,详细例子下载:点击打开链接 ,内里包含:pythonv3.3.2的安装包,matplotlib与其依赖包。除此之外,还有一个log文件,log.py用于示例如何使用python进行图形化的log分析。

代码:

import re
import matplotlib.pyplot as plt

print("analyse video input pts!...")

#[16:11:08:535] [INFO] CRingBuffer::WriteFile() begin m_llCurWriteMemPos=1536000  m_llCurWriteDsikPos=1331200
#[16:11:08:535] [INFO] CRingBuffer::WriteFile() begin m_RbFile.llCurWritePos=87654400  m_RbFile.llCurReadPos=0
regex  = re.compile("m_RbFile.llCurWritePos=(\d+)")
regex2 = re.compile("m_RbFile.llCurReadPos=(\d+)")

WritePos_index = []
WritePos   = []
ReadPos_index = []
ReadPos    = []

file  = open("RingBuffer_Source.txt", "r")
log = file.read()
file.close()

#write pos
m = regex.findall(log)
if m:
    print("write pos match success")
    i = 0
    j = 0
    for pos in m:
        if(int(pos) < 10000000000) :
            WritePos_index.append(i)
            WritePos.append(int(pos)/1000)
            i = i+1
else:
    print("not match")
    
#read pos
m = regex2.findall(log)
if m:
    print("read pos match success")
    i = 0
    j = 0
    for pos in m:
        if(int(pos) < 10000000000) :
            ReadPos_index.append(i)
            ReadPos.append(int(pos)/1000)
            i = i+1
else:
    print("not match")

print("begin to plot")

fig = plt.figure()
video_pts_plot = fig.add_subplot(211)
video_pts_plot.plot(WritePos_index, WritePos, 'r')
video_pts_plot.plot(ReadPos_index, ReadPos, 'b')
plt.show()


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值