Sunday, 31 January 2010

inotail - tail clone using inotify

I regularly use the tail command to look at the end of log files - generally I use the -f flag to follow (monitor and display) new entries that are appended to the log.

Tail will poll every second to see if the file size is changed and will act if data has been appended or the file has been truncated, and the poll interval is adjustable.  However, polling a file is plain ugly, it causes extra wakeup events and if one wants very fast updates then polling is not a good solution.

Hence, a better tool to use is inotail when following a file. Inotail uses inotify to only wake up inotail when a file has been modified, deleted or moved - hence no polling is required.  This also means inotail will output the changes to a file almost immediately - unlike tail which by default may wait almost a second before detecting a change.

To install inotail use:

sudo apt-get install inotail

..and use it the same was as tail.

UPDATE:  Pete Graner has also informed me that the tailf command is also an inotify based tail -f like replacement too. Just goes to show there are many ways of doing the same thing...

Thursday, 28 January 2010

Using the FIEMAP ioctl() to get file extents

The fiemap ioctl() allows user space programmes to glean the extent information from a file's inode in a fairly direct and fast way.

Mark Fasheh (Suse) has written up a detailed description of this ioctl() in a LWN article, and this is really worth reading.

I've put some quick-and-hacky sample code in my repository to dump out the file extents of given files. This code works in two phases.  Step 1, one allocates a fiemap structure and queries the number of extents a file has.   Step 2, one re-allocates the fiemap structure with enough space for the extent data to be filled in by the ioctl() and re-issues the ioctl() query to get the requested extent data.   Data such as the physical and logical block location and also the size of the extent and extent flags is returned for each extent.

Code such as ureadahead uses fiemap; ureadahead in fact re-probes with the fiemap ioctl() if it detects that the number of extents has increased - just in case the file is growing during the probe.

[ Update ]

It appears that cp has recently been modified to use FIEMAP to detect where holes are in a file to make copying more efficient. However, some users have reported seeing cp corruption issues - the root cause was that FIEMAP was not dealing with regions of a file that have been written to that don't have blocks yet assigned.  This is alarming, as the delayed allocation mechanism is used by modern filesystems.  This is described in more detail in a recent LWN article.

Wednesday, 20 January 2010

Simple ACPI monitoring tools

Back to basics - here are a couple of quick-and-easy tools for seeing ACPI activity on linux. The first is acpi_listen (from the acpid package) - this tool simply monitors ACPI events and dumps them to stdout:

$ acpi_listen
button/power PWRF 00000080 00000001
ac_adapter AC0 00000080 00000000

The above shows the events when I hit the power button and suspend a HP mini netbook.  One can specify the number of events to capture before exiting with the -c flag, and also the number of seconds to wait for with the -t flag. As things go, it's a handy sanity checking tool to make sure things like specific button events get handled correctly.

The next tool is acpitail - this periodically dumps out ACPI status about the battery, fan and temperature to stdout. One can specify the update polling intervals for checking state change using various flags.  To install use:

sudo apt-get install acpitail

and to use, simply run:

$ acpitail
Wed Jan 20 20:40:14 2010
BAT1 remaining capacity: 88% (126 minutes)
Adapter AC0: batteries
temperature THRM: 47 (ok)
Wed Jan 20 20:40:19 2010
temperature THRM: 46 (ok)
Wed Jan 20 20:40:29 2010
temperature THRM: 45 (ok)

..again, it's another simple tool to do some ACPI state sanity checking.

Tuesday, 12 January 2010

Fixing the BBC clickbits sign off

The other week I E-mailed the BBC to grumble (in a very tongue-in-cheek manner) about the sign-off tag line in their Clickbits technology news video. The sign-off goes:

"Updates have now been installed - you may reboot"

I helpfully pointed out that this was Microsoft-centric and Linux users generally don't have to reboot after installing updates. I suggested an alternative tag line of:

"Updates have now been installed, unfortunately Microsoft users are forced to reboot to get the goodness."

Today I received a friendly E-mail from Zoe Kleinman, the Clickbits Producer, politely asking me to check out the following URL:  http://news.bbc.co.uk/1/hi/technology/8449159.stm

...behold, at the end of the video, the sign-off tag line is now:

"Updates have now been installed, you may restart, unless you are using Linux, in which case you don't have too."

Excellent! I'm really glad the BBC is listening!  Kudos to Zoe for being so enlightened!

Thursday, 7 January 2010

Raving about WorkRave

I'm now back from having several weeks rest after a major operation on my neck to replace a slipped disc with a Titanium one. The operation went well, I just need to now focus on doing a lot of regular neck exercises through the day to keep me from seizing up.

Thankfully I found a neat little application called WorkRave. WorkRave is designed to help stop repetitive strain injury (RSI), but I've been using it to tell me when to have short breaks to exercise my neck and back.

To install it on a Ubuntu system use:

sudo apt-get install workrave

WorkRave allows one to configure short micro-breaks, rest breaks and daily work limits. At the break intervals, one is presented a set of short exercises, such neck turning, shoulder-arm stretches, should movements, neck tilts, etc...





WorkRave keeps track of mouse movements and keystrokes, it can be very revealing just how many meters one moves a mouse in a day and how much one can type! It also keeps the stats on a daily basis, so one can see one's desktop usage over a period of weeks and months.

I'd recommend using this application if you need regular desk-exercise and don't mind a little bit of regular nagging from the computer. Give it a try! It's certainly helped me!