You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by zhouyuan <yz...@microstrategy.com> on 2011/01/05 12:09:06 UTC

How to get transaction time into a user defined variable?

Hi guys,

I want to use a BeanShell Timer to get dynamical think time in transactions.
Now I'm trying to use BeanShell PreProcessor and BeanShell PostProcessor in
a transaction to get the start and end timestamp like the following:

long time2;
${__time(,time2)};
${__log(${time2},OUT)};
long response = Long.parseLong(${time2})-Long.parseLong(${time1});
long response1 = ${time2}-${time1};
${__log(${response},OUT)};
${__log(${response1},OUT)};

But it always logs an error like this:

2011/01/05 17:53:20 WARN  - jmeter.extractor.BeanShellPostProcessor: P
roblem in BeanShell script org.apache.jorphan.util.JMeterException: Error
 invoking bsh method: eval Parse error at line 2, column 1 : Error or 
number too big for integer type: 1294221200196 

How could I defined the variables in long format or is there other ways to
get transaction time and use it in a timer?

Many thanks in advance!
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3328587.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 6 January 2011 14:42, zhouyuan <yz...@microstrategy.com> wrote:
>
>
> sebb-2-2 wrote:
>>
>> On 5 January 2011 11:09, zhouyuan <yz...@microstrategy.com> wrote:
>>>
>>> Hi guys,
>>>
>>> I want to use a BeanShell Timer to get dynamical think time in
>>> transactions.
>>> Now I'm trying to use BeanShell PreProcessor and BeanShell PostProcessor
>>> in
>>> a transaction to get the start and end timestamp like the following:
>>>
>>> long time2;
>>> ${__time(,time2)};
>>> ${__log(${time2},OUT)};
>>> long response = Long.parseLong(${time2})-Long.parseLong(${time1});
>>> long response1 = ${time2}-${time1};
>>> ${__log(${response},OUT)};
>>> ${__log(${response1},OUT)};
>>>
>>> But it always logs an error like this:
>>>
>>> 2011/01/05 17:53:20 WARN  - jmeter.extractor.BeanShellPostProcessor: P
>>> roblem in BeanShell script org.apache.jorphan.util.JMeterException: Error
>>>  invoking bsh method: eval Parse error at line 2, column 1 : Error or
>>> number too big for integer type: 1294221200196
>>>
>>> How could I defined the variables in long format or is there other ways
>>> to
>>> get transaction time and use it in a timer?
>>
>> What calculation are you actually trying to perform?
>> I.e. how is the think time to be calculated?
>> What does it depend on?
>>
>> If you tell us that it might be easier to advise what approach to take.
>>
>>> Many thanks in advance!
>>> --
>>> View this message in context:
>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3328587.html
>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> I want to calculate the think time like this:
> ( Const time - Response time of each transaction ) * Random Value

OK, that should be easy to calculate.

So do you want to add the delay after each sample, based on the
response time of the sample?

Timers are applied before samplers, so what you need to do is (pseudo-code):

If PREV != null
then
    delay = (const - PREV.elapsed) * Random Value
else
    delay = 0
endif

This is easy in BSH, as JMeter provides access to the previous sample
result in in "prev" variable.

if (prev == null) {
    return 0;
} else {
    return (1234 - prev.getTime()) * Math.random();
}

(not tested, but you get the idea)
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330495.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 5 January 2011 11:09, zhouyuan <yz...@microstrategy.com> wrote:
>>
>> Hi guys,
>>
>> I want to use a BeanShell Timer to get dynamical think time in
>> transactions.
>> Now I'm trying to use BeanShell PreProcessor and BeanShell PostProcessor
>> in
>> a transaction to get the start and end timestamp like the following:
>>
>> long time2;
>> ${__time(,time2)};
>> ${__log(${time2},OUT)};
>> long response = Long.parseLong(${time2})-Long.parseLong(${time1});
>> long response1 = ${time2}-${time1};
>> ${__log(${response},OUT)};
>> ${__log(${response1},OUT)};
>>
>> But it always logs an error like this:
>>
>> 2011/01/05 17:53:20 WARN  - jmeter.extractor.BeanShellPostProcessor: P
>> roblem in BeanShell script org.apache.jorphan.util.JMeterException: Error
>>  invoking bsh method: eval Parse error at line 2, column 1 : Error or
>> number too big for integer type: 1294221200196
>>
>> How could I defined the variables in long format or is there other ways
>> to
>> get transaction time and use it in a timer?
> 
> What calculation are you actually trying to perform?
> I.e. how is the think time to be calculated?
> What does it depend on?
> 
> If you tell us that it might be easier to advise what approach to take.
> 
>> Many thanks in advance!
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3328587.html
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

