Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-05 Thread Michael Schuster, Oracle

On 04.05.10 21:13, Yossi Lev wrote:

No, this-entry-pc is not a user-space pointer --- it is not a pointer at all, 
it is an unsigned integer that I would like to convert to a string.

Here is what I'm trying to do:

- I have a structure of type ReadAcqEntry at userspace with various
   numeric fields (unsigned long long type).

- I would like to convert a few of these fields to a string (e.g. for
   the purpose of concatenating it with other strings), and use the
   numerical value of the others.

What I was doing so far is copying the whole structure with:

   this-entry = 
(ReadAcqEntry*)copyin((uintptr_t)(this-rAcqArr[this-numEntries-1]) , 
sizeof(ReadAcqEntry));

so now this-entry points to the local copy of the structure.  Now I can
access all of the structure's fields as integers (I tested this part and
it works fine), but I am not sure how I can convert some of the fields
to strings.  What I really need is the equivalent of sprintf or itoa...

It seems like stringof requires a pointer, so I am not sure that this is
what I need to use here.


no, you don't, regular printf will work:

printf(%d, somenumber);

stringof(p) returns string pointer to character array(p) (strings and 
character arrays are not the same in DTrace), but it does not do the 
integer-string conversion you're looking for.


I can't think of a way of doing the exact equivalent of sprintf(s, %d, 
number) and then continue using 's' within your D script. what do you need 
a string for here that the numbers themselves won't solve?


Michael
--
Michael SchusterOracle
Recursion, n.: see 'Recursion'
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-05 Thread Yossi Lev
Hi Michael

I just found a function that (sort of) does what I need: it is called lltostr 
and it takes a long long integer, and returns a string that represents it.  
(Unfortunately I didn't find an option to do the translation in hexadecimal, 
but I can live with that...)

 As for your question, I need to use the numbers as a key to an aggregation, 
but I need to concatenate a few of those.  In particular, I have a sequence of 
N numbers where N  9, and I need to count how many times I'm getting each 
sequence.  The value of N may be different in separate invocations of the probe 
function, so I would like to use an unrolled loop to concatenate the N numbers 
to single string representing the sequence, and then use the string as the key 
to my aggregation.  

Do you see any other option but to use the lltostr function to and concatenate 
the resulted strings?

Thanks,
Yossi
-- 
This message posted from opensolaris.org
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-05 Thread Michael Schuster

On 05.05.10 18:11, Yossi Lev wrote:

Hi Michael

I just found a function that (sort of) does what I need: it is called lltostr 
and it takes a long long integer, and returns a string that represents it.  
(Unfortunately I didn't find an option to do the translation in hexadecimal, 
but I can live with that...)

  As for your question, I need to use the numbers as a key to an aggregation, but 
I need to concatenate a few of those.  In particular, I have a sequence of N 
numbers where N  9, and I need to count how many times I'm getting each 
sequence.  The value of N may be different in separate invocations of the probe 
function, so I would like to use an unrolled loop to concatenate the N numbers to 
single string representing the sequence, and then use the string as the key to my 
aggregation.

Do you see any other option but to use the lltostr function to and concatenate 
the resulted strings?


does this answer your question:

$ pfexec dtrace -n 'syscall:::ent...@c[execname,pid] = count()}'
dtrace: description 'syscall:::entry' matched 227 probes

look closely at the [...] part :-)

HTH
Michael
--
michael.schus...@oracle.com http://blogs.sun.com/recursion
Recursion, n.: see 'Recursion'
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-05 Thread Nicolas Williams
On Wed, May 05, 2010 at 09:11:27AM -0700, Yossi Lev wrote:
 I just found a function that (sort of) does what I need: it is called
 lltostr and it takes a long long integer, and returns a string that
 represents it.  (Unfortunately I didn't find an option to do the
 translation in hexadecimal, but I can live with that...)
 
  As for your question, I need to use the numbers as a key to an
  aggregation, but I need to concatenate a few of those.  In
  particular, I have a sequence of N numbers where N  9, and I need to
  count how many times I'm getting each sequence.  The value of N may
  be different in separate invocations of the probe function, so I
  would like to use an unrolled loop to concatenate the N numbers to
  single string representing the sequence, and then use the string as
  the key to my aggregation.  
 
 Do you see any other option but to use the lltostr function to and
 concatenate the resulted strings?

Yes: aggregations take multiple keys, not just one, so rather than
format a string with all the key content that you need: use a comma-
separated list of expressions of various types as the key.  See:

http://docs.sun.com/app/docs/doc/819-5488/gcggh?a=view

Nico
-- 
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-05 Thread Yossi Lev
Thanks, I know that I can provide multiple keys, but the number of keys for an 
aggregation must be constant, and I didn't want to pad with zeros all missing 
keys as in the common case my sequence has 2 or 3 keys (and not the maximum 
number of 8).  These are minor issues that have to do with how the data looks 
when it is printed at the end --- I'm trying to use DTrace to generate a 
performance profiling report that the users can read, so do not want to add 
many trailing zeros to everything.

I guess I could store the information on different aggregations depending on 
the number of keys that I get, but an integer--string translation results in a 
much simpler/cleaner script, which is why I posted this message asking whether 
there is a function that does it.

Thanks for all the help!
Yossi
-- 
This message posted from opensolaris.org
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-05 Thread Michael Schuster

