45
Improving the Performance of Your NI LabVIEW Applications

Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

  • Upload
    dinhque

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving the Performance of YourNI LabVIEW ApplicationsNI LabVIEW Applications

Page 2: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving Performance inLabVIEW

Purpose of Profiling MemoryPurpose ofOptimization

ProfilingTools

MemoryOptimization

Page 3: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Optimization Cycle

Optimize• Improve efficiency

Benchmark• Evaluate performance • Improve efficiency

• Improve speed• Evaluate performance•Identify problem areas

Page 4: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Why Should You Profile Your VIs?

• 80 percent of the execution time isspent in 20 percent of the code

The 80/20 rule of software performance

• Performance improvements are mosteffective in the 20 percent

• Guessing which 20 percent is difficult

spent in 20 percent of the code

Page 5: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving Performance inLabVIEW

Purpose of Profiling MemoryPurpose ofOptimization

ProfilingTools

MemoryOptimization

Page 6: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Windows Task Manager

•Gives user a rough idea ofwhether memory or CPU isthe bottleneck

•Can be helpful in•Can be helpful inidentifying memory leaks

•View»Select Columns …allows you to add additionalstats

Page 7: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Perfmon

•Allows you to monitor•Processors•Disk I/O•Network Tx/Rx•Memory/Paging•Memory/Paging

•Access by typing“perfmon” into theWindows Run dialog

Page 8: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Benchmarking Code Execution

“Timing Template (data dep)” – LabVIEW Shipping Example

Page 9: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Benchmarking Code Execution

Code

Calibration

Analysis

“Benchmark Project” – LabVIEW Real-Time Shipping Example

Page 10: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

VI Profiler• Timing and memory statistics for VIs

•Tools»Profile»Performance and Memory …

Page 11: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Demo – VI ProfilingDemo – VI Profiling

Page 12: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

LabVIEW Desktop Execution TraceToolkit

Threads, CPUMultiple

Sessions

• Detailedexecutiontraces

• Thread and VIinformation

Threads, CPU

and Memory

VIs

Sessions• Measurement

of executiontime

Page 13: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Benchmarking Summary

OS Level

• Task Manager, Perfmon

LabVIEW LevelLabVIEW Level

• VI Profiler, Benchmark VIs

VI Level

• LabVIEW Desktop Execution Trace Toolkit

Page 14: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving Performance inLabVIEW

Purpose of Profiling MemoryPurpose ofOptimization

ProfilingTools

MemoryOptimization

Page 15: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

VI Components

• Panel

• Diagram

• Code

– Diagram compiled into machine code– Diagram compiled into machine code

• Data

– Control/indicator values

– Default data

– Block diagram constant data

Page 16: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

VIs in Memory

• When a VI is loaded into memory

– We always load the data

– We load the code if it matches our platform(x86 Windows, x86 Linux, x86 Mac, PowerPC Mac)(x86 Windows, x86 Linux, x86 Mac, PowerPC Mac)

– We load the panel and diagram only if we need to(for instance, we need to recompile the VI)

Page 17: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Panel and Diagram Data• Front panel controls and indicators need their own

copy of the data to display, called “operate data”

• This VI uses about 8 KB of data if the panel is open,and about 4 KB otherwise

Page 18: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

LabVIEW Terminology

• Panel data is called “Operate Data”

– Controls and indicators have their own copy of thedata, so that front panel editing of data does notinterfere with computations in the diagraminterfere with computations in the diagram

• Diagram data is called “Execution Data”

– Every wire represents a buffer of data

• “Transfer Data” is used to copy between them

– Avoids multithreading issues

Page 19: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Memory Performance

• The following features affect the impactmemory allocation has on your application:

– Wire Semantics and “In Placeness”

– Type coercion– Type coercion

– Passing values to subVIs

– Shift registers

– Front panel indicators

Page 20: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Wire Semantics• Every wire is a buffer