I want to calculate the think time like this:
( Const time - Response time of each transaction ) * Random Value
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330495.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 5 January 2011 11:09, zhouyuan <yz...@microstrategy.com> wrote:
>
> Hi guys,
>
> I want to use a BeanShell Timer to get dynamical think time in transactions.
> Now I'm trying to use BeanShell PreProcessor and BeanShell PostProcessor in
> a transaction to get the start and end timestamp like the following:
>
> long time2;
> ${__time(,time2)};
> ${__log(${time2},OUT)};
> long response = Long.parseLong(${time2})-Long.parseLong(${time1});
> long response1 = ${time2}-${time1};
> ${__log(${response},OUT)};
> ${__log(${response1},OUT)};
>
> But it always logs an error like this:
>
> 2011/01/05 17:53:20 WARN  - jmeter.extractor.BeanShellPostProcessor: P
> roblem in BeanShell script org.apache.jorphan.util.JMeterException: Error
>  invoking bsh method: eval Parse error at line 2, column 1 : Error or
> number too big for integer type: 1294221200196
>
> How could I defined the variables in long format or is there other ways to
> get transaction time and use it in a timer?

What calculation are you actually trying to perform?
I.e. how is the think time to be calculated?
What does it depend on?

If you tell us that it might be easier to advise what approach to take.

> Many thanks in advance!
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3328587.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
Another question is, as the execution order is:

Pre-Processor 1
Timer 1
Timer 2
Sampler 1
Post-Processor 1
Post-Processor 2
Assertion 1
Pre-Processor 1
Timer 1
Timer 2
Sampler 2
Post-Processor 1
Post-Processor 2
Assertion 1

How can I use timer to control the think time between transactions rather
than samplers?  I hope to get the transaction elapse time into the
computation.
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330754.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
http://jmeter.512774.n5.nabble.com/file/n3332099/%E6%9C%AA%E6%A0%87%E9%A2%98-2.jpg 

There is still no parent sample result...
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3332099.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

zhouyuan wrote:
> 
> I also tried with: 
> pa = prev.getParent();
> print("parent:"+pa);
> 
> But the return value of parent is null...so strange...
> 

Sorry, there are some samplers have parent, I checked with:
pa = prev.getParent();
if (pa != null) {
print("parent:"+pa);
long rt1=prev.getTime();
print(rt1);
} else {
}
But they are all the last samplers in the transaction controller.
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3332179.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by Felix Frank <ff...@mpexnet.de>.
> And another question is, is every thread execute all the samplers
> sequentially? Because when a real user using a browser to access web sites,
> there will be several connections downloading elements of a web page
> concurrently. I'm wondering how to simulate this with JMeter? Thanks!

That has been discussed here a lot. In short:

Yes, Jmeter does everything sequentially. No, this is unlike any modern
browser.
The only way to bring concurrency to Jmeter ATM is to have multiple
threads do different things (which isn't usually feasible when the goal
is simple browser mimicry).

Regards,
Felix

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
I  found that the problem is there is no transaction sample result in the
prev variable, I used an BSF assertion and beanshell timer to make the
"transaction timer" that I need:

BSF Assertion:

sleep=0;
if (SampleResult.getURL() == null) {
sleep = (10000 - SampleResult.getTime()) * Math.random();
vars.put("RT", sleep.toString());
//print(sleep);
} else {
sleep = 0;
vars.put("RT", sleep.toString());
}
//print(SampleResult.getTime());
//print(SampleResult.getURL());

BeanShell Timer:

st=vars.get("RT");
t=Float.parseFloat(st);
t2=t.intValue();
print(t2);
return t2;

