Appending timestamp in Filename

270 views
Skip to first unread message

bluedust

unread,
May 2, 2012, 12:59:16 PM5/2/12
to LoadRunner
Hey all,

I am new to loadrunner. Just into it i have a query of how to append a
timestamp to a filename..

the situation is like,..
i am planning to write the particular contents into a file, the path
is something like..E:\\Siebel\\filename.txt
now that i want a timestamp in between that filename i.e. E:\\Siebel\
\filename_02/05/2012_2226.txt

i have tried it using strcat function but all in vain..

Thanks,

Arun

Ashish Tyagi

unread,
May 2, 2012, 11:47:55 PM5/2/12
to LR-Loa...@googlegroups.com
Can be done using C functions. Please refer to function reference.

Harish

unread,
May 2, 2012, 10:21:24 PM5/2/12
to lr-loa...@googlegroups.com
You can create Date/Time parameter for appending timestamp.But I guess
we cannot create a file with characters like '/'.instead use something
like this '02May2012'

Thanks

Sent from my iPhone
> --
> You received this message because you are subscribed to the Google
> "LoadRunner" group.
> To post to this group, send email to LR-Loa...@googlegroups.com
> To unsubscribe from this group, send email to
> LR-LoadRunne...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/LR-LoadRunner?hl=en

Kevyland

unread,
May 3, 2012, 10:48:33 AM5/3/12
to LoadRunner
Slam Dunk!
First did you look at the time functions in the LR functions help.
The answer is quite apparent and is resolved in a few minutes of
research.
In LR Function help search time and read the example for localtime

Action()
{

typedef long time_t;
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
#ifdef LINUX
int tm_gmtoff;
const char *tm_zone;
#endif
};


time_t t;
struct tm *now;
char filename[128];

_tzset(); /* Sets variables used by localtime */
time(&t);

/* Convert to time structure and adjust for PM if necessary */
now = (struct tm *)localtime(&t);


/* Use strftime to build a customized time string */
strftime(filename, 128, "filename_%Y-%m-%d.txt", now);

lr_message(filename);

return 0;
}

The code will output the string filename_yyyy_mm_dd.txt

I could add some James Pulley wisdom about learning basic programming,
doing research, searching this forum's history, and checking LR help
files.

Prasenjit Dutta

unread,
May 4, 2012, 6:48:09 AM5/4/12
to lr-loa...@googlegroups.com
were these many lines were written to get the file format in "filename_yyyy_mm_dd.txt" ?? then I would say it is not required.... you could have done it in better way.....

--
You received this message because you are subscribed to the Google "LoadRunner" group.
To post to this group, send email to LR-Loa...@googlegroups.com
To unsubscribe from this group, send email to
LR-LoadRunne...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/LR-LoadRunner?hl=en



--
Prasenjit

André Luyer

unread,
May 6, 2012, 9:11:17 AM5/6/12
to LoadRunner
Do NOT write to file unless there is absolutely no other option.
Otherwise you will be load-testing the I/O rate of the load generator.
Try storing the contents in a LR parameter instead.

The easiest way would be to use a datetime parameter or the function
lr_save_datetime (which are basically a wrapper around the strftime
function).
Use the setlocale function once to make a datetime parameter,
lr_save_datetime, asctime, ctime and strftime operate in the language
of your choosing (like %A) instead of the locale of the OS on the load
generator / Vugen.

For standard C functions (those without a '_') it is better to
reference sites dedicated to the C/C++ language, such as www.cplusplus.com,
because the "HP LoadRunner Online Function Reference" is for standard
C functions often incomplete and sometimes incorrect.
( http://www.cplusplus.com/reference/clibrary/ctime/strftime/ )

@Kevyland: don't duplicate constants, use the operator sizeof instead.

Note: if you must write to a file then put the fopen in vuser_init and
fclose in vuser_end. This will help to keep the I/O overhead low.

André

Kevyland

unread,
May 7, 2012, 10:19:00 AM5/7/12
to LoadRunner
Not sure why I'm being criticized for using the LR sample supplied in
their help. I took the cheap 10 minute approach to coding the
solution to problem by first looking at the LoadRunner Function
Library Help.

Remember the issue? The problem stated: " i am planning to write the
particular contents into a file, the path
is something like..E:\\Siebel\\filename.txt now that i want a
timestamp in between that filename i.e. E:\\Siebel\
\filename_02/05/2012_2226.txt "

Did I not provide a solution that works in LR?

BTW: I dont think my LoadRunner C engine is C++, its ANSI C to the
best of my knowledge and yes lr_save_datetime is a better solution.
Can someone show bluedust the example using the api call?

Reply all
Reply to author
Forward
0 new messages