• Branches typically create copies

Page 21: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Optimizations by LabVIEW

The theoretical 5 copies become 1 copy operation

Copy

Output is “in place” with input

Page 22: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

The “In Place” Algorithm

• Determines when a copy needs to be made

– Weighs arrays and clusters higher than othertypes

• Algorithm runs before execution• Algorithm runs before execution

– Does not know the size of an array or cluster

• Relies on the sequential aspects of theprogram

– Branches may require copies

Page 23: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Bottom Up

In-place information is propagated bottom up

Branched wire

Increments array in place

Copy becauseof increment No copies required

Page 24: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Showing Buffer Allocations

Page 25: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Allows you to explicitly modify data “in place”

The In-Place Element Structure

Page 26: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Types of Border Nodes

• Array index/replace element

• Array split/replace subarray

• Unbundle/bundle

• Waveform unbundle/bundle• Waveform unbundle/bundle

• Variant to/from G data

• Simple “in place” relationship

• Data value referenceread/write

Page 27: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Operate on each element of an array of waveforms

Example of In Place Optimization

Page 28: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Make the First SubVI “In Place”

changes into…

Page 29: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

SubVI 2 Is Made “In Place”

Changes into …Changes into …

Page 30: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

SubVI 3 Is Made “In Place”

Changes into …

Page 31: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Final Result: Dots Are Hidden

Page 32: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Type Coercion

• Changing the data type of a wire to matchthe required data type

– Dots indicate automatic coercion

– Requires a copy– Requires a copyCoercion Dot

Page 33: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Passing Values to SubVIs

• SubVI does not always have to make a copy

• Best when …

– Inputs are required

– Inputs and outputs are not in structures– Inputs and outputs are not in structures

– Inputs and outputs are “in place”

Page 34: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Passing Values to SubVIs• Parameters within structures cause

unnecessary copies

MoveMove

Page 35: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Shift Registers• Single left input always in place with right

output

– Even better when the body is in place

In Place

Always In Place

In Place

Page 36: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Building Arrays

There are a number of ways to build arraysand some are better than others

BadBad

•Reallocates array memory onevery loop iteration

•No compile time optimization

Page 37: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Building Arrays

There are a number of ways to build arraysand some are better than others

Better

Keep graphicsbelow the textand to the right.

Better

•Memory allocated at load time

•Values populated “in place”

Page 38: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Building Arrays

There are a number of ways to build arraysand some are better than others

BestBest

•Memory preallocated

•Indexing tunnel eliminatesneed for copies

Page 39: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Build Array Ordering

• Appending to the end of an array is muchmore efficient than prepending to themore efficient than prepending to thebeginning

• If you need to insert items at the beginning,insert at the end instead and use a singleReverse Array when finished

Page 40: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Demo – Effects of MemoryOptimization

Demo – Effects of MemoryOptimization

Page 41: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving Performance inLabVIEW

Purpose ofOptimization

Profiling ToolsMemory

Optimization

• Decrease memory usage, increase speed• 80/20 Rule

Page 42: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving Performance inLabVIEW

Purpose ofOptimization

Profiling ToolsMemory

Optimization

• Windows Tools (Task Manager, perfmon)• VI Profiler• Real-Time Execution Trace Toolkit

Page 43: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Improving Performance inLabVIEW

Purpose ofOptimization

Profiling ToolsMemory

Optimization

• Hide the dots• Take advantage of “in placeness”

Page 44: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Next Steps

• LabVIEW Help

In LabVIEW

• ni.com/multicore

• ni.com/devzone

On the Web

Page 45: Improving the Performance of Your NI LabVIEW … · LabVIEW Desktop Execution Trace Toolkit Threads, CPU Multiple Sessions • Detailed execution traces • Thread and VI information

Next Steps

• Visit ni.com/training

• Identify your current expertise level anddesired level

• Register for appropriate courses• Register for appropriate courses