Category: Code
Date: 2008.05.04

gcov file summaries vs. manpage

Playing with gcov recently, I noticed the output on multiple machines does not match the manpage. On a larger program the gcov summary of a source file appears displays a value the man page implies should be total lines but is in reality ... not.

Even the trivial example from the gcov man page (from both OS X leopard and redhat box) produces different output (in format an values).

man page:

gcov -b tmp.c
90.00% of 10 source lines executed in file tmp.c
80.00% of 5 branches executed in file tmp.c
80.00% of 5 branches taken at least once in file tmp.c
50.00% of 2 calls executed in file tmp.c
Creating tmp.c.gcov.

reality:

ryans-mac-pro:Gcov rbetts$ gcov -b man.c
File 'man.c'
Lines executed:87.50% of 8
Branches executed:100.00% of 4
Taken at least once:75.00% of 4
Calls executed:50.00% of -2
man.c:creating 'man.c.gcov'

The useful in-file annotations are correct and on the non-trivial program match my understanding of what's being excercised.

Wonder how lcov generates its results? From the summary or by recalculating from the source annotations? It does make pretty summaries, though:

Category: Code
Date: 2008.02.09

Creating XML with Python using xml.dom.minidom

A google search for "create xml with python" doesn't return the python documentation site as top link. Searching for "site:www.python.org create xml with python" doesn't do much better. Google does lead to a few good pages on the topic. I read those to start.

Create a document:

    import xml.dom.minidom
    doc = xml.dom.minidom.Document()

Create an element:

    el = doc.createElementNS("http://example.com/namespaceURI", "name")
    doc.appendChild(el)

Don't to be fooled in to thinking minidom's output methods will serialize that namespace in any way whatsoever. Long discussions debate this point... I didn't go off and read the DOM spec. (Well, okay, I peeked.) I added my own namespace attributes, setting the default namespace in this example. The first time I felt let down by python.

    el.setAttribute("xmlns", "http://example.com/namespaceURI")

Create additional elements and text nodes.

    elWithContent = doc.createElementNS("http://example.com/namespaceURI", "content")
    content = doc.createTextNode("some text content")
    elWithContent.appendChild(content)
    el.appendChild(elWithContent)

Serialize to a file.

    fileObj = open("example.xml", 'w')
    fileObj.write(doc.toxml())
    fileObj.close()

The resulting output:

    <name xmlns="http://example.com/namespaceURI"><content>some text content</content></name>

Category: Code
Date: 2008.01.27

A Test of Remotely Authored Post

This is a simple test to see if my remote posting will work. This was authored on my power book - with luck it will appear on my blog :-)