0

For purpose of better understanding/analyzing JMeter logs I'd like to add loop count to Simple Data Writer log record. I could have an loop count variable easily, but how to add variable value to Simple Data Writer record?

E.g. in my JMeter test I have 50 users, which e.g. ramping up slowly like each 5 mins new user. And my threadgroup is configured to loop forever during test run. So I have SDW records like:

1447625139724,20,157 /Start.aspx,200,OK,Thread Group - Dashboard 50 1-1,text,true,3418,1,1,6,0,0
...
1447625158283,42,171 /Logout.aspx,200,OK,Thread Group - Dashboard 50 1-1,text,true,6814,1,1,32,0,0
1447625160283,13,157 /Start.aspx,200,OK,Thread Group - Dashboard 50 1-1,text,true,3419,1,1,4,0,0
...
...
1447625201195,1023,160 /Start.aspx,200,OK,Thread Group - Dashboard 50 1-2,text,true,24038,2,2,29,0,0
...

So at the end I have 50 threads running. And withing each thread users login - do things - logout - log back in ...

What I would like to see in log file is not only "Thread Group - Dashboard 50 1-2" but something like "Thread Group - Dashboard 50 1-2-15" where 15 would mean 15th loop for thread 2 in thread group 1.

I know I can make a counter variable and increment it e.g. each /Start call. But how do I write value of that variable with each Simple Data Writer record? That is the question!

Thank you.

user2997497
  • 159
  • 1
  • 2
  • 11
  • Also if solution is to go with creating own log file and save counter in there as described in http://stackoverflow.com/questions/26179894/how-to-save-jmeter-variables-to-csv-file Then how can I add that same file all the things that Simple Data Writer logs? So that I have more like my own logging module? – user2997497 Nov 18 '15 at 13:01

2 Answers2

1

Use JMeter's sample_variables property:

  1. Add the following line to user.properties file (located under /bin folder of your JMeter installation)

    sample_variables=counter,threadGroup,etc.
    
  2. On next JMeter restart defined variables values (if any) will be added to .jtl results file.

You can also provide this property via -J command line argument like:

jmeter -Jsample_variables=foo,bar -n -t testplan.jmx -l results.jtl

See Apache JMeter Properties Customization Guide for some extra information on the domain.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I did following: - added JMeter Counter (named it "LoopCounter") to my /Start.aspx call - added "sample_variables=LoopCounter" to user.properties restarted JMeter run test - not found in log file what I was looking for. Do I miss something? Also is it possible to somehow "decorate" wanted record in log file? So that I get e.g. ---- just to have it well distinguishing in log file. – user2997497 Nov 19 '15 at 12:19
  • It will be the last column of `results.jtl` file. – Dmitri T Nov 19 '15 at 16:31
  • Works beautifully. I set my variable name/value pairs in a JSR 223 request pre-processor that randomises some data in the request, and I log these name/value pairs using the Simple Data Writer using vars.put(name, value) in my script. This allows me to use the log details to generate reports on how different parameters affect response times, etc. Very simple solution - so thanks for that! – Morten Jorgensen Apr 21 '20 at 13:52
0

Add a beanshell element to your test, preprocessor, postprocessor or sampler, doesn't really matter and add a log line to it, to write to JMeter log.

log.info("Hello World!");

You can write values of variables and jmeter properties to log as well. You can get a lot of run time information from JMeter context

log.info(ctx.getThreadNum() + "-" + vars.get("LoopCounterVariable"));

LoopCounterVariable can be your own variable that you're updating, or you can add a JMeter counter to your test plan.

RaGe
  • 22,696
  • 11
  • 72
  • 104
  • I did following: - added JMeter Counter (named it "LoopCounter") to my /Start.aspx call - added BeanShell PostProcessor to /Start.aspx call with "log.info(ctx.getThreadNum() + "-" + vars.get("LoopCounter"));" in it. Still I don't get anything like that in log file. I assume my BeanShell isn't made correctly? – user2997497 Nov 19 '15 at 12:00
  • Log.info entries are written to `jmeter.log` in the bin folder – RaGe Nov 19 '15 at 12:16
  • Ahaaa! Yes they are there! Thank you! Is there way to get everything (like those things that SimpleDataWriter provides, I'm using CSV version of it) in 1 log file? Preferably 1 file per threadgroup? – user2997497 Nov 19 '15 at 13:39
  • Perhaps it might be possible define my "LoopCounter" in jmeter.properties file? That might be good solution. Or also change/append (in jmeter.properties) the way #jmeter.save.saveservice.thread_name=true will make the record? – user2997497 Nov 19 '15 at 13:55
  • Figured that out: added "sample_variables=LoopCounter" to jmeter.properties – user2997497 Nov 19 '15 at 14:24
  • Glad to hear it worked out for you. You should upvote answers you find useful and also mark the most helpful answer with the check mark. – RaGe Nov 19 '15 at 14:32