1fb726d48Sopenharmony_ci# Smartperf_Host 2fb726d48Sopenharmony_ci## Introduction 3fb726d48Sopenharmony_ciSmartperf_Host is an intuitive performance and power optimization tool that offers in-depth data mining and fine-grained data visualization. With this tool, you can gain visibility into a multitude of metrics in terms of CPU scheduling, frequency, process and thread time slices, heap memory, frame rate, and more, in swimlanes. Better yet, you can analyze the collected data intuitively on the GUI. 4fb726d48Sopenharmony_ci## Architecture 5fb726d48Sopenharmony_ci 6fb726d48Sopenharmony_ci 7fb726d48Sopenharmony_ciSmartperf_Host consists of the device end and PC end, which exchange data with each other based on gRPC – a high-performance remote procedure call (RPC) framework. 8fb726d48Sopenharmony_ci 9fb726d48Sopenharmony_ciThe device end consists of modules such as Native Hook (application-embedded component), hiprofiler_command (command-line tool), hiprofilerd (performance profiler service), a set of performance profiler plug-ins, and some system tools and kernels. The device end provides the plug-in extension capability by exposing plug-in interfaces for external systems. By drawing on this capability, you can integrate custom plug-ins into the framework. For details about the preset plug-ins, see [Performance Profiler Component](https://gitee.com/openharmony/developtools_profiler). 10fb726d48Sopenharmony_ci 11fb726d48Sopenharmony_ciThe PC end is accessible from the Smartperf_Host website. It consists of modules such as Trace Streamer, SQLite, HDC device management, data import, UI drawing, and data analysis. 12fb726d48Sopenharmony_ci## Project Directory 13fb726d48Sopenharmony_ci``` 14fb726d48Sopenharmony_ci/developtools/smartperf_host 15fb726d48Sopenharmony_ci├── figures # Image resources 16fb726d48Sopenharmony_ci├── ide # Smartperf_Host IDE module 17fb726d48Sopenharmony_ci│ └── src # Profiler module 18fb726d48Sopenharmony_ci│ │ ├── base-ui # Basic components 19fb726d48Sopenharmony_ci│ │ └── Trace # Service logic 20fb726d48Sopenharmony_ci├── trace_streamer # Trace Streamer module 21fb726d48Sopenharmony_ci│ ├── base # Basic functionality 22fb726d48Sopenharmony_ci│ ├── cfg # Configuration 23fb726d48Sopenharmony_ci│ ├── filter # Filter 24fb726d48Sopenharmony_ci│ ├── include # Header files 25fb726d48Sopenharmony_ci│ ├── multi_platform # Platform adaptation 26fb726d48Sopenharmony_ci│ ├── parser # Parsing service logic 27fb726d48Sopenharmony_ci│ │ ├── bytrace_parser # byTrace service logic 28fb726d48Sopenharmony_ci│ │ └── htrace_parser # hTrace service logic 29fb726d48Sopenharmony_ci│ ├── table # Table structure 30fb726d48Sopenharmony_ci│ ├── trace_data # Trace structure 31fb726d48Sopenharmony_ci│ ├── trace_streamer # Trace Streamer structure 32fb726d48Sopenharmony_ci│ └── kits # JS APIs and native APIs 33fb726d48Sopenharmony_ci``` 34fb726d48Sopenharmony_ci## Functions 35fb726d48Sopenharmony_ci### Loading Trace Files on Web Pages 36fb726d48Sopenharmony_ciLoad local trace files (such as htrace and ftrace) and display the data in swimlanes. For details, see [Loading Trace Files on Web Pages](./ide/src/doc/md/quickstart_systemtrace.md). 37fb726d48Sopenharmony_ci### Capturing Traces Online 38fb726d48Sopenharmony_ciUse Smartperf_Host to capture traces online, with the content, duration, and save path all customizable. For details, see [Capturing Traces on Web Pages](./ide/src/doc/md/quickstart_web_record.md). 39fb726d48Sopenharmony_ci### Capturing Traces on a Device 40fb726d48Sopenharmony_ciCapture traces on the target device, with the content, duration, and save path all customizable. For details, see [Capturing Traces from a Device](./ide/src/doc/md/quickstart_device_record.md). 41fb726d48Sopenharmony_ci### Using Ability Monitor 42fb726d48Sopenharmony_ciWith Ability Monitor in Smartperf_Host, you can learn the CPU, memory, disk I/O, and network usage of your application. For details, see [Ability Monitor Usage](./ide/src/doc/md/quickstart_ability_monitor.md). 43fb726d48Sopenharmony_ci### Using Native Memory 44fb726d48Sopenharmony_ciWith Native Memory in Smartperf_Host, you can track the allocation and release of your application's native memory (specific to C and C++). For details, see [Native Memory Usage](./ide/src/doc/md/quickstart_native_memory.md). 45fb726d48Sopenharmony_ci### Using Hiperf 46fb726d48Sopenharmony_ciWith Hiperf in Smartperf_Host, you can view the CPU usage of your application and the call stack. For details, see [Hiperf Usage](./ide/src/doc/md/quickstart_hiperf.md). 47fb726d48Sopenharmony_ci### Using HiSystemEvent 48fb726d48Sopenharmony_ciWith HiSystemEvent in Smartperf_Host, you can inspect the power consumption of each category (CPU, network, and location, and more) of your application, resource application and usage records (WorkScheduler, Runninglock, Alarm, and Location Request), power consumption exceptions, and system states associated with the power consumption (battery level and screen status). For details, see [HiSystemEvent Usage](./ide/src/doc/md/quickstart_hisystemevent.md). 49fb726d48Sopenharmony_ci### Collecting FileSystem Records 50fb726d48Sopenharmony_ciIn Smartperf_Host, you can find out the system invoking information and read/write invoking times of all file systems. For details, see [Usage of FileSystem Recording](./ide/src/doc/md/quickstart_filesystem.md). 51fb726d48Sopenharmony_ci### Collecting Page Fault Records 52fb726d48Sopenharmony_ciIn Smartperf_Host, you can collect page fault records, covering various aspects such as start time, duration, triggering process, triggering thread, event type, memory address, and memory size of page memory events. For details, see [Usage of Page Fault Recording](./ide/src/doc/md/quickstart_page_fault.md). 53fb726d48Sopenharmony_ci### Collecting BIO Records 54fb726d48Sopenharmony_ciIn Smartperf_Host, you can collect I/O operation records, which provide the following information: start time, total latency, process, average latency of every 4 KB data, thread, operation (write data, page swap-in, and metadata), access traffic, path, block number, priority, and backtrace call stack. For details, see [Usage of BIO Latency Recording](./ide/src/doc/md/quickstart_bio.md). 55fb726d48Sopenharmony_ci### Collecting Smaps Records 56fb726d48Sopenharmony_ciIn Smartperf_Host, you can collect the smaps data (type, Pss, Rss, Vss, and more) on a process-by-process basis. The data source is **/proc/$pid/smaps**. For details, see [Smaps Usage](./ide/src/doc/md/quickstart_smaps.md). 57fb726d48Sopenharmony_ci### Using SQL Analysis and Metrics 58fb726d48Sopenharmony_ciYou can Query (SQL) and Metrics features to quickly locate the trace data. For details, see [SQL Analysis and Metrics Usage](./ide/src/doc/md/quickstart_sql_metrics.md). 59fb726d48Sopenharmony_ci## Compilation Guidance 60fb726d48Sopenharmony_ciProject compilation includes Trace Streamer compilation and Smartperf_Host compilation and deployment. 61fb726d48Sopenharmony_ci### Prerequisites 62fb726d48Sopenharmony_ci- C++ version: 11 or later 63fb726d48Sopenharmony_ci- Node.js version: 16.15.1 or later 64fb726d48Sopenharmony_ci- npm version: 8.13.2 or later 65fb726d48Sopenharmony_ci- TypeScript version: 4.2.3 or later 66fb726d48Sopenharmony_ci- Go version: 1.13.8 or later 67fb726d48Sopenharmony_ci### Compiling Trace Streamer 68fb726d48Sopenharmony_ciTo set up the Smartperf_Host website, you need to compile the WASM version of Trace Streamer for the web page to parse the original trace data. For details about the compilation process, see [Compiling Trace Streamer](./trace_streamer/doc/compile_trace_streamer.md). 69fb726d48Sopenharmony_ci### Compiling and Deploying Smartperf_Host 70fb726d48Sopenharmony_ciFor details about the compilation and deployment process, see [SmartPerf Compilation and Deployment Guide](./ide/README_zh.md). After successful deployment, you can start to use Smartperf_Host by visiting **https://[*IP address of the device where SmartPerf is deployed*]:9000/application/**. 71