Debugging and profiling in R

Similar documents
Debugging R code. by Marek Rychlik February 28, 2009

Computing and compilers

6.828: OS/Language Co-design. Adam Belay

Advances in Memory Management and Symbol Lookup in pqr

Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way.

Eliminate Threading Errors to Improve Program Stability

Full file at

Chapter 2: Operating-System Structures. Operating System Concepts Essentials 8 th Edition

Chapter 2: Operating-System Structures

Chapter 2: Operating-System

Chapter 2. Operating-System Structures

Introduction to Parallel Performance Engineering

Supplement: Visual C++ Debugging

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

OPERATING SYSTEMS. Goals of the Course. This lecture will cover: This Lecture will also cover:

Processes and Threads

Chapter 2: Operating-System Structures

Debugging and Profiling

Chapter 2: Operating-System Structures

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

Integrated Software Environment. Part 2

Chapter 2: System Structures

Often, more information is required when designing system call Information varies according to OS and types of system call

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

CS 11 C track: lecture 6

Chapter 2: Operating-System Structures

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Pointers II. Class 31

Lecture 2 Operating System Structures (chapter 2)

Outline. Program development cycle. Algorithms development and representation. Examples.

Software Exorcism: A Handbook for Debugging and Optimizing Legacy Code

Chapter 2: System Structures. Operating System Concepts 9 th Edition

CSE 4/521 Introduction to Operating Systems

Chapter 2: Operating-System Structures

Chapter 2: Operating-System Structures. Chapter 2: Operating-System Structures. Objectives. Operating System Services

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Lecture # 1. SPIM & MIPS Programming

Introduction to Hive. Feng Li School of Statistics and Mathematics Central University of Finance and Economics

Eliminate Threading Errors to Improve Program Stability

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

An Introduction to Python (TEJ3M & TEJ4M)

ECE QNX Real-time Lab

TraceBack: First Fault Diagnosis by Reconstruction of Distributed Control Flow

SPIM & MIPS Programming

Operating System Services. User Services. System Operation Services. User Operating System Interface - CLI. A View of Operating System Services

Debugging with gdb and valgrind

ZAP Cross Debuggers for STMicroelectronics Microcontrollers

CS307: Operating Systems

HPCC - Hrothgar. Getting Started User Guide TotalView. High Performance Computing Center Texas Tech University

Virtual Memory. 11/8/16 (election day) Vote!

Yaffs Tuning. Charles Manning

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Unit 2 : Computer and Operating System Structure

An Introduction to Komodo

System Assertions. Your Submissions. Oral Exams FEBRUARY FEBRUARY FEBRUARY

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

An Introduction to Tilde

This guide will show you how to use Intel Inspector XE to identify and fix resource leak errors in your programs before they start causing problems.

Run-Time Data Structures

Exploring the file system. Johan Montelius HT2016

Buffer Manager: Project 1 Assignment

HOT-Compilation: Garbage Collection

The Operating System. Chapter 6

Advanced Programming & C++ Language

Programming II (CS300)

TREX Set-Up Guide: Creating a TREX Executable File for Windows

Testing Exceptions with Enforcer

Heapy a memory profiler and debugger for Python

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

Subject : Computer Science. Paper : Software Quality Management. Module : CASE Tools

Debugging in LISP. trace causes a trace to be printed for a function when it is called

Lab 3-2: Exploring the Heap

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Short Introduction to tools on the Cray XC system. Making it easier to port and optimise apps on the Cray XC30

Cache Profiling with Callgrind

Efficient and Large Scale Program Flow Tracing in Linux. Alexander Shishkin, Intel

Seminar report Java Submitted in partial fulfillment of the requirement for the award of degree Of CSE

Class #509 The Heisenberg Principal of Debugging

Reliable programming

Unit E Step-by-Step: Programming with Python

CS143 Final Spring 2016

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Exceptions and Design

Simple Garbage Collection and Fast Allocation Andrew W. Appel

Reading and manipulating files

Operating-System Structures

Dynamic Storage Allocation

OPERATING SYSTEMS. Prescribed Text Book Operating System Principles, Seventh Edition By Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

O B J E C T L E V E L T E S T I N G

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

Recursion. Chapter 7

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Debugging with TotalView

Operating-System Structures

Programming II (CS300)

Software Carpentry. Nicola Chiapolini. Physik-Institut University of Zurich. June 16, 2015

Intro to Segmentation Fault Handling in Linux. By Khanh Ngo-Duy

A function that invokes itself is said to

Transcription:

Debugging and profiling in R Feng Li feng.li@cufe.edu.cn School of Statistics and Mathematics Central University of Finance and Economics June 12, 2014 Revision: June 12, 2014

The basic concepts of debugging Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected. A debugger or debugging tool is a computer program that is used to test and debug other programs (the target program) Debugging involves numerous aspects including interactive debugging, control flow, integration testing, log files, monitoring (application, system), memory dumps, profiling, Statistical Process Control, and special design tactics to improve detection while simplifying changes. Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 2 / 8

Typical debugging process Normally the first step in debugging is to attempt to reproduce the problem. After the bug is reproduced, the input of the program may need to be simplified to make it easier to debug After the test case is sufficiently simplified, a programmer can use a debugger tool to examine program states (values of variables, plus the call stack) and track down the origin of the problem(s). Alternatively, tracing can be used Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 3 / 8

Debugging tools in R The simplest version: cat(); print() browser() At the browser prompt the user can enter commands or R expressions, followed by a newline. The commands are c (or just an empty line, by default) exit the browser and continue execution at the next statement. n enter the step-through debugger if the function is interpreted. This changes the meaning of c : see the documentation for debug. For byte compiled functions n is equivalent to c. where print a stack trace of all active function calls. Q exit the browser and the current evaluation and return to the top-level prompt. > options(browsernldisabled = TRUE) trace() traceback() if control flow ls() try() trycatch() Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 4 / 8

Why profiling? Find the computational bottom-neck of your code. Fine the memory bottom-neck of your code. Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 5 / 8

Profiling R code for speed Check computing time of a piece of code: proc.time(). Profiling works by recording at fixed intervals (by default every 20 msecs) which line in which R function is being used, and recording the results in a file. The R profiling procedure Rprof("myprofile.out") # Open the profile log file ##... ## Some code you want to profile ## Rprof(NULL) # Close the profile log summaryrprof("myprofile.out") # summarize the results Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 6 / 8

Profiling R code for memory use I Measuring memory use in R code is useful either when the code takes more memory than is conveniently available or when memory allocation and copying of objects is responsible for slow code. Garbage collection: gc() >gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 311043 16.7 597831 32.0 597831 32.0 Vcells 761909 5.9 1445757 11.1 1137162 8.7 Vcells used to store the contents of vectors Ncells used to store everything else, including all the administrative overhead for vectors such as type and length information. In fact the vector contents are divided into two pools. The sampling profiler Rprof described in the previous section can be given the option memory.profiling=true. Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 7 / 8

Profiling R code for memory use II Rprof("myprofile.out", memory.profiling=true) # Open the profile ##... ## Some code you want to profile ## Rprof(NULL) # Close the profile log summaryrprof("myprofile.out") # summarize the results Memory profiling requires R to have been compiled with --enable-memory-profiling, which is not the default, but is currently used for the OS X and Windows binary distributions. Feng Li (Stat & Math, CUFE) Statistical Computing June 12, 2014 8 / 8