Example: lr.wasted_time and lr.get_transaction_wasted_time
The following segment demonstrates the use of timers to generate and retrieve wasted time.
int i, baseIter = 1000; long wasteTime, actualElapsedTime; //merc_timer_handle_t MasterT, timer; long mainTimer, timer; // Examine the total elapsed time of the action mainTimer = lr.start_timer(); //Start transaction lr.start_transaction("Demo"); // Create some elapsed time for the transaction for (i=0; i< (10 * baseIter); ++i) lr.output_message("This is the way we create elapsed time artificially = " + i); // Add some think time lr.think_time(0.5); // Create some wasted time and record it with timer timer = lr.start_timer(); for (i=0; i< (5 * baseIter); ++i) lr.output_message("This is the way we waste time in a script = " + i); wasteTime = lr.end_timer(timer); lr.output_message("User created waste time = " + wasteTime); lr.output_message("Before lr.wasted_time: Duration = " + lr.get_transaction_duration("Demo") + "- Waste = " + lr.get_transaction_wasted_time("Demo")); // Convert timer in seconds to wasted time in milliseconds and add to internally generated waste time */ wasteTime *= 1000; lr.wasted_time(wasteTime); lr.output_message("After lr.wasted_time: Duration = " + lr.get_transaction_duration("Demo") + "- Waste = " + lr.get_transaction_wasted_time("Demo")); lr.output_message("Think time = " + lr.get_transaction_think_time("Demo")); lr.end_transaction("Demo", lr.AUTO); actualElapsedTime = lr.end_timer(mainTimer); lr.output_message("Total Elapsed time for Action = " + actualElapsedTime);