Peter Stubbs
2009-Apr-28 15:05 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
Hi, I''m trying to modify the dtrace toolkit script iotop to print argv[0] rather than execname. This is because I have a very busy E25k running multiple oracle instances so execname always gives me ''oracle'' while argv[0] returns the oracle SID. I could post-process the output using the pid, but I''d rather just have it print argv0. This is a sample script that demonstrates my problem. #!/usr/sbin/dtrace -s #pragma D option quiet io:genunix::done { a1 = copyinstr((uintptr_t)(curpsinfo->pr_dmodel == PR_MODEL_ILP32 ? *(uint32_t *)copyin(arg1, 4) : *(uint64_t *)copyin(arg1, 8))); printf("%d:%s\n", pid, a1); } This just seems to produce the following style errors dtrace: error on enabled probe ID 1 (ID 8628: io:genunix:biodone:done): invalid address (0x0) in action #1 at DIF offset 256 dtrace: error on enabled probe ID 1 (ID 8628: io:genunix:biodone:done): invalid address (0x2a100a46000) in action #1 at DIF offset 256 dtrace: error on enabled probe ID 1 (ID 8628: io:genunix:biodone:done): invalid address (0x0) in action #1 at DIF offset 256 dtrace: error on enabled probe ID 1 (ID 8628: io:genunix:biodone:done): invalid address (0x0) in action #1 at DIF offset 256 I''ve tried io:genunix::done and io:genunix::start. Both behave the same way. It works most of the time with syscall::exece:entry, but that''s not what I''m interested in. I could use this #!/usr/sbin/dtrace -s #pragma D option quiet io:genunix::start { printf("%d:%s\n", pid, curpsinfo->pr_psargs); } which works a treat, but gives all of the argument vector, I only want the first entry! Does anyone know how to extract this info? I don''t want to use stop() and inspect /proc because I really don''t want to put that sort of overhead onto the system. Cheers, Peter -- This message posted from opensolaris.org
Jonathan Adams
2009-Apr-28 16:26 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
On Tue, Apr 28, 2009 at 08:05:32AM -0700, Peter Stubbs wrote:> Hi, > > I''m trying to modify the dtrace toolkit script iotop to print argv[0] > rather than execname. This is because I have a very busy E25k running > multiple oracle instances so execname always gives me ''oracle'' while > argv[0] returns the oracle SID. I could post-process the output using > the pid, but I''d rather just have it print argv0. This is a sample > script that demonstrates my problem. > > #!/usr/sbin/dtrace -s > #pragma D option quiet > io:genunix::done > { > a1 = copyinstr((uintptr_t)(curpsinfo->pr_dmodel == PR_MODEL_ILP32 ? *(uint32_t *)copyin(arg1, 4) : *(uint64_t *)copyin(arg1, 8))); > printf("%d:%s\n", pid, a1); > }There''s some confusion here: arg1 is the second *argument to the probe*, not argv[1] for the current process.> I''ve tried io:genunix::done and io:genunix::start. Both behave the same way. > > It works most of the time with syscall::exece:entry, but that''s not > what I''m interested in.> I could use this > #!/usr/sbin/dtrace -s > #pragma D option quiet > io:genunix::start > { > printf("%d:%s\n", pid, curpsinfo->pr_psargs); > } > which works a treat, but gives all of the argument vector, I only want > the first entry! > > Does anyone know how to extract this info? I don''t want to use stop() > and inspect /proc because I really don''t want to put that sort of > overhead onto the system.If you want the first argument, then: io:genunix::start { this->execname = strtok(curpsinfo->pr_psargs, " "); this->firstarg = strtok(NULL, " "); this->firstarg = (this->firstarg != NULL) ? this->firstarg : ""; printf("%d:%s %s\n", pid, this->execname, this->firstarg); } Cheers, - jonathan
Peter Stubbs
2009-Apr-28 21:51 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
Jonathan, Thankyou for putting me out of my misery! It''s works at last. Thanks again! Peter -- This message posted from opensolaris.org
Peter Stubbs
2009-Apr-29 12:48 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
Hi Again, That''s solved my problem, but what happens if argv[0] has a space in it? That would be very uncommon on solaris, but on a Mac it''s more common. It seems strange that all the arguments are only available bunched together with spaces between them. Is there a more reliable way to get this info? Cheers, Peter -- This message posted from opensolaris.org
Colin Burgess
2009-Apr-30 20:32 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
I''m not 100% sure how one finds it in Solaris, but isn''t argv[0] on the main thread''s stack? On Wed, Apr 29, 2009 at 8:48 AM, Peter Stubbs <ps258 at hotmail.com> wrote:> Hi Again, > > That''s solved my problem, but what happens if argv[0] has a space in it? > That would be very uncommon on solaris, but on a Mac it''s more common. It > seems strange that all the arguments are only available bunched together > with spaces between them. Is there a more reliable way to get this info? > > Cheers, > Peter > -- > This message posted from opensolaris.org > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >-- colin.burgess at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20090430/357f7b33/attachment.html>
James Litchfield
2009-Apr-30 21:53 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
argv[0] is on the stack but not always in the same place. See http://blogs.sun.com/thejel/category/Sun for the 26 Jul 2007 entry that discusses this. Jim --- Colin Burgess wrote:> I''m not 100% sure how one finds it in Solaris, but isn''t argv[0] on > the main thread''s stack? > > On Wed, Apr 29, 2009 at 8:48 AM, Peter Stubbs <ps258 at hotmail.com > <mailto:ps258 at hotmail.com>> wrote: > > Hi Again, > > That''s solved my problem, but what happens if argv[0] has a space > in it? That would be very uncommon on solaris, but on a Mac it''s > more common. It seems strange that all the arguments are only > available bunched together with spaces between them. Is there a > more reliable way to get this info? > > Cheers, > Peter > -- > This message posted from opensolaris.org <http://opensolaris.org> > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org <mailto:dtrace-discuss at opensolaris.org> > > > > > -- > colin.burgess at gmail.com <mailto:colin.burgess at gmail.com> > ------------------------------------------------------------------------ > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >
Colin Burgess
2009-May-01 01:23 UTC
[dtrace-discuss] trying to find argv[0] for writing processes
Yes - funnily enough that''s almost exactly the same as QNX 32bit Intel. :-) I guess it would be a bit evil in Dtrace to snoop through the various arrays to find the argv[0] there... :-) On Thu, Apr 30, 2009 at 5:53 PM, James Litchfield <James.Litchfield at sun.com>wrote:> argv[0] is on the stack but not always in the same place. See > http://blogs.sun.com/thejel/category/Sun for the > 26 Jul 2007 entry that discusses this. > > Jim > --- > Colin Burgess wrote: > >> I''m not 100% sure how one finds it in Solaris, but isn''t argv[0] on the >> main thread''s stack? >> >> On Wed, Apr 29, 2009 at 8:48 AM, Peter Stubbs <ps258 at hotmail.com <mailto: >> ps258 at hotmail.com>> wrote: >> >> Hi Again, >> >> That''s solved my problem, but what happens if argv[0] has a space >> in it? That would be very uncommon on solaris, but on a Mac it''s >> more common. It seems strange that all the arguments are only >> available bunched together with spaces between them. Is there a >> more reliable way to get this info? >> >> Cheers, >> Peter >> -- >> This message posted from opensolaris.org <http://opensolaris.org> >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org <mailto:dtrace-discuss at opensolaris.org> >> >> >> >> >> -- >> colin.burgess at gmail.com <mailto:colin.burgess at gmail.com> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org >> >> > >-- colin.burgess at gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20090430/5dfabf5d/attachment.html>