Is there a way that I can get the SampleResult variable in the timer
directly?

And another question is, is every thread execute all the samplers
sequentially? Because when a real user using a browser to access web sites,
there will be several connections downloading elements of a web page
concurrently. I'm wondering how to simulate this with JMeter? Thanks!
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3334971.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
I found the information in http://jakarta.apache.org/jmeter/changes.html as
belows:

Bug 41418 - Exclude timer duration from Transaction Controller runtime in
report

But it seems that it still have problems?
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3335892.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
The transaction controller is buggy?

I tried to adjust the duration for a constant timer from 100ms to 90000ms,
the response time will increase around 9s not matter i check or un-check the
flag "Include timer durations in generated sample". 

Need to manual subtract the timer duration from the results ? 
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3335864.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
I also tried with: 
pa = prev.getParent();
print("parent:"+pa);

But the return value of parent is null...so strange...
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3332173.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 7 January 2011 16:05, zhouyuan <yz...@microstrategy.com> wrote:
>
>
> Felix Frank-2 wrote:
>>
>>>> Whose child is the PostProcessor?
>>>>
>>>
>>> I add the PostProcessor as a child of the simple controller.
>>
>> I meant - before there even was a SimpleController?
>>
>> Please draw a short excerpt of your TestPlan. It *should* look like this
>> I guess
>>
>> -+ TransactionController
>> --+ Sampler
>> --+ Sampler
>> --+ ...
>> --+ PostProcessor
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> +Thread Group
> -+HTTP Cookie Manager
> -+TransactionController
> --+SimpleController
> ---+Sampler1
> ---+Sampler2
> ---+PostProcessor
>
> Is that right?

Try adding the PostProcessor as a direct child of the Transaction
Controller, or at the same level

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

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

Felix Frank-2 wrote:
> 
>>> Whose child is the PostProcessor?
>>>
>> 
>> I add the PostProcessor as a child of the simple controller.
> 
> I meant - before there even was a SimpleController?
> 
> Please draw a short excerpt of your TestPlan. It *should* look like this
> I guess
> 
> -+ TransactionController
> --+ Sampler
> --+ Sampler
> --+ ...
> --+ PostProcessor
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

+Thread Group
-+HTTP Cookie Manager
-+TransactionController
--+SimpleController
---+Sampler1
---+Sampler2
---+PostProcessor

Is that right?
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3332046.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by Felix Frank <ff...@mpexnet.de>.
>> Whose child is the PostProcessor?
>>
> 
> I add the PostProcessor as a child of the simple controller.

I meant - before there even was a SimpleController?

Please draw a short excerpt of your TestPlan. It *should* look like this
I guess

-+ TransactionController
--+ Sampler
--+ Sampler
--+ ...
--+ PostProcessor

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

Felix Frank-2 wrote:
> 
>> 
>> I try to get the previous sample result using BeanShell PostProcessor
>> like
>> this:
>> print("prev:"+prev);
>> long rt1=prev.getTime();
>> print(rt1);
>> But it only shows the sample result of nested http requests not the
>> parent
>> sample... I also tried simple controller to contain the samples in it...
>> but
>> the problem remained the same.
>> 
>> 
> 
> Whose child is the PostProcessor?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

I add the PostProcessor as a child of the simple controller.
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3332034.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by Felix Frank <ff...@mpexnet.de>.
> 
> I try to get the previous sample result using BeanShell PostProcessor like
> this:
> print("prev:"+prev);
> long rt1=prev.getTime();
> print(rt1);
> But it only shows the sample result of nested http requests not the parent
> sample... I also tried simple controller to contain the samples in it... but
> the problem remained the same.
> 
> 

