Skip to content

Commit 6320847

Browse files
authored
Merge pull request #92 from chrismullins/support-realtime-cutoff
Support realtime cutoff access
2 parents 8b92ac5 + d6b3af9 commit 6320847

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

systemd/_reader.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,48 @@ static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args) {
883883
Py_RETURN_NONE;
884884
}
885885

886+
PyDoc_STRVAR(Reader_get_start__doc__,
887+
"get_start() -> int\n\n"
888+
"Return the realtime timestamp of the first journal entry\n\n"
889+
"in microseconds.\n\n"
890+
"Wraps sd_journal_get_cutoff_realtime_usec().\n"
891+
"See :manpage:`sd_journal_get_cutoff_realtime_usec(3)`.");
892+
static PyObject* Reader_get_start(Reader *self, PyObject *args) {
893+
uint64_t start;
894+
int r;
895+
896+
assert(self);
897+
assert(!args);
898+
899+
r = sd_journal_get_cutoff_realtime_usec(self->j, &start, NULL);
900+
if (set_error(r, NULL, NULL) < 0)
901+
return NULL;
902+
903+
assert_cc(sizeof(unsigned long long) == sizeof(start));
904+
return PyLong_FromUnsignedLongLong(start);
905+
}
906+
907+
PyDoc_STRVAR(Reader_get_end__doc__,
908+
"get_end() -> int\n\n"
909+
"Return the realtime timestamp of the last journal entry\n\n"
910+
"in microseconds.\n\n"
911+
"Wraps sd_journal_get_cutoff_realtime_usec().\n"
912+
"See :manpage:`sd_journal_get_cutoff_realtime_usec(3)`.");
913+
static PyObject* Reader_get_end(Reader *self, PyObject *args) {
914+
uint64_t end;
915+
int r;
916+
917+
assert(self);
918+
assert(!args);
919+
920+
r = sd_journal_get_cutoff_realtime_usec(self->j, NULL, &end);
921+
if (set_error(r, NULL, NULL) < 0)
922+
return NULL;
923+
924+
assert_cc(sizeof(unsigned long long) == sizeof(end));
925+
return PyLong_FromUnsignedLongLong(end);
926+
}
927+
886928

887929
PyDoc_STRVAR(Reader_process__doc__,
888930
"process() -> state change (integer)\n\n"
@@ -1278,6 +1320,8 @@ static PyMethodDef Reader_methods[] = {
12781320
{"seek_tail", (PyCFunction) Reader_seek_tail, METH_NOARGS, Reader_seek_tail__doc__},
12791321
{"seek_realtime", (PyCFunction) Reader_seek_realtime, METH_VARARGS, Reader_seek_realtime__doc__},
12801322
{"seek_monotonic", (PyCFunction) Reader_seek_monotonic, METH_VARARGS, Reader_seek_monotonic__doc__},
1323+
{"_get_start", (PyCFunction) Reader_get_start, METH_NOARGS, Reader_get_start__doc__},
1324+
{"_get_end", (PyCFunction) Reader_get_end, METH_NOARGS, Reader_get_end__doc__},
12811325
{"process", (PyCFunction) Reader_process, METH_NOARGS, Reader_process__doc__},
12821326
{"wait", (PyCFunction) Reader_wait, METH_VARARGS, Reader_wait__doc__},
12831327
{"seek_cursor", (PyCFunction) Reader_seek_cursor, METH_VARARGS, Reader_seek_cursor__doc__},

systemd/journal.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ def seek_realtime(self, realtime):
318318
realtime = int(realtime * 1000000)
319319
return super(Reader, self).seek_realtime(realtime)
320320

321+
def get_start(self):
322+
start = super(Reader, self)._get_start()
323+
return _convert_realtime(start)
324+
325+
def get_end(self):
326+
end = super(Reader, self)._get_end()
327+
return _convert_realtime(end)
328+
321329
def seek_monotonic(self, monotonic, bootid=None):
322330
"""Seek to a matching journal entry nearest to `monotonic` time.
323331

0 commit comments

Comments
 (0)