Python way to printk?

J

J

Does anyone know of a way, or have a recipe, to do a linux printk
equivalent in Python?

I've been googling for a while and not finding anything useful.

The nutshell version of this is that I need to write a routine for a
test tool I'm working on that will time the amount of time used to
take a system and go from Live to Suspended and then from Suspended to
Live.

I can get all the times I need from the kernel message buffer (via
dmesg) but one of the test cases involves doing 30 suspend/resume
cycles, so I'll end up having to parse and weed out a lot of redundant
data.

One idea I had was to just flush the buffer (calling dmesg -c) but
that's not the nicest way of doing things on an end user's system.

SO, the thought I had was to just inject a marker like "START SUSPEND
TEST hash" where hash is a unique identifier for that test run, either
the number of the run (1 - 30) or a timestamp or whatever... it just
has to be unique
and then inject a "FINISHED SUSPEND TEST has" marker after the system
is fully live.

THEN I could just look for those two markers and parse the data in
between them for the timestamps I need.

but I can't find any way so far, in python to write kernel messages.
Perhaps this is something for ctypes? (though I'm trying to keep from
introducing non-python code if at all possible) and I've never used
ctypes before and have no real idea how to use them (perhaps this
would be a good, easy way to learn?)

I'm going to start looking at ctypes after sending this and maybe
learn something new today, but I also wanted to ask the list for
suggestions as well.

Cheers,

Jeff

And yes, this is not something that would be portable to a non-Linux
OS, but that's ok, because this is strictly a Linux tool anyway.
 
N

News123

Hi J,
Does anyone know of a way, or have a recipe, to do a linux printk
equivalent in Python?

I've been googling for a while and not finding anything useful.

The nutshell version of this is that I need to write a routine for a
test tool I'm working on that will time the amount of time used to
take a system and go from Live to Suspended and then from Suspended to
Live.

I can get all the times I need from the kernel message buffer (via
dmesg) but one of the test cases involves doing 30 suspend/resume
cycles, so I'll end up having to parse and weed out a lot of redundant
data.

One idea I had was to just flush the buffer (calling dmesg -c) but
that's not the nicest way of doing things on an end user's system.

SO, the thought I had was to just inject a marker like "START SUSPEND
TEST hash" where hash is a unique identifier for that test run, either
the number of the run (1 - 30) or a timestamp or whatever... it just
has to be unique
and then inject a "FINISHED SUSPEND TEST has" marker after the system
is fully live.


I'm rephrasing your question:
You would like to perform printk from user space.
I think this is not really intended.

You could write a small linux kernel module relaying user space messages
to the dmesg buffer.


Just look at
http://serverfault.com/questions/140354/how-to-add-message-that-will-be-read-with-dmesg
to get some ideas and continue googling for |"printk" and "user space".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top