Whose child is the PostProcessor?

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 7 January 2011 12:00, zhouyuan <yz...@microstrategy.com> wrote:
>>
>> Hi sebb! I tried to do it in the following way:
>>
>> import org.apache.jmeter.control.TransactionSampler;
>> import org.apache.jmeter.control.TransactionController;
>> import org.apache.jmeter.util.JMeterUtils;
>>
>> TransactionSampler ts = new TransactionSampler();
>>
>> //print(ts);
>>
>> sp = ctx.getCurrentSampler();
>>
>> print("sampler:"+sp);
>>
>> ct = JMeterUtils.getControllers(sp);
>>
>> print("controller:"+ct);
>>
>> previous = ts.getTransactionResult();
>>
>> print("haha"+previous);
>>
>> tt=previous.getTime();
>>
>> print(tt);
>>
>> But I can't the right properties of sampler... I also tried to create a
>> new
>> instance of Transaction Controller, it also doesn't work... I don't know
>> how
>> to get the results in transactions. Could you help to take a look?
>> Thanks!
> 
> Where does the Transaction Controller store its result?
> 
> http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Transaction_Controller
> 
> says:
> 
> "The Transaction Controller generates an additional sample which
> measures the overall time taken to perform the nested test elements."
> 
> So try looking at the previous sample result.
> 
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3331734.html
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

I try to get the previous sample result using BeanShell PostProcessor like
this:
print("prev:"+prev);
long rt1=prev.getTime();
print(rt1);
But it only shows the sample result of nested http requests not the parent
sample... I also tried simple controller to contain the samples in it... but
the problem remained the same.


-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3332027.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 7 January 2011 12:00, zhouyuan <yz...@microstrategy.com> wrote:
>
> Hi sebb! I tried to do it in the following way:
>
> import org.apache.jmeter.control.TransactionSampler;
> import org.apache.jmeter.control.TransactionController;
> import org.apache.jmeter.util.JMeterUtils;
>
> TransactionSampler ts = new TransactionSampler();
>
> //print(ts);
>
> sp = ctx.getCurrentSampler();
>
> print("sampler:"+sp);
>
> ct = JMeterUtils.getControllers(sp);
>
> print("controller:"+ct);
>
> previous = ts.getTransactionResult();
>
> print("haha"+previous);
>
> tt=previous.getTime();
>
> print(tt);
>
> But I can't the right properties of sampler... I also tried to create a new
> instance of Transaction Controller, it also doesn't work... I don't know how
> to get the results in transactions. Could you help to take a look? Thanks!

Where does the Transaction Controller store its result?

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

says:

"The Transaction Controller generates an additional sample which
measures the overall time taken to perform the nested test elements."

So try looking at the previous sample result.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
Hi sebb! I tried to do it in the following way:

import org.apache.jmeter.control.TransactionSampler;
import org.apache.jmeter.control.TransactionController;
import org.apache.jmeter.util.JMeterUtils;

TransactionSampler ts = new TransactionSampler();

//print(ts);

sp = ctx.getCurrentSampler();

print("sampler:"+sp);

ct = JMeterUtils.getControllers(sp);

print("controller:"+ct);

previous = ts.getTransactionResult();

print("haha"+previous);

tt=previous.getTime();

print(tt);

But I can't the right properties of sampler... I also tried to create a new
instance of Transaction Controller, it also doesn't work... I don't know how
to get the results in transactions. Could you help to take a look? Thanks!
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3331734.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
And I can't use the method through: 
import org.apache.jmeter.control.TransactionSampler;
transactionResult = TransactionSampler.getTransactionResult();

