Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'offline': 0.03; '16,': 0.03; 'messages.': 0.04; 'subject:Python': 0.05; 'bits': 0.07; 'next,': 0.07; 'used.': 0.07; 'python': 0.09; 'broke': 0.09; 'itself,': 0.09; 'marking': 0.09; 'mem': 0.09; 'subject:create': 0.09; 'subject:messages': 0.09; 'timestamps': 0.09; 'to:addr:comp.lang.python': 0.09; 'will,': 0.09; 'cc:addr:python- list': 0.10; 'affinity': 0.16; 'cc:name:python list': 0.16; 'hits': 0.16; 'mark.': 0.16; 'marker': 0.16; 'oct': 0.16; 'preparing': 0.16; 'subject:log': 0.16; 'syslog': 0.16; 'wrote:': 0.17; 'test.': 0.17; 'module': 0.19; 'written': 0.20; 'bit': 0.21; 'ctypes': 0.22; 'parse': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; "i've": 0.23; 'second': 0.24; 'linux': 0.24; 'machine': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'done.': 0.27; 'first,': 0.27; "doesn't": 0.28; 'correct': 0.28; 'this?': 0.28; 'all.': 0.28; 'cpu': 0.29; 'occurred': 0.29; 'sleep': 0.29; 'points': 0.29; 'starts': 0.29; 'related': 0.30; 'ends': 0.30; 'seconds': 0.30; 'code': 0.31; 'point': 0.31; 'problem.': 0.32; 'could': 0.32; 'message.': 0.33; 'certain': 0.33; 'instead,': 0.33; 'problem': 0.33; 'anyone': 0.33; 'themselves': 0.33; 'hi,': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'or,': 0.34; 'done': 0.34; 'so,': 0.35; 'doing': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'be.': 0.36; 'test': 0.36; 'too': 0.36; 'october': 0.37; 'does': 0.37; 'uses': 0.37; 'skip:4 10': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'things': 0.38; 'google': 0.39; 'where': 0.40; 'help': 0.40; 'end': 0.40; 'networking': 0.60; 'skip:u 10': 0.60; 'most': 0.61; 'real': 0.61; 'first': 0.61; 'between': 0.63; 'services.': 0.63; 'total': 0.65; 'moments': 0.65; 'subject:there': 0.65; '"going': 0.84; 'different.': 0.84; 'injecting': 0.84; 'subject:via': 0.84; 'timestamps,': 0.84 Newsgroups: comp.lang.python Date: Tue, 16 Oct 2012 03:26:00 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=137.17.109.98; posting-account=QNsEXgoAAABu_Avbf026MEK8WO7y27Mt References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 137.17.109.98 MIME-Version: 1.0 Subject: Re: Is there a way to create kernel log messages via Python? From: Marco Nawijn To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 111 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350383164 news.xs4all.nl 6871 [2001:888:2000:d::a6]:40485 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31381 On Tuesday, October 16, 2012 5:43:28 AM UTC+2, J wrote: > Hi... > > > > I have a bit of code that does the following: > > > > uses the syslog module to inject a LOG_INFO message into the syslog on > > my linux machine > > runs a suspend/resume cycle > > uses the syslog module to inkect a LOG_INFO message marking the end of test. > > > > Then I parse everything between the start and stop markers for certain > > items that the Linux kernel logs during a suspend and resume cycle. > > > > But my "resume complete" timing is not as accurate as it could be. > > The problem with doing it this way is that while I can find definite > > kernel messages that mark various points in the suspend/resume cycle, > > the final message when the kernel is done resuming is NOT the point I > > actually want to mark. > > > > Instead, the end point I want is the time of the ending marker itself, > > as this happens after certain other things are done such as resumption > > of networking services. > > > > Here's the problem. I can't just use syslog timestamps. The reason > > is that the syslog timestamps are only indicative of when messages are > > written to syslog via syslogd. The kernel timestamps are different. > > For example, the following bits of log are taken from the time the > > test starts until the end of the "going to sleep" kernel messages. > > First, note that there's a 5 second difference between the START > > marker and the first kernel message. Next, look at the kernel > > timestamps. The total real time to suspend starts at 421320.380947 > > and ends at 421322.386355, around 2 seconds later, where the log > > messages themselves all state that the events occurred at the same > > time. > > > > Oct 15 10:24:19 klaatu sleep_test: ---SLEEP TEST START 1350296656--- > > Oct 15 10:25:24 klaatu kernel: [421320.380947] PM: Syncing filesystems ... done. > > Oct 15 10:25:24 klaatu kernel: [421320.391282] PM: Preparing system > > for mem sleep > > [SNIP] > > Oct 15 10:25:24 klaatu kernel: [421322.282943] Broke affinity for irq 23 > > Oct 15 10:25:24 klaatu kernel: [421322.386355] CPU 7 is now offline > > > > So, what I REALLY want is to inject my start/stop markers into klogd > > rather than syslogd. This will, I hope, give my markers kernel > > timestamps rather than syslog timestamps which are not as accurate. > > > > So does anyone know of a way to do this? Unfortunately, I've tried > > some searching but google doesn't like the term klog, and most of the > > hits involved injecting code or other things that are not related at > > all. > > > > Or, if there's a better way to get accurate timestamps, what would that be? Hi, I cannot be of too much help here, but is there a userspace/kernel C-interface that could be used. If so, you might be able to use the Python ctypes module to create messages at the correct moments Regards, Marco