溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python如何提取log文件內(nèi)容并畫出圖表

發(fā)布時間:2021-08-12 15:04:36 來源:億速云 閱讀:283 作者:小新 欄目:開發(fā)技術

這篇文章將為大家詳細講解有關python如何提取log文件內(nèi)容并畫出圖表,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

之前在excel里面分析log數(shù)據(jù),簡直日了*了。 現(xiàn)在用python在處理日志數(shù)據(jù).

主要涉及 matplotlib,open和循環(huán)的使用。

日志內(nèi)容大致如下

2016-10-21 21:07:59,787 [7 MainWindowForm]INFO: update time 136.6314
2016-10-21 21:07:59,908 [7 KinectServer]INFO: lClientSockets[0] elapsed time 16.
2016-10-21 21:07:59,918 [7 KinectServer]INFO: lClientSockets[1] elapsed time 107.
2016-10-21 21:07:59,929 [7 MainWindowForm]INFO: update time 135.1311
2016-10-21 21:08:00,039 [7 KinectServer]INFO: lClientSockets[0] elapsed time 14.
2016-10-21 21:08:00,045 [7 KinectServer]INFO: lClientSockets[1] elapsed time 103.
2016-10-21 21:08:00,053 [7 MainWindowForm]INFO: update time 118.1132

python處理代碼

import matplotlib.pyplot as plt

input = open('serverlog.txt', 'r')

rangeUpdateTime = [0.0]

for line in input:
  line = line.split()
  if 'update' in line:
    rangeUpdateTime.append(float(line[-1]))

plt.figure('frame time')
plt.subplot(211)
plt.plot(rangeUpdateTime, '.r',)
plt.grid(True)
plt.subplot(212)
plt.plot(rangeUpdateTime)
plt.grid(True)
plt.show()

結果

python如何提取log文件內(nèi)容并畫出圖表

關于“python如何提取log文件內(nèi)容并畫出圖表”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI