Mehul Choube
2011-Nov-08 11:48 UTC
[dtrace-discuss] concatenate structure members into one variable
Hi, I want the guid in a variable. I tried stringof(), strjoin(), copyinstr() but none works :( D script: ====== #!/usr/sbin/dtrace -s #pragma D option quiet typedef struct GUID { unsigned long Data1; unsigned long Data2; unsigned long Data3; unsigned char Data4[8]; }GUID_t; pid$1::*myFunc*:entry { this->ptr = arg1; this->sptr = (GUID_t *)copyin(this->ptr, sizeof(GUID_t)); printf("Id: "); printf("%8.8X%4.4X%4.4X%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X\\n", ((GUID_t *)this->sptr)->Data1, ((GUID_t *)this->sptr)->Data2, ((GUID_t *)this->sptr)->Data3, ((GUID_t *)this->sptr)->Data4[0], ((GUID_t *)this->sptr)->Data4[1], ((GUID_t *)this->sptr)->Data4[2], ((GUID_t *)this->sptr)->Data4[3], ((GUID_t *)this->sptr)->Data4[4], ((GUID_t *)this->sptr)->Data4[5], ((GUID_t *)this->sptr)->Data4[6], ((GUID_t *)this->sptr)->Data4[7]); } ====== The output is: Id: 11E109F8702B323E9CAF5000568000D000000000 Any help is greatly appreciated. Thanks, Mehul -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20111108/25569008/attachment.html>
James Carlson
2011-Nov-08 12:44 UTC
[dtrace-discuss] concatenate structure members into one variable
Mehul Choube wrote:> Hi, > > I want the guid in a variable. I tried stringof(), strjoin(), > copyinstr() but none works LAs defined, it''s a structure containing longs and binary data, not a string. Can you describe what sort of result you''d like to see? Or perhaps what sort of problem you''d like to solve?> The output is: > Id: 11E109F8702B323E9CAF5000568000D000000000Is that output wrong ... ? -- James Carlson 42.703N 71.076W <carlsonj at workingcode.com>
Mehul Choube
2011-Nov-08 13:02 UTC
[dtrace-discuss] concatenate structure members into one variable
Hi, I want to collect the performance information for each myFunc call. The program is multi-threaded and uses multiple queues which can be served by any thread. GUID is the unique handle for each request. I can collect the information and store it based on GUID something like: @[guid] = ... I think the ID is correct. Thanks, Mehul -----Original Message----- From: James Carlson [mailto:carlsonj at workingcode.com] Sent: 08 November 2011 18:15 To: Mehul Choube Cc: dtrace-discuss at opensolaris.org Subject: Re: [dtrace-discuss] concatenate structure members into one variable Mehul Choube wrote:> Hi, > > I want the guid in a variable. I tried stringof(), strjoin(), > copyinstr() but none works LAs defined, it''s a structure containing longs and binary data, not a string. Can you describe what sort of result you''d like to see? Or perhaps what sort of problem you''d like to solve?> The output is: > Id: 11E109F8702B323E9CAF5000568000D000000000Is that output wrong ... ? -- James Carlson 42.703N 71.076W <carlsonj at workingcode.com>
James Carlson
2011-Nov-08 13:20 UTC
[dtrace-discuss] concatenate structure members into one variable
Mehul Choube wrote:> Hi, > > I want to collect the performance information for each myFunc call. The program is multi-threaded and uses multiple queues which can be served by any thread. GUID is the unique handle for each request. I can collect the information and store it based on GUID something like: > > @[guid] = ... > > I think the ID is correct.Then just use the data as they are. Dtrace doesn''t have functions that translate buffers into D strings. (The trace() mechanism actually logs the raw data; the printing occurs well after the fact when the user-space code gets ahold of the sampled data.) -- James Carlson 42.703N 71.076W <carlsonj at workingcode.com>
Mehul Choube
2011-Nov-08 13:20 UTC
[dtrace-discuss] concatenate structure members into one variable
Hi, Yes but that is my last resort. Also, I have other values also like: io::wait-done /self->waits/ { self->elapsed = ((timestamp - self->waits) / 1000000); @[guid, pid, tid, args[2]->fi_pathname] = sum(this->elapsed); self->waits = 0; } But now it will have to be: @[self->Data1, self->Data2, self->Data3, self->Data4, pid, tid, args[2]->fi_pathname] = sum(this->elapsed); Right? Thanks, Mehul -----Original Message----- From: Michael Schuster [mailto:michaelsprivate at gmail.com] Sent: 08 November 2011 18:40 To: Mehul Choube Subject: Re: [dtrace-discuss] concatenate structure members into one variable On Tue, Nov 8, 2011 at 14:02, Mehul Choube <Mehul_Choube at symantec.com> wrote:> Hi, > > I want to collect the performance information for each myFunc call. The program is multi-threaded and uses multiple queues which can be served by any thread. GUID is the unique handle for each request. I can collect the information and store it based on GUID something like: > > @[guid] = ...I could be mistaken (it''s been a while since I''ve done any significant work with DTrace), but can''t you use more than one value as value to hash on, eg @[a,b,c] (check the exact syntax)? HTH Michael> I think the ID is correct. > > > > Thanks, > Mehul > > -----Original Message----- > From: James Carlson [mailto:carlsonj at workingcode.com] > Sent: 08 November 2011 18:15 > To: Mehul Choube > Cc: dtrace-discuss at opensolaris.org > Subject: Re: [dtrace-discuss] concatenate structure members into one variable > > Mehul Choube wrote: >> Hi, >> >> I want the guid in a variable. I tried stringof(), strjoin(), >> copyinstr() but none works L > > As defined, it''s a structure containing longs and binary data, not a > string. ?Can you describe what sort of result you''d like to see? ?Or > perhaps what sort of problem you''d like to solve? > >> The output is: >> Id: 11E109F8702B323E9CAF5000568000D000000000 > > Is that output wrong ... ? > > -- > James Carlson ? ? ? ? 42.703N 71.076W ? ? ? ? <carlsonj at workingcode.com> > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >-- Michael Schuster http://recursiveramblings.wordpress.com/
Mehul Choube
2011-Nov-08 13:31 UTC
[dtrace-discuss] concatenate structure members into one variable
Hi, self->d4 = ((GUID_t *)this->sptr)->Data4[0]; works but self->d4 = ((GUID_t *)this->sptr)->Data4; doesn''t with following error: dtrace: failed to compile script nums.d: line 20: operator = may not be applied to operand of type "unsigned char [8]" Thanks, Mehul -----Original Message----- From: James Carlson [mailto:carlsonj at workingcode.com] Sent: 08 November 2011 18:50 To: Mehul Choube Cc: dtrace-discuss at opensolaris.org Subject: Re: [dtrace-discuss] concatenate structure members into one variable Mehul Choube wrote:> Hi, > > I want to collect the performance information for each myFunc call. The program is multi-threaded and uses multiple queues which can be served by any thread. GUID is the unique handle for each request. I can collect the information and store it based on GUID something like: > > @[guid] = ... > > I think the ID is correct.Then just use the data as they are. Dtrace doesn''t have functions that translate buffers into D strings. (The trace() mechanism actually logs the raw data; the printing occurs well after the fact when the user-space code gets ahold of the sampled data.) -- James Carlson 42.703N 71.076W <carlsonj at workingcode.com>
Chris Ridd
2011-Nov-08 15:40 UTC
[dtrace-discuss] concatenate structure members into one variable
On 8 Nov 2011, at 13:20, James Carlson wrote:> Mehul Choube wrote: >> Hi, >> >> I want to collect the performance information for each myFunc call. The program is multi-threaded and uses multiple queues which can be served by any thread. GUID is the unique handle for each request. I can collect the information and store it based on GUID something like: >> >> @[guid] = ... >> >> I think the ID is correct. > > Then just use the data as they are. Dtrace doesn''t have functions that > translate buffers into D strings.It is a pity there''s no sprintf; was the omission of sprintf from D a deliberate design decision? Chris
James Carlson
2011-Nov-08 15:54 UTC
[dtrace-discuss] concatenate structure members into one variable
Mehul Choube wrote:> Hi, > > Yes but that is my last resort. > Also, I have other values also like: > > io::wait-done > /self->waits/ > { > self->elapsed = ((timestamp - self->waits) / 1000000); > @[guid, pid, tid, args[2]->fi_pathname] = sum(this->elapsed); > self->waits = 0; > } > > But now it will have to be: > > @[self->Data1, self->Data2, self->Data3, self->Data4, pid, tid, args[2]->fi_pathname] = sum(this->elapsed); > > Right?Something like that. You''ll probably have to use the elements inside Data4[]. It might be helpful to use a #define to hide the expansion, so you can just say GUID(self->guid), or some such. -- James Carlson 42.703N 71.076W <carlsonj at workingcode.com>
James Carlson
2011-Nov-08 16:01 UTC
[dtrace-discuss] concatenate structure members into one variable
Mehul Choube wrote:> Hi, > > self->d4 = ((GUID_t *)this->sptr)->Data4[0]; > > works but > > self->d4 = ((GUID_t *)this->sptr)->Data4; > > doesn''t with following error: > > dtrace: failed to compile script nums.d: line 20: operator = may not be applied to operand of type "unsigned char [8]"Since it''s an internal array, you should be able to cast it to "unsigned char *". Or, if you really want to keep broken out values instead of a structure (why?), you could individually address each byte. It might be helpful to have something like: #define DATA4(d4) (((uint64_t)(d4)[0]<<56) \ ((uint64_t)(d4)[1]<<48) \ ((uint64_t)(d4)[2]<<40) \ ((uint64_t)(d4)[3]<<32) \ ((uint64_t)(d4)[4]<<24) \ ((uint64_t)(d4)[5]<<16) \ ((uint64_t)(d4)[6]<<8) \ ((uint64_t)(d4)[7])) so you can treat that last one as an integral quantity. -- James Carlson 42.703N 71.076W <carlsonj at workingcode.com>
Jonathan Adams
2011-Nov-08 18:57 UTC
[dtrace-discuss] concatenate structure members into one variable
On Tue, Nov 08, 2011 at 03:48:17AM -0800, Mehul Choube wrote:> Hi, > > I want the guid in a variable. I tried stringof(), strjoin(), copyinstr() but none works :( > > D script: > > ======> > #!/usr/sbin/dtrace -s > > #pragma D option quiet > > typedef struct GUID { > unsigned long Data1; > unsigned long Data2; > unsigned long Data3; > unsigned char Data4[8]; > }GUID_t; >Have you tried: pid$1::*myFunc*:entry { this->ptr = arg1; this->sptr = (GUID_t *)copyin(this->ptr, sizeof(GUID_t)); @a[*this->sptr] = count(); ^^^^^^^^^^^^^^^^^^^^^^^^^ } Cheers, - jonathan
Mehul Choube
2011-Nov-09 04:17 UTC
[dtrace-discuss] concatenate structure members into one variable
Hi, The output is: 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 0: 00 77 83 ef 87 0a e1 11 a4 7b 00 50 56 80 00 d0 .w.......{.PV... 10: 00 00 00 00 .... 1 Thanks, Mehul -----Original Message----- From: Jonathan Adams [mailto:jonathan.adams at oracle.com] Sent: 09 November 2011 00:27 To: Mehul Choube Cc: dtrace-discuss at opensolaris.org Subject: Re: [dtrace-discuss] concatenate structure members into one variable On Tue, Nov 08, 2011 at 03:48:17AM -0800, Mehul Choube wrote:> Hi, > > I want the guid in a variable. I tried stringof(), strjoin(), copyinstr() but none works :( > > D script: > > ======> > #!/usr/sbin/dtrace -s > > #pragma D option quiet > > typedef struct GUID { > unsigned long Data1; > unsigned long Data2; > unsigned long Data3; > unsigned char Data4[8]; > }GUID_t; >Have you tried: pid$1::*myFunc*:entry { this->ptr = arg1; this->sptr = (GUID_t *)copyin(this->ptr, sizeof(GUID_t)); @a[*this->sptr] = count(); ^^^^^^^^^^^^^^^^^^^^^^^^^ } Cheers, - jonathan