The primary purpose (as noted in Perl coredump analysis tool ?), is to provide a strace-like capability for running Perl apps. Which means the external strace program (let's call it plstrace) needs to share something with the running script thats being traced. Note that plstrace is completely independent of the script to be traced, except for the ability to peek into the shared area to see what the script is doing at any given moment, and hence threads::shared is not an option for the shared area.

Further, I'd like to be able to support both Win32 and *nix platforms. The most similar solution I can find for those is memory mapped files, via Win32::MMF and Sys::Mmap, respectively. So plstrace, and Devel:STrace map to the same file, w/ Devel::STrace acting a bit like Devel::Dprof, except simpler: just keeping track of the call stack, and updating things in the shared area as things change. I try to minimze the amount of accesses and locks to keep the overhead as minimal as I can (Unfortunately, Win32::MMF does a lot of extra stuff I'd rather it not do in that regard, but in the interest of GOWI, I'll live with it...if I can get Win32::MMF to work).

Now the fun part: my primary need for this is a large multithreaded application which occasionally hangs in one of the threads (apparently caught in an infinite loop). Hence, Devel::STrace needs to dump traces for all the threads in a process. So, thru a series of clever parlor tricks, each thread gets its own region of the mmf to trace its call stack, from which DB::sub() adds and removes entries, and which DB::DB() updates with line numbers and timestamps. And plstrace attaches to the mmf and dumps its contents every so often. And then I eyeball the output when on of my threads goes 100% CPU, et voila I know which thread and where things are going awry.

Note that I'm not doing anything w/ threads::shared and mmf here. I was *hoping* that all that cloning would properly pick up the tie of the mmf scalar I'm using, and I'd just use CLONE() to invalidate the current mmf region and grab a new one for the new thread. And everything just carries merrily on. (And, wonder of wonders it actually works on Linux - FC4 Perl 5.8.6 - ! Tho Sys::Mmap has its own set of bizarre behavior)

But I don't want to stop there...the next step is multiprocess apps and multithreaded-multiprocess apps. One might question my sanity for pursuing multiprocess support, since the user can always separately attach plstrace to each process manually...but being able to see everything as a group seems useful to me, and (theoretically, at least) should work just as well as a single process, multithreaded solution.

Thats why.


In reply to Re^2: Win32::MMF + threads misbehavior by renodino
in thread Win32::MMF + threads misbehavior by renodino

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.