From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steve Grubb Subject: Re: Minimizing CPU Utilization of audisp Plugin Date: Fri, 05 Oct 2018 10:10:22 -0400 Message-ID: <10916994.zGLAod9bSu@x2> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: linux-audit@redhat.com List-Id: linux-audit@redhat.com Hello, On Friday, October 5, 2018 9:11:28 AM EDT Osama Elnaggar wrote: > I'm currently working on a Python audisp plugin. My main routine looks > like this: > > if __name__ == '__main__': > > try: > ... > > aup = auparse.AuParser(auparse.AUSOURCE_FEED) > aup.add_callback(process_event, None) > > while True: > for _ in fileinput.input(): > aup.feed(_) > except: > ... > > While profiling my plugin, I noticed that 95% + of the CPU time used by my > plugin is used in fileinput.input(), waiting/reading from input > > Is there any way to lower this or preferred way to poll/read? I don't do much if any python programming. But in C, all examples include a select in the event processing loop. Python has a select module. There are examples on the internet about how to use it. One is here: https://www.programcreek.com/python/example/258/select.select There are other examples. -Steve