On 06/14/2013 10:43 PM, Zbigniew Jędrzejewski-Szmek wrote:
On Wed, Jun 12, 2013 at 02:41:15PM +0200, Jan Janssen wrote:
Unfortunately, to get a chronological list of boot IDs, we
need to search through the journal. sd_journal_enumerate_unique()
doesn't help us here, because the order of returned values
is undefined.
Hi Jan,

as an experiment, I tried to create the time-sorted list of boot
ids in python:

from pprint import pprint
from systemd import journal
j = journal.Reader()
matches={}
for id in j.query_unique('_BOOT_ID'):
    j.add_match(_BOOT_ID=id.hex)
    j.seek_head()
    try:
        ts = j.get_next()['__REALTIME_TIMESTAMP']
        print(ts)
    except OSError as e:
        print(e)    # [1]
    else:
        matches[ts] = id
    j.flush_matches()

pprint(sorted(matches.items()))

This runs very fast on my machine... I have ~1GB of logs (cached in RAM),
and it runs .12s including Python load time. In fact python -c '' takes .04s,
so not an insubstantial chunk of the time for the whole query.

I think you might be overcomplicating the function to query boot
ids.
I like the idea. But sorting the boot IDs could order a few boots
wrongly, since realtime can jump backwards.

Jan
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to