Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 3.22 KB

File metadata and controls

62 lines (42 loc) · 3.22 KB
title Use R code profiling functions
description Improve performance and get faster results on R computations on SQL Server by using R profiling functions to return information about internal function calls.
ms.prod sql
ms.technology machine-learning
ms.date 12/12/2018
ms.topic conceptual
author dphansen
ms.author davidph
monikerRange >=sql-server-2016||>=sql-server-linux-ver15||=sqlallproducts-allversions

Use R code profiling functions to improve performance

[!INCLUDEappliesto-ss-xxxx-xxxx-xxx-md]

In addition to using SQL Server resources and tools to monitor R script execution, you can use performance tools provided by other R packages to get more information about internal function calls.

Tip

This article provides basic resources to get you started. For expert guidance, we recommend the Performance section in "Advanced R" by Hadley Wickham.

Using RPROF

rprof is a function included in the base package utils, which is loaded by default.

In general, the rprof function works by writing out the call stack to a file, at specified intervals. You can then use the summaryRprof function to process the output file. One advantage of rprof is that it performs sampling, thus lessening the performance load from monitoring.

To use R profiling in your code, you call this function and specify its parameters, including the name of the location of the log file that will be written. Profiling can be turned on and off in your code. The following syntax illustrates basic usage:

# Specify profiling output file.
varOutputFile <- "C:/TEMP/run001.log")
Rprof(varOutputFile)

# Turn off profiling
Rprof(NULL)
    
# Restart profiling
Rprof(append=TRUE)

Note

Using this function requires that Windows Perl be installed on the computer where code is run. Therefore, we recommend that you profile code during development in an R environment, and then deploy the debugged code to SQL Server.

R System Functions

The R language includes many base package functions for returning the contents of system variables. For example, as part of your R code, you might use Sys.timezone to get the current time zone, or Sys.Time to get the system time from R.

To get information about individual R system functions, type the function name as the argument to the R help() function from an R command prompt.

help("Sys.time")

Debugging and Profiling in R

The documentation for Microsoft R Open, which is installed by default, includes a manual on developing extensions for the R language that discusses profiling and debugging in detail. You can find the same documentation on your computer at C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\R_SERVICES\doc\manual.

See also