Overview
LabWindows/CVI 執行分析 (Execution Profiler) 工具組為獨立應用程式,可擷取 LabWindows/CVI 應用的執行資料。工具組將透過 Profile Viewer 顯示資料,讓使用者可開啟、瀏覽,並分析所記錄的資料。使用相關資料進行除錯,並加快 LabWindows/CVI 應用的執行速度。
Table of Contents
介紹
C 程式設計語言可提供初階的控制功能,讓使用者最佳化應用的執行時間效能。C 工程師往往耗費大量時間分析原始碼,以估算執行速度並進行修改,才能最佳化應用並達最佳效能。LabWindows/CVI 2009 具備 LabWindows/CVI 執行分析 (Execution Profiler) 工具組,可提升產能並加快分析作業,以最佳化 LabWindows/CVI 應用的效能。
LabWindows/CVI 執行分析 (Execution Profiler) 工具組概述
LabWindows/CVI 執行分析 (Execution Profiler) 工具組為獨立應用程式,可擷取 LabWindows/CVI 應用的執行資料。工具組將透過 Profile Viewer 顯示資料,讓使用者可開啟、瀏覽,並分析所記錄的資料。再使用相關資料進行除錯,並加快 LabWindows/CVI 應用的執行速度。
透過 LabWindows/CVI 中的「Build Options」對話框,啟動 LabWindows/CVI 的分析功能,並可使用 Utility Library 中的 CVIProfSetCurrentThreadProfiling 函式。當設定 1 組應用要進行分析時,LabWindows/CVI 將建立內含分析資訊的「.cvip」檔案,可輕鬆檢視整理/排序過的檔案,或於 Profile Viewer 中呼叫樹狀格式。
使用 LabWindows/CVI 執行分析 (Execution Profiler) 工具組
啟動執行分析功能
使用 CVIProfSetCurrentThreadProfiling 函式,針對應用中的各組執行緒設定分析功能,並可從「Build Options」對話框中的 Profiling 選出下列選項之一:
- User functions - 僅分析使用者定義的函式。使用者於來源檔案中定義的函式。
- User functions and other calls - 分析使用者定義的函式,還有其他所有函式的呼叫。舉例來說,其他函式的呼叫可能包含 LabWindows/CVI 函式、Win32 API 函式,與其他函式的呼叫。這些呼叫均將於 Profile Viewer 中淡化顯示。
LabWindows/CVI 將於執行時間建立「.cvip」檔案,其中的分析資訊可於 Profile Viewer 中進行分析。
載入執行分析檔
針對於執行時間所建立的執行分析資訊,則有 3 個分析選項可供檢視:
- 在設定 Profiler Settings 對話框中的選項之後,只要啟動 Launch Viewer 即可 Automatically launch (自動開啟) Profile Viewer 並載入「.cvip」檔案。只要於 Profile Viewer 中點選 Options » Profiler Settings,即可開啟 Profiler Settings 對話框。 in the .
- 於 Profile Viewer 中點選 File » Open,即可 Open the .cvip file (開啟 .cvip 檔案) 並進行分析。
- 將「.cvip」檔案 Drag and drop (拖曳) 至 Profile Viewer 中。

分析執行分析檔
將「.cvip」檔案載入至 Profile Viewer 之後,即可選擇 3 種檢視模式:
- Flattened - 此種檢視模式,將顯示程式中所有已分析函式的時序資訊。而透過 Flattened View 可迅速找出執行時間最長的函式。
- Threaded - 此檢視模式將依呼叫執行緒的先後排列分析函式,並顯示時序資訊。透過 Threaded View,可找出耗費最多時間執行各組執行緒的函式。在單一執行緒的應用中,Profile Viewer 將不會顯示 Threaded View 分頁。Threaded View 中的根階層 (Root-level) 函式,將對應至各組執行緒中的「Entry-point」函式。若根階層函式可呼叫其他任何函式,則不論執行緒的程式碼路徑為何,所呼叫的函式將以縮寫呈現於根階層函式之下。
注意:Threaded View 模式僅可用於多執行緒的應用中。 - Call Tree - 根據所分析的呼叫分支 (Call branch),此檢視模式將顯示時序資訊。Call Tree View 可了解特定程式碼路徑的執行狀況。當於此檢視模式中選擇函式之後,Profile Viewer 將以單一元件 (Component) 為基礎而顯示條狀圖 (Bar plot) 資訊。單一元件包含母函式 (Parent function) 及其直屬 (Immediate) 子函式 的分析時間。若函式可同時為母子函式,則包含元件的條狀圖亦將納入其子函式,而非包含其母函式的元件。
更多資源
體驗 LabWindows/CVI 執行分析 (Execution Profiler) 工具組
訂閱 LabWindows/CVI 開發新聞報
此份季刊將提供最新線上教學、使用秘訣,還有可能的產業趨勢。
加入 LabWindows/CVI 社群
此線上社群可張貼文章、分享意見、學習概念,並聯繫全世界的 LabWindows/CVI 使用者。
LabWindows 商標為 Microsoft 公司授權使用。Windows 為 Micorsoft 微軟公司於美國與其他國家的註冊商標。
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