Or I should define the class first?
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3331470.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 7 January 2011 03:34, zhouyuan <yz...@microstrategy.com> wrote:
>>
>>
>> sebb-2-2 wrote:
>>>
>>> On 6 January 2011 16:40, zhouyuan <yz...@microstrategy.com> wrote:
>>>>
>>>>
>>>> sebb-2-2 wrote:
>>>>>
>>>>> On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>>>>>>
>>>>>> I find the following information in the log file:
>>>>>> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error
>>>>>> invoking
>>>>>> bsh method: eval        Sourced file: inline evaluation of: ``long
>>>>>> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis()
>>>>>> print(t
>>>>>> . . . '' : Typed variable declaration : Attempt to resolve method:
>>>>>> getTime()
>>>>>> on undefined variable or class name: prev
>>>>>> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
>>>>>> BeanShell script org.apache.jorphan.util.JMeterException: Error
>>>>>> invoking
>>>>>> bsh
>>>>>> method: eval    Sourced file: inline evaluation of: ``long
>>>>>> rt=prev.getTime();
>>>>>> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' :
>>>>>> Typed
>>>>>> variable declaration : Attempt to resolve method: getTime() on
>>>>>> undefined
>>>>>> variable or class name: prev
>>>>>
>>>>> Sorry, it looks like the BeanShellTimer does not have the 'prev'
>>>>> variable set up, unlike the BSH PostProcessor
>>>>>
>>>>> However, you can get it from the context:
>>>>>
>>>>> prev=ctx.getPreviousResult()
>>>>>
>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
>>>>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>> Thank you so much! You are my idol!!!
>>>> As it's a script variable, I can't watch it in the debug sampler, am I
>>>> right?
>>>
>>> Yes.
>>>
>>> Script variables are not automatically visible as JMeter variables,
>>> but you can use vars.put() to create or update a variable as described
>>> in the manual.
>>>
>>>> I used print to see the value of prev.getTime, and there are 2 lines
>>>> of output in the console. Which one will take effect to the BSH Timer?
>>>> And I
>>>> wonder why there are two different values of the same function.
>>>
>>> Because the Timer was called twice.
>>>
>>> Add a print("Timer here") to the script and see.
>>>
>>>> --
>>>> View this message in context:
>>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330699.html
>>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>> I wonder that is there anything like ctx.getPreviousTransactionResult()
>> to
>> get the previous transaction response time?
> 
> That's what the Javadoc is for.
> 
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3331408.html
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

It seems that there is no getTime method in TransactionSampler class... But
I can get it in the aggregate report listener...
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3331455.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 7 January 2011 03:34, zhouyuan <yz...@microstrategy.com> wrote:
>
>
> sebb-2-2 wrote:
>>
>> On 6 January 2011 16:40, zhouyuan <yz...@microstrategy.com> wrote:
>>>
>>>
>>> sebb-2-2 wrote:
>>>>
>>>> On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>>>>>
>>>>> I find the following information in the log file:
>>>>> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error
>>>>> invoking
>>>>> bsh method: eval        Sourced file: inline evaluation of: ``long
>>>>> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis()
>>>>> print(t
>>>>> . . . '' : Typed variable declaration : Attempt to resolve method:
>>>>> getTime()
>>>>> on undefined variable or class name: prev
>>>>> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
>>>>> BeanShell script org.apache.jorphan.util.JMeterException: Error
>>>>> invoking
>>>>> bsh
>>>>> method: eval    Sourced file: inline evaluation of: ``long
>>>>> rt=prev.getTime();
>>>>> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' :
>>>>> Typed
>>>>> variable declaration : Attempt to resolve method: getTime() on
>>>>> undefined
>>>>> variable or class name: prev
>>>>
>>>> Sorry, it looks like the BeanShellTimer does not have the 'prev'
>>>> variable set up, unlike the BSH PostProcessor
>>>>
>>>> However, you can get it from the context:
>>>>
>>>> prev=ctx.getPreviousResult()
>>>>
>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
>>>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>
>>> Thank you so much! You are my idol!!!
>>> As it's a script variable, I can't watch it in the debug sampler, am I
>>> right?
>>
>> Yes.
>>
>> Script variables are not automatically visible as JMeter variables,
>> but you can use vars.put() to create or update a variable as described
>> in the manual.
>>
>>> I used print to see the value of prev.getTime, and there are 2 lines
>>> of output in the console. Which one will take effect to the BSH Timer?
>>> And I
>>> wonder why there are two different values of the same function.
>>
>> Because the Timer was called twice.
>>
>> Add a print("Timer here") to the script and see.
>>
>>> --
>>> View this message in context:
>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330699.html
>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> I wonder that is there anything like ctx.getPreviousTransactionResult() to
> get the previous transaction response time?

That's what the Javadoc is for.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 6 January 2011 16:40, zhouyuan <yz...@microstrategy.com> wrote:
>>
>>
>> sebb-2-2 wrote:
>>>
>>> On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>>>>
>>>> I find the following information in the log file:
>>>> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error
>>>> invoking
>>>> bsh method: eval        Sourced file: inline evaluation of: ``long
>>>> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis()
>>>> print(t
>>>> . . . '' : Typed variable declaration : Attempt to resolve method:
>>>> getTime()
>>>> on undefined variable or class name: prev
>>>> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
>>>> BeanShell script org.apache.jorphan.util.JMeterException: Error
>>>> invoking
>>>> bsh
>>>> method: eval    Sourced file: inline evaluation of: ``long
>>>> rt=prev.getTime();
>>>> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' :
>>>> Typed
>>>> variable declaration : Attempt to resolve method: getTime() on
>>>> undefined
>>>> variable or class name: prev
>>>
>>> Sorry, it looks like the BeanShellTimer does not have the 'prev'
>>> variable set up, unlike the BSH PostProcessor
>>>
>>> However, you can get it from the context:
>>>
>>> prev=ctx.getPreviousResult()
>>>
>>>
>>>> --
>>>> View this message in context:
>>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
>>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>> Thank you so much! You are my idol!!!
>> As it's a script variable, I can't watch it in the debug sampler, am I
>> right?
> 
> Yes.
> 
> Script variables are not automatically visible as JMeter variables,
> but you can use vars.put() to create or update a variable as described
> in the manual.
> 
>> I used print to see the value of prev.getTime, and there are 2 lines
>> of output in the console. Which one will take effect to the BSH Timer?
>> And I
>> wonder why there are two different values of the same function.
> 
> Because the Timer was called twice.
> 
> Add a print("Timer here") to the script and see.
> 
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330699.html
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

I wonder that is there anything like ctx.getPreviousTransactionResult() to
get the previous transaction response time?
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3331408.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
It's very late here so I have to go to sleep.Thank you for your help! I will
try to solve the problem tomorrow.

Have a nice day!
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330776.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 6 January 2011 16:40, zhouyuan <yz...@microstrategy.com> wrote:
>>
>>
>> sebb-2-2 wrote:
>>>
>>> On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>>>>
>>>> I find the following information in the log file:
>>>> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error
>>>> invoking
>>>> bsh method: eval        Sourced file: inline evaluation of: ``long
>>>> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis()
>>>> print(t
>>>> . . . '' : Typed variable declaration : Attempt to resolve method:
>>>> getTime()
>>>> on undefined variable or class name: prev
>>>> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
>>>> BeanShell script org.apache.jorphan.util.JMeterException: Error
>>>> invoking
>>>> bsh
>>>> method: eval    Sourced file: inline evaluation of: ``long
>>>> rt=prev.getTime();
>>>> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' :
>>>> Typed
>>>> variable declaration : Attempt to resolve method: getTime() on
>>>> undefined
>>>> variable or class name: prev
>>>
>>> Sorry, it looks like the BeanShellTimer does not have the 'prev'
>>> variable set up, unlike the BSH PostProcessor
>>>
>>> However, you can get it from the context:
>>>
>>> prev=ctx.getPreviousResult()
>>>
>>>
>>>> --
>>>> View this message in context:
>>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
>>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>> Thank you so much! You are my idol!!!
>> As it's a script variable, I can't watch it in the debug sampler, am I
>> right?
> 
> Yes.
> 
> Script variables are not automatically visible as JMeter variables,
> but you can use vars.put() to create or update a variable as described
> in the manual.
> 
>> I used print to see the value of prev.getTime, and there are 2 lines
>> of output in the console. Which one will take effect to the BSH Timer?
>> And I
>> wonder why there are two different values of the same function.
> 
> Because the Timer was called twice.
> 
> Add a print("Timer here") to the script and see.
> 
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330699.html
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

I wonder why the timer was called twice? I only have one http request in the
transaction.
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330769.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 6 January 2011 16:40, zhouyuan <yz...@microstrategy.com> wrote:
>
>
> sebb-2-2 wrote:
>>
>> On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>>>
>>> I find the following information in the log file:
>>> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error
>>> invoking
>>> bsh method: eval        Sourced file: inline evaluation of: ``long
>>> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis()
>>> print(t
>>> . . . '' : Typed variable declaration : Attempt to resolve method:
>>> getTime()
>>> on undefined variable or class name: prev
>>> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
>>> BeanShell script org.apache.jorphan.util.JMeterException: Error invoking
>>> bsh
>>> method: eval    Sourced file: inline evaluation of: ``long
>>> rt=prev.getTime();
>>> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' : Typed
>>> variable declaration : Attempt to resolve method: getTime() on undefined
>>> variable or class name: prev
>>
>> Sorry, it looks like the BeanShellTimer does not have the 'prev'
>> variable set up, unlike the BSH PostProcessor
>>
>> However, you can get it from the context:
>>
>> prev=ctx.getPreviousResult()
>>
>>
>>> --
>>> View this message in context:
>>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
>>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> Thank you so much! You are my idol!!!
> As it's a script variable, I can't watch it in the debug sampler, am I
> right?

Yes.

Script variables are not automatically visible as JMeter variables,
but you can use vars.put() to create or update a variable as described
in the manual.

> I used print to see the value of prev.getTime, and there are 2 lines
> of output in the console. Which one will take effect to the BSH Timer? And I
> wonder why there are two different values of the same function.

Because the Timer was called twice.

Add a print("Timer here") to the script and see.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>>
>> I find the following information in the log file:
>> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error
>> invoking
>> bsh method: eval        Sourced file: inline evaluation of: ``long
>> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis()
>> print(t
>> . . . '' : Typed variable declaration : Attempt to resolve method:
>> getTime()
>> on undefined variable or class name: prev
>> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
>> BeanShell script org.apache.jorphan.util.JMeterException: Error invoking
>> bsh
>> method: eval    Sourced file: inline evaluation of: ``long
>> rt=prev.getTime();
>> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' : Typed
>> variable declaration : Attempt to resolve method: getTime() on undefined
>> variable or class name: prev
> 
> Sorry, it looks like the BeanShellTimer does not have the 'prev'
> variable set up, unlike the BSH PostProcessor
> 
> However, you can get it from the context:
> 
> prev=ctx.getPreviousResult()
> 
> 
>> --
>> View this message in context:
>> http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

Thank you so much! You are my idol!!!
As it's a script variable, I can't watch it in the debug sampler, am I
right? I used print to see the value of prev.getTime, and there are 2 lines
of output in the console. Which one will take effect to the BSH Timer? And I
wonder why there are two different values of the same function.
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330699.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 6 January 2011 15:42, zhouyuan <yz...@microstrategy.com> wrote:
>
> I find the following information in the log file:
> 2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error invoking
> bsh method: eval        Sourced file: inline evaluation of: ``long
> rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis() print(t
> . . . '' : Typed variable declaration : Attempt to resolve method: getTime()
> on undefined variable or class name: prev
> 2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
> BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh
> method: eval    Sourced file: inline evaluation of: ``long rt=prev.getTime();
> print(rt); Long time1=System.currentTimeMillis() print(t . . . '' : Typed
> variable declaration : Attempt to resolve method: getTime() on undefined
> variable or class name: prev

Sorry, it looks like the BeanShellTimer does not have the 'prev'
variable set up, unlike the BSH PostProcessor

However, you can get it from the context:

prev=ctx.getPreviousResult()


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

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.
I find the following information in the log file:
2011/01/06 23:36:56 ERROR - jmeter.util.BeanShellInterpreter: Error invoking
bsh method: eval	Sourced file: inline evaluation of: ``long
rt=prev.getTime(); print(rt); Long time1=System.currentTimeMillis() print(t
. . . '' : Typed variable declaration : Attempt to resolve method: getTime()
on undefined variable or class name: prev 
2011/01/06 23:36:56 WARN  - jmeter.timers.BeanShellTimer: Problem in
BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh
method: eval	Sourced file: inline evaluation of: ``long rt=prev.getTime();
print(rt); Long time1=System.currentTimeMillis() print(t . . . '' : Typed
variable declaration : Attempt to resolve method: getTime() on undefined
variable or class name: prev 
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3330602.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 6 January 2011 15:34, zhouyuan <yz...@microstrategy.com> wrote:
>
>
> sebb-2-2 wrote:
>>
>> On 6 January 2011 15:10, zhouyuan <yz...@microstrategy.com> 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: jmeter-user-unsubscribe@jakarta.apache.org
>>>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> 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: jmeter-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>
>>> 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: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> 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: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

sebb-2-2 wrote:
> 
> On 6 January 2011 15:10, zhouyuan <yz...@microstrategy.com> 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: jmeter-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>> 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: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>> 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: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

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... And
where can I find the reference about functions in BSH like prev.getTime()?
-- 
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: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by sebb <se...@gmail.com>.
On 6 January 2011 15:10, zhouyuan <yz...@microstrategy.com> 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: jmeter-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>
>>> 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: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
>
> 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: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

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: jmeter-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>>
>>>
>>>
>> 
>> 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: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

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!
-- 
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: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by Felix Frank <ff...@mpexnet.de>.
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: jmeter-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>>
> 
> 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: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

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: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

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?

Thanks,
Yuan
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3329998.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by Felix Frank <ff...@mpexnet.de>.
> 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: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by zhouyuan <yz...@microstrategy.com>.

Felix Frank-2 wrote:
> 
> On 01/05/2011 12:09 PM, zhouyuan wrote:
>> 
>> Hi guys,
>> 
>> I want to use a BeanShell Timer to get dynamical think time in
>> transactions.
>> Now I'm trying to use BeanShell PreProcessor and BeanShell PostProcessor
>> in
>> a transaction to get the start and end timestamp like the following:
>> 
>> long time2;
>> ${__time(,time2)};
>> ${__log(${time2},OUT)};
>> long response = Long.parseLong(${time2})-Long.parseLong(${time1});
>> long response1 = ${time2}-${time1};
>> ${__log(${response},OUT)};
>> ${__log(${response1},OUT)};
>> 
>> But it always logs an error like this:
>> 
>> 2011/01/05 17:53:20 WARN  - jmeter.extractor.BeanShellPostProcessor: P
>> roblem in BeanShell script org.apache.jorphan.util.JMeterException: Error
>>  invoking bsh method: eval Parse error at line 2, column 1 : Error or 
>> number too big for integer type: 1294221200196 
>> 
>> How could I defined the variables in long format or is there other ways
>> to
>> get transaction time and use it in a timer?
> 
> I cannot really see where you're going with this, but I do note that you
> are probably working with a milliseconds timestamp there. Try chopping
> off the last three digits to convert it to a seconds timestamp. That
> way, it should parse to a long just fine.
> 
> Otherwise, doesn't Java have a "long long" type? Don't ask me how to
> parse those, though.
> 
> HTH,
> Felix
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 
> 
> 

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.

Thanks,
Yuan
-- 
View this message in context: http://jmeter.512774.n5.nabble.com/How-to-get-transaction-time-into-a-user-defined-variable-tp3328587p3328614.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: How to get transaction time into a user defined variable?

Posted by Felix Frank <ff...@mpexnet.de>.
On 01/05/2011 12:09 PM, zhouyuan wrote:
> 
> Hi guys,
> 
> I want to use a BeanShell Timer to get dynamical think time in transactions.
> Now I'm trying to use BeanShell PreProcessor and BeanShell PostProcessor in
> a transaction to get the start and end timestamp like the following:
> 
> long time2;
> ${__time(,time2)};
> ${__log(${time2},OUT)};
> long response = Long.parseLong(${time2})-Long.parseLong(${time1});
> long response1 = ${time2}-${time1};
> ${__log(${response},OUT)};
> ${__log(${response1},OUT)};
> 
> But it always logs an error like this:
> 
> 2011/01/05 17:53:20 WARN  - jmeter.extractor.BeanShellPostProcessor: P
> roblem in BeanShell script org.apache.jorphan.util.JMeterException: Error
>  invoking bsh method: eval Parse error at line 2, column 1 : Error or 
> number too big for integer type: 1294221200196 
> 
> How could I defined the variables in long format or is there other ways to
> get transaction time and use it in a timer?

I cannot really see where you're going with this, but I do note that you
are probably working with a milliseconds timestamp there. Try chopping
off the last three digits to convert it to a seconds timestamp. That
way, it should parse to a long just fine.

Otherwise, doesn't Java have a "long long" type? Don't ask me how to
parse those, though.

HTH,
Felix

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org