Re: [systemd-devel] order of sd_journal_query_unique()?

2015-03-09 Thread Daurnimator
On 6 March 2015 at 14:38, Daurnimator q...@daurnimator.com wrote:
 sd_journal_query_unique() finds unique *field names*.
 Not journal entries.

Apologies, I described this incorrectly.

sd_journal_query_unique() takes a field name, and allows you to
iterate over all different values that field has taken.

To accomplish a wildcard or pattern matched search, you can iterate
through unique fields, adding all that meet your pattern as matches.

Here is an example lua program that will print (in reverse) matches
for the given field and (lua) pattern:

#!/usr/bin/env lua
--[[
Depends on lua-systemd: https://github.com/daurnimator/lua-systemd
]]

local sj = require systemd.journal

local field = assert(arg[1], need to provide field name)
local patt = assert(arg[2], need to provide a pattern)

local j = assert(sj.open())

assert(j:seek_tail())
assert(j:flush_matches())
local has_at_least_one = false
for value in j:each_unique(field) do
if value:match(patt) then
has_at_least_one = true
assert(j:add_match(field..=..value))
end
end
if not has_at_least_one then
io.stderr:write(no matches found\n)
os.exit(1)
end
assert(j:add_disjunction())
while j:previous() do
print(j:get(_SYSTEMD_UNIT), j:get(MESSAGE))
end
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] order of sd_journal_query_unique()?

2015-03-06 Thread Chris Morgan
On Fri, Mar 6, 2015 at 6:45 PM, Daurnimator q...@daurnimator.com wrote:
 On 6 March 2015 at 16:13, Chris Morgan chmor...@gmail.com wrote:
 So is SD_JOURNAL_FOREACH_BACKWARDS the fastest way to find the newest
 journal entry with a given field? journalctl seems a ton faster than
 my c application is when I search for a given field that is not
 present. And by search I'm doing:

 journalctl --user BLAH=1

 Chris

 To find the newest journal entry:
   - sd_journal_seek_tail
   - sd_journal_add_match and similar to add criteria
   - sd_journal_previous

Yes, this looks much more efficient.

Thank you.

Chris
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] order of sd_journal_query_unique()?

2015-03-06 Thread Daurnimator
On 6 March 2015 at 16:13, Chris Morgan chmor...@gmail.com wrote:
 So is SD_JOURNAL_FOREACH_BACKWARDS the fastest way to find the newest
 journal entry with a given field? journalctl seems a ton faster than
 my c application is when I search for a given field that is not
 present. And by search I'm doing:

 journalctl --user BLAH=1

 Chris

To find the newest journal entry:
  - sd_journal_seek_tail
  - sd_journal_add_match and similar to add criteria
  - sd_journal_previous
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] order of sd_journal_query_unique()?

2015-03-06 Thread Chris Morgan
I was using a journal iterator to search from the newest journal entry
backwards for a matching field, using SD_JOURNAL_FOREACH_BACKWARDS.
This appears to be pretty slow but journalctl is really fast. I went
looking and found sd_journal_query_unique() (although I'm not 100%
positive this is why journalctl is faster).

Looking at 
http://www.freedesktop.org/software/systemd/man/sd_journal_query_unique.html
there isn't any mention of ordering or direction.

Is this search finding journal entries that are newest to oldest or???

Chris
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] order of sd_journal_query_unique()?

2015-03-06 Thread Daurnimator
On 6 March 2015 at 14:25, Chris Morgan chmor...@gmail.com wrote:
 I was using a journal iterator to search from the newest journal entry
 backwards for a matching field, using SD_JOURNAL_FOREACH_BACKWARDS.
 This appears to be pretty slow but journalctl is really fast. I went
 looking and found sd_journal_query_unique() (although I'm not 100%
 positive this is why journalctl is faster).

 Looking at 
 http://www.freedesktop.org/software/systemd/man/sd_journal_query_unique.html
 there isn't any mention of ordering or direction.

 Is this search finding journal entries that are newest to oldest or???

sd_journal_query_unique() finds unique *field names*.
Not journal entries.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] order of sd_journal_query_unique()?

2015-03-06 Thread Chris Morgan
On Fri, Mar 6, 2015 at 2:38 PM, Daurnimator q...@daurnimator.com wrote:
 On 6 March 2015 at 14:25, Chris Morgan chmor...@gmail.com wrote:
 I was using a journal iterator to search from the newest journal entry
 backwards for a matching field, using SD_JOURNAL_FOREACH_BACKWARDS.
 This appears to be pretty slow but journalctl is really fast. I went
 looking and found sd_journal_query_unique() (although I'm not 100%
 positive this is why journalctl is faster).

 Looking at 
 http://www.freedesktop.org/software/systemd/man/sd_journal_query_unique.html
 there isn't any mention of ordering or direction.

 Is this search finding journal entries that are newest to oldest or???

 sd_journal_query_unique() finds unique *field names*.
 Not journal entries.


Hmm

So is SD_JOURNAL_FOREACH_BACKWARDS the fastest way to find the newest
journal entry with a given field? journalctl seems a ton faster than
my c application is when I search for a given field that is not
present. And by search I'm doing:

journalctl --user BLAH=1

Chris
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel