Java Reference
In-Depth Information
Listing 13-4. The Contents of the NashornProfile.txt File
0 dyn:getProp|getElem|getMethod:Math 438462 2
1 dyn:getMethod|getProp|getElem:floor 433936 2
2 dyn:call 650602 2
3 dyn:getProp|getElem|getMethod:Math 313834 1
4 dyn:getMethod|getProp|getElem:sqrt 283356 1
5 dyn:call 0 1
Listing 13-5 contains the Java program that sets the nashorn.debug system
property and runs the script shown in Listing 13-3. Running the program will create a
NashornProfile.txt file in the current directory, and the contents of the file will be the
same as shown in Listing 13-2.
Listing 13-5. Setting the nashorn.debug System Property and Profiling Scripts
// ProfilerTest.java
package com.jdojo.script;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class ProfilerTest {
public static void main(String[] args) {
// Set the nashorn.debug system property, so the tracing and
// profiling directives will be recognized
System.setProperty("nashorn.debug", "true");
// Construct the script file path
String scriptFileName = "primeprofiler.js";
Path scriptPath = Paths.get(scriptFileName);
// Make sure the script file exists. If not, print the full
// path of the script file and terminate the program.
if (!Files.exists(scriptPath)) {
System.out.println(scriptPath.toAbsolutePath() +
"does not exist.");
return;
}
Search WWH ::




Custom Search