Original post

Hi all,

I got 2 problems related to the same task (hence I only post it once). This is about a project that needs to check regular expressions in Perl style (including lokaheads etc, which are not supported by ’s standard regexp). So I’m using github.com/glenn-brown/-pkg-pcre/src/pkg/pcre, which is a wrapper around the Unix pcre library (using cgo). In my project, hundreds of threads are using this library concurrently.

One problem is that the execution of the C library call often takes a very long time, so I’m wondering if there’s a possibility to time-limit these calls. Basically this would mean to stop the execution of a goroutine from another one, which afaik is not possible; but maybe there is some way to solve the issue for an external cgo routine that went havoc?

An alternative solution would be to at least log execution times of these calls, and also sort them such that I can see what search term caused problems on what data. I would prefer not using Go’s pprof (I don’t think I get the data I need out of it, i.e. sorted and summed after tge search terms), so I started by simply measure wallclock times before and after these regex calls. This works quite well, but of wallclock time is not optimal in case of a concurrent program; the actual CPU time used by the current goroutine would be much better. Is there a way to get this information, or maybe at least for the cgo call itself? Measuring thread times would not work neither, as go routines are lightweight (not sure however about cgo calls). All I found on Google at some point tells you to use pprof – which I think would be overkill for this case, and would not give me the information grouped the way I’d need it; but maybe I’m missing something?