README.md
1# Smartperf_Host
2## Introduction
3Smartperf_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.
4## Architecture
5![System Architecture](./figures/smartperf_frame.png)
6
7Smartperf_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.
8
9The 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).
10
11The 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.
12## Project Directory
13```
14/developtools/smartperf_host
15├── figures # Image resources
16├── ide # Smartperf_Host IDE module
17│ └── src # Profiler module
18│ │ ├── base-ui # Basic components
19│ │ └── Trace # Service logic
20├── trace_streamer # Trace Streamer module
21│ ├── base # Basic functionality
22│ ├── cfg # Configuration
23│ ├── filter # Filter
24│ ├── include # Header files
25│ ├── multi_platform # Platform adaptation
26│ ├── parser # Parsing service logic
27│ │ ├── bytrace_parser # byTrace service logic
28│ │ └── htrace_parser # hTrace service logic
29│ ├── table # Table structure
30│ ├── trace_data # Trace structure
31│ ├── trace_streamer # Trace Streamer structure
32│ └── kits # JS APIs and native APIs
33```
34## Functions
35### Loading Trace Files on Web Pages
36Load 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).
37### Capturing Traces Online
38Use 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).
39### Capturing Traces on a Device
40Capture 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).
41### Using Ability Monitor
42With 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).
43### Using Native Memory
44With 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).
45### Using Hiperf
46With 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).
47### Using HiSystemEvent
48With 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).
49### Collecting FileSystem Records
50In 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).
51### Collecting Page Fault Records
52In 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).
53### Collecting BIO Records
54In 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).
55### Collecting Smaps Records
56In 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).
57### Using SQL Analysis and Metrics
58You 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).
59## Compilation Guidance
60Project compilation includes Trace Streamer compilation and Smartperf_Host compilation and deployment.
61### Prerequisites
62- C++ version: 11 or later
63- Node.js version: 16.15.1 or later
64- npm version: 8.13.2 or later
65- TypeScript version: 4.2.3 or later
66- Go version: 1.13.8 or later
67### Compiling Trace Streamer
68To 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).
69### Compiling and Deploying Smartperf_Host
70For 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