码迷,mamicode.com
首页 > 其他好文 > 详细

内存采集

时间:2017-05-22 00:11:17      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:xls   import   sed   open   enum   sheet   class   port   cin   

__author__ = Administrator
import xlsxwriter  as writer
import xlrd as read
import linecache
import re
CPUFile=jcc.txt
CPUfiles=[jcc.txt,jcc2.txt]

def getKeyline(CPUFile):
    Keyline=0
    fin=open(CPUFile,r)
    KeyLine=[]
    for num,line in enumerate(fin):
        if "sh 30" in line:
           Keyline=str(num)
           #print "Keyline="+Keyline
        if "pool used size" in line and Keyline>0:
            KeyLine.append(num+1)
        if "T_TREE" in line and Keyline>0:
            KeyLine.append(num+1)
        if "B_TREE" in line and Keyline>0:
            KeyLine.append(num+1)
        if "U_WMCINFO" in line and Keyline>0:
            KeyLine.append(num)
    return KeyLine

def Getkeyword(Filenum,Theline):
    workbook = writer.Workbook(jcc2.xls)
    worksheet = workbook.add_worksheet(Cpuinfo)
    #p=re.compile(r"(\:)\d+B|( )\d+ ")
    print Theline,

    if "T_TREE" in Theline:
        p=re.compile(r"(\:)\d+B")
        for m in p.finditer(Theline):
            print m.group()
            print Filenum
            worksheet.write(Filenum, 2, m.group())

    if "B_TREE" in Theline:
        p=re.compile(r"(\:)\d+B")
        for m in p.finditer(Theline):
            worksheet.write(Filenum, 3, m.group())

    if "pool used size" in Theline:
        p=re.compile(r"( )\d+ ")
        for m in p.finditer(Theline):
            worksheet.write(Filenum, 1, m.group())

    

    workbook.close()


def main():
    for j in CPUfiles:
        x=1
        for i in getKeyline(j):
            Theline=linecache.getline(j,i)
            Getkeyword(x,Theline)
        x=x+1 #print Theline

if __name__=="__main__":
    main()

 

内存采集

标签:xls   import   sed   open   enum   sheet   class   port   cin   

原文地址:http://www.cnblogs.com/stonerainjc/p/6886598.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!