This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
Our project uses CSS version7.4.0 under Windows. We are running JavaScript for test automation under DSS. I've tried several timestamp approaches recommended for JavaScript, and have not found one that is supported by DSS. DSS seems to not support the require function or console.log.
Has anyone been successful at adding a timestamp with millisecond resolution to DSS running JavaScript in a WIndows command prompt environment? If so, could you provide the JavaScript code you use?
You can just use the javaScript Date object:
https://www.w3schools.com/jsref/jsref_obj_date.asp
I do something like the below in my scripts:
date = new Date();
script.traceWrite("START TIME: " + date.toTimeString() + "\n");
Thomas Cox30 said:where the elapsed time between two events must be logged. The elegant way to do that would be to precede each output text line to the DSS console with a time tag of the form [HH:MM:SS:.mmm]
yes that is the ideal solution. It is supported in the xml log but not the console output.
Thomas Cox30 said:. In other words, to incorporate the time tag mechanism into traceWrite and print calls. If I were to make your two-line example a function, I would still have to find a way to execute that function after every line of text printed on the console.
Yes you would to get the current date/time each time before you printed it to the console
I was finally able to create a time tag that is pre-pended to console output that uses the print() function. I have attached the JavaScript source code.for timeStamp.js below.
// timeStamp.js - Add a time stamp prefix to output from the print() function.
// The time stamp appears in the format [13:23:05.380].
var printLog = print;
print = function () {
var first_parameter = arguments[0];
var other_parameters = Array.prototype.slice.call(arguments, 1);
function formatTimeTag (date) {
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var milliseconds = date.getMilliseconds();
return '[' +
((hour < 10) ? '0' + hour: hour) +
':' +
((minutes < 10) ? '0' + minutes: minutes) +
':' +
((seconds < 10) ? '0' + seconds: seconds) +
'.' +
('00' + milliseconds).slice(-3) +
'] ';
}
printLog.apply( print, [formatTimeTag(new Date()) + first_parameter].concat( other_parameters ));
};