Linux::Taskstats::Read - Read Linux taskstats structures
use Linux::Taskstats::Read; my $ts = new Linux::Taskstats::Read( -file => '/some/taskstats.log' -ver => 3 ); while( my $rec = $ts->read ) { printf("Comm: %s (uid: %d)\n", $rec->{ac_comm}, $rec->{ac_uid}); } $ts->close;
The Linux 2.6.19 kernel introduced real-time task and process statistical accounting routines. These stats are requested and gathered via a netlink interface. This module does not interface with netlink, but it can read a raw binary dump of a taskstats struct (either from memory or from disk).
Creates a new taskstats record reader object. Parameters:
Specifies a file to open. This file should be a binary dump of taskstats objects (e.g. such as produced by getdelays).
Specifies the taskstats struct version. This is a required parameter. Try '3' if you don't know what version to use. Otherwise, look near the top of linux/taskstats.h to see your kernel's current version.
Reads a taskstats record from the file specified in either the constructor (new()) or open().
my $rec = $ts->read;
Returns a raw (packed) taststats structure.
When you're done reading what you need from the taststats dump, kindly close the file.
Example:
$ts->close();
If you don't know the filename at the time of object construction, or you've closed the object's filehandle (via close()), you can (re-)open a new file with this method.
$ts->open('/path/to/some/file.log');
Returns a list containing all of the fields of the taskstats structure in the order they appear in taskstats.h.
my @fields = $ts->fields;
Returns the record size in bytes for the current taskstats version.
my $size = $ts->size;
Returns the template for unpack() for this taskstats version.
my $rec = $ts->read_raw; @data = unpack($ts->template, $rec);
Returns the taskstats version this object is currently set to parse.
print $ts->version . "\n";
A taskstats struct, as returned by read() has the following fields you can examine (this is the version 3 format):
version ac_exitcode ac_flag ac_nice cpu_count cpu_delay_total blkio_count blkio_delay_total swapin_count swapin_delay_total cpu_run_real_total cpu_run_virtual_total ac_comm ac_sched ac_pad ac_uid ac_gid ac_pid ac_ppid ac_btime ac_etime ac_utime ac_stime ac_minflt ac_majflt coremem virtmem hiwater_rss hiwater_vm read_char write_char read_syscalls write_syscalls read_bytes write_bytes cancelled_write_bytes
More information on what is stored in these fields may be found in the documentation supplied by your kernel. These fields are subject to change depending on the taskstats version used. They are supplied here only as a courtesy and reference. Future versions may or may not be included in subsequent releases of this module.
Q. I have no idea what this modules is for! What is it for?
A. Linux::Taskstats::Read can read taskstats dumps. If you don't know what taskstats is, you probably don't need this module (but you can find out more by reading the 'SEE ALSO' references below).
Q. I get "Invalid type 'Q' in unpack at .../Linnux/Taskstats/Read.pm" errors.
A. You're not on a 64-bit box (or your kernel has not been built with 64-bit support). This module has to be used on a box that can build and run taskstats (but may not necessarily be running it at the moment).
Q. How can I make taskstats dumps that this module can read?
A. See the getdelays program in the 'SEE ALSO' section below for an example program.
Q. I can't get getdelays to run on my system.
A. Try a 2.6.2x kernel or higher (apparently there were some problems in the 19 kernel). Beyond that, check with your kernel vendor for additional support.
The major version of this module will match the latest version of the taskstats struct it supports natively (e.g., 3.xx for taskstats version 3, etc.).
The following documents in the 2.6.19 or higher Linux kernel sources (under the Documentation/accounting directory):
Scott Wiersdorf, <scott@perlcode.org>
Copyright (C) 2007 by Bluehost, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
To install Linux::Taskstats::Read, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Linux::Taskstats::Read
CPAN shell
perl -MCPAN -e shell install Linux::Taskstats::Read
For more information on module installation, please visit the detailed CPAN module installation guide.