On 6 January 2011 15:34, zhouyuan <[email protected]> wrote:
>
>
> sebb-2-2 wrote:
>>
>> On 6 January 2011 15:10, zhouyuan <[email protected]> wrote:
>>>
>>>
>>> Felix Frank-2 wrote:
>>>>
>>>> On 01/06/2011 06:43 AM, zhouyuan wrote:
>>>>>
>>>>>
>>>>> Felix Frank-2 wrote:
>>>>>>
>>>>>>> No, I'm not trying to chopping off the last three digits, I just want
>>>>>>> to
>>>>>>> get
>>>>>>> the transaction time through subtracting the 2 timestamps...but i
>>>>>>> couldn't
>>>>>>> do any operations on time1 and time2 directly. It seems that the
>>>>>>> time1
>>>>>>> and
>>>>>>> time2 are int variables by default? There are some extra lines just
>>>>>>> because
>>>>>>> I tried to debug this problem.
>>>>>>
>>>>>> The variables are untyped to BeanShell - their values are inserted
>>>>>> verbatim (as numerals) into your script.
>>>>>>
>>>>>> Your log shows a "number too large" error, hence my suggestion to drop
>>>>>> the milliseconds.
>>>>>>
>>>>>> Your computation of "long response1" should produce a valid timespan
>>>>>> in
>>>>>> milliseconds, I believe.
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [email protected]
>>>>>> For additional commands, e-mail: [email protected]
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> Hi Felix,
>>>>>
>>>>> The problem is that I can't do any computation on time2 and time1, you
>>>>> suggest me to drop milliseconds through dividing them by 1000? Or do
>>>>> some
>>>>> formatting with the time function?
>>>>> I also tried like this:
>>>>> int a=1;
>>>>> ${__log(${a},OUT)};
>>>>> int b=2;
>>>>> ${__log(${b},OUT)};
>>>>> int c=b-a;
>>>>> ${__log(${c},OUT)};
>>>>> But the console output is:
>>>>> Log: Thread Group 1-1 : ${a}
>>>>> Log: Thread Group 1-1 : ${b}
>>>>> Log: Thread Group 1-1 : ${c}
>>>>>
>>>>> Is there anything wrong with my script?
>>>>
>>>> Careful: ${a} supposes that there is a variable *on the Test Plan level*
>>>> that is named a (e.g., created by a RegexExtractor or
>>>> UserDefinedVariables).
>>>>
>>>> Before Jmeter sends your BSH Script to the interpreter, it substitutes
>>>> all occurences of ${a} by the value of this Jmeter variable.
>>>>
>>>> "int a=1" on the other hand creates a variable local to your BSH Script.
>>>> The two types of variables can't be mingled.
>>>>
>>>> To manipulate Jmeter variables, use the vars object from BSH.
>>>>
>>>> From your earlier error logs, I assume time1 and time2 are actual Jmeter
>>>> variables. To loose the milliseconds, I suggest using them as strings,
>>>> chopping 3 characters using substr() or whatever that is in BSH and then
>>>> parse it to a long value.
>>>>
>>>> HTH,
>>>> Felix
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [email protected]
>>>> For additional commands, e-mail: [email protected]
>>>>
>>>>
>>>>
>>>
>>> I tried to create UDVs first and then do the computations above, but I
>>> still
>>> can't get any output using __log function in the console. Could you give
>>> me
>>> an example that works fine in basic computations and we can also watch
>>> the
>>> variables in some way? Thanks!
>>
>> Use print() for debugging BSH scripts.
>>
>> __log is intended for use in GUI fields, not scripts.
>>
>> Use Debug Sampler + Tree View Listener for showing variables.
>>
>>> --
>>> View this message in context:
>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330545.html
>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>>
>
> Thanks! But I still don't know how to do simple computations or variable
> assignments... I tried to create variables in UDV and use them in BSH like:
> long rt=prev.getTime() but the sampler shows that rt is still empty...

As Felix already mentioned, JMeter variables are not the same as
script variables.

Please re-read the thread, and the JMeter manual, particularly:

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#BeanShell_Sampler

> And where can I find the reference about functions in BSH like prev.getTime()?

JMeter Javadoc, as mentioned at the end of

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#BeanShell_Sampler

> --
> View this message in context: 
> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330594.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to