On 05.05.10 18:40, Yossi Lev wrote:

Thanks, I know that I can provide multiple keys, but the number of keys
for an aggregation must be constant, and I didn't want to pad with zeros
all missing keys as in the common case my sequence has 2 or 3 keys (and
not the maximum number of 8).  These are minor issues that have to do
with how the data looks when it is printed at the end --- I'm trying to
use DTrace to generate a performance profiling report that the users can
read, so do not want to add many trailing zeros to everything.


you may want to consider post-processing with your favourite string 
manipulation tool for the looks of your output.


Michael
--
michael.schus...@oracle.com http://blogs.sun.com/recursion
Recursion, n.: see 'Recursion'
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-04 Thread Chad Mynhier
On Tue, May 4, 2010 at 11:23 AM, Yossi Lev yosef@sun.com wrote:
 Hi

 I'm running a simple DTrace script that has the following clause:

 pid$target::ReportTx:entry
 /arg1 != 0  this-numEntries != 0/
 {
  printf(NumEntries: %lld\n, (long long)this-numEntries);
  this-entry = 
 (ReadAcqEntry*)copyin((uintptr_t)(this-rAcqArr[this-numEntries-1]),
                                      sizeof(ReadAcqEntry));

  this-pcInt = (uintptr_t)(this-entry-pc);
  this-instr = stringof(this-pcInt);
 /* �...@acqtotals[this-instr] = sum(this-entry-acqNum);*/

  this-numEntries--;
 }



What is this-rAcqArr in the code above?  Did you mean this to be a
thread-local variable instead of a clause-local variable?  Is it
possible that you're getting garbage because that array hasn't
persisted from where you initialized it?

Chad
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-04 Thread Yossi Lev
Thanks Chad, but I don't think that this is the problem.  The this-rAcqArr 
points to the beginning of an array in the traced process.  I initialize it in 
a previous clause that has exactly the same probe:

pid$target::ReportTx:entry
/arg1 != 0 /
{
  this-dataP = (ProfData*)copyin(arg2, sizeof(ProfData));
  this-numEntries = this-dataP-numRAcqEntries;
  this-rAcqArr = this-dataP-racqInfoArr;
}

So the value of this-rAcqArr should be live until all clauses with the same 
probe are done executing.

Moreover, I know that the value that I'm getting is valid, because I had the 
following printf statement:

pid$target::ReportTx:entry
/arg1 != 0  this-numEntries != 0/
{
  printf(NumEntries: %lld\n, (long long)this-numEntries);
  this-entry = 
(ReadAcqEntry*)copyin((uintptr_t)(this-rAcqArr[this-numEntries-1]),
  sizeof(ReadAcqEntry));

  this-pcInt = (uintptr_t)(this-entry-pc);
/*  this-instr = stringof(this-pcInt);*/

  printf(%p\t%d\t%d\t%d\n,
 this-entry-pc,
 this-entry-acqNum,
 this-entry-upgradeNum + this-entry-contUpgradeNum,
 this-entry-contUpgradeNum);
  this-numEntries--;
}

and the results look fine.  The only problem is when I un-comment the stringof 
statement.

I even tried using this-entry-pc as a key to an aggregation, with no 
problems.  I only encountered the problem when I tried to convert it to a 
string.

So, I can printf this-entry-pc (with %p flag), I can use it as a key to an 
aggregation, but I cannot convert it to a string --- any idea why?

As an aside, I noticed that the invalid address specified in the error message 
is different that the value of this-entry-pc.

Thanks again,
Yossi
-- 
This message posted from opensolaris.org
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-04 Thread Yossi Lev
I have some more information, that suggests that something is just wrong with 
the way I'm using stringof.  I tried replacing stringof(this-pcInt) with 
stringof(5) and still got the error.

So, I tried the following one-liner from the shell:

dtrace -n 'BEGIN{printf(%s\n,stringof(0x5));}'
dtrace: description 'BEGIN' matched 1 probe
dtrace: error on enabled probe ID 1 (ID 1: dtrace:::BEGIN): invalid address 
(0x0) in action #1

Note that all the script does is convert 0x5 to a string and print it... any 
ideas?

Thanks,
Yossi
-- 
This message posted from opensolaris.org
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org


Re: [dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string

2010-05-04 Thread Chad Mynhier
On Tue, May 4, 2010 at 12:58 PM, Yossi Lev yosef@sun.com wrote:

 Moreover, I know that the value that I'm getting is valid, because I had the 
 following printf statement:

 pid$target::ReportTx:entry
 /arg1 != 0  this-numEntries != 0/
 {
  printf(NumEntries: %lld\n, (long long)this-numEntries);
  this-entry = 
 (ReadAcqEntry*)copyin((uintptr_t)(this-rAcqArr[this-numEntries-1]),
                                      sizeof(ReadAcqEntry));

  this-pcInt = (uintptr_t)(this-entry-pc);
 /*  this-instr = stringof(this-pcInt);*/

  printf(%p\t%d\t%d\t%d\n,
         this-entry-pc,
         this-entry-acqNum,
         this-entry-upgradeNum + this-entry-contUpgradeNum,
         this-entry-contUpgradeNum);
  this-numEntries--;
 }

 and the results look fine.  The only problem is when I un-comment the 
 stringof statement.

So this-entry-ps is a userspace pointer?  If that's the case, then
you want copyinstr(), not stringof().

Chad
___
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org