This post summarises the progress in the second week of the community bonding period.
This week was a bit unproductive at the start but ended with a good step towards the aim of this project.
At the end of the last week, I finished reading about the documentation as suggested by the mentors. I also wrote about it in the previous post.
I started reading the source for htop till I get a reply for the previous message. I did not recieve a reply in my inbox till friday. But unknowingly I opened this week’s mailing list archive and I found three mails from Ryan which were somehow not delivered to my inbox.
Strange and sad!
I immediately mailed Ryan about this as he was also waiting for my reply to those mail. I explained him the situation and checked if were good to go further. After having this sorted out, we ended up deciding that we will be coding more in the upcoming weeks and we’ll start taking small steps towards writing a pcp version of pidstat command.
pidstat command is used to display statistics about the tasks that are running on the local machine. It shows the result in a tabular form with the rows being individual processes and the columns being the information type. It has columns like User ID, Process ID, % execution in user mode, % execution in system mode, % execution in guest mode, %CPU utilization, CPU core on which the task is being executed.
PCP version of pidstat would be a simple python script that will show similar information using PCP Api (pmapi). As a first step towards this I wrote a simple program in python to use pmapi to demonstrate a simple fetch operation of a metric.
import sys from pcp import pmapi from cpmapi import PM_TYPE_U32 from cpmapi import PM_ERR_VALUE class TotalRead(): """It prints the total read operations, summed for all disks""" def __init__(self): self.context = None self.opts = pmapi.pmOptions() self.opts.pmSetShortOptions("V?") self.opts.pmSetLongOptionHeader("Options") self.opts.pmSetLongOptionVersion() self.opts.pmSetLongOptionHelp() def execute(self): if self.context: metrics = ('disk.all.read',) pmids = self.context.pmLookupName(metrics) # print "PMID: ",pmids descs = self.context.pmLookupD escs(pmids) # print "Desc: ",descs result = self.context.pmFetch(pmids) if result.contents.numpmid != len(metrics): print "Got error here" raise pmapi.pmErr(PM_ERR_VALUE) atom = self.context.pmExtractValue( result.contents.get_valfmt(0), result.contents.get_vlist(0,0), descs.contents.type, PM_TYPE_U32) print "Total Disk Reads: ",atom.ul self.context.pmFreeResult(result) def connect(self): """Establish a PMAPI context Local using args """ self.context = pmapi.pmContext.fromOptions(self.opts,sys.argv) if self.context: print "Connection Established" if __name__ == "__main__": try: tr = TotalRead() tr.connect() tr.execute() except pmapi.pmErr as error: print "Error: ",error.message() except pmapi.pmUsageErr as usage: usage.message()
This code simply displays the total no of read operations on the disk. For this it fetches the data from disk.all.read metric using pmapi.
This repository is hosted here. I will be adding more to this soon.
The next step will to find the right pcp metrics for fetching the information required for the pidstat and then deciding the format for the values that will be evaluated from those metrics.
That’s all folks.