Defined by the Mobile Industry Processor Interface \(MIPI\) Alliance, the Camera Serial Interface \(CSI\) is a specification that allows data to be transmitted from the camera to the host processor on mobile platforms. In the Hardware Driver Foundation \(HDF\), the MIPI CSI module uses the service-free mode for API adaptation. The service-free mode applies to the devices that do not provide user-mode APIs or the OS that does not distinguish the user mode and the kernel mode. In the service-free mode, DevHandle \(a void pointer\) directly points to the kernel-mode address of the device object.
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p155578927170128"><aname="p155578927170128"></a><aname="p155578927170128"></a><strongid="b2983104693117"><aname="b2983104693117"></a><aname="b2983104693117"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p534134719170128"><aname="p534134719170128"></a><aname="p534134719170128"></a><strongid="b717683263220"><aname="b717683263220"></a><aname="b717683263220"></a>pAttr</strong>: structure pointer to the configuration structure of the MIPI CSI.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry1104973652170128p0"><aname="entry1104973652170128p0"></a><aname="entry1104973652170128p0"></a>Sets the MIPI-CSI configuration.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p548503413170128"><aname="p548503413170128"></a><aname="p548503413170128"></a><strongid="b33316314348"><aname="b33316314348"></a><aname="b33316314348"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p1389106408170128"><aname="p1389106408170128"></a><aname="p1389106408170128"></a><strongid="b7288183093611"><aname="b7288183093611"></a><aname="b7288183093611"></a>devno</strong>: Device ID, which is of the uint8_t type.</p>
<pid="p118314402170128"><aname="p118314402170128"></a><aname="p118314402170128"></a><strongid="b1347113393714"><aname="b1347113393714"></a><aname="b1347113393714"></a>cmvMode</strong>: common-mode voltage (CMV) mode.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry1506663070170128p0"><aname="entry1506663070170128p0"></a><aname="entry1506663070170128p0"></a>Sets the CMV mode.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p114389566170128"><aname="p114389566170128"></a><aname="p114389566170128"></a><strongid="b34053117344"><aname="b34053117344"></a><aname="b34053117344"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p996608377170128"><aname="p996608377170128"></a><aname="p996608377170128"></a><strongid="b784685684412"><aname="b784685684412"></a><aname="b784685684412"></a>dataType</strong>: structure pointer to the data that defines the YUV, original data formats, and bit depth.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry1309676064170128p0"><aname="entry1309676064170128p0"></a><aname="entry1309676064170128p0"></a>Sets the YUV, RAW data format, and bit depth.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1054266120170128"><aname="p1054266120170128"></a><aname="p1054266120170128"></a><strongid="b144183117349"><aname="b144183117349"></a><aname="b144183117349"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p1574674418170128"><aname="p1574674418170128"></a><aname="p1574674418170128"></a><strongid="b18748194155516"><aname="b18748194155516"></a><aname="b18748194155516"></a>laneDivideMode</strong>: lane mode.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry1643965522170128p0"><aname="entry1643965522170128p0"></a><aname="entry1643965522170128p0"></a>Sets the MIPI RX lane distribution.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p867235167170128"><aname="p867235167170128"></a><aname="p867235167170128"></a><strongid="b94263116342"><aname="b94263116342"></a><aname="b94263116342"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p1770663973170128"><aname="p1770663973170128"></a><aname="p1770663973170128"></a><strongid="b1342116531004"><aname="b1342116531004"></a><aname="b1342116531004"></a>comboDev</strong>: channel ID, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry373275246170128p0"><aname="entry373275246170128p0"></a><aname="entry373275246170128p0"></a>Enables the MIPI clock.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p252627163170128"><aname="p252627163170128"></a><aname="p252627163170128"></a><strongid="b343103114343"><aname="b343103114343"></a><aname="b343103114343"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p573650189170128"><aname="p573650189170128"></a><aname="p573650189170128"></a><strongid="b1747970172618"><aname="b1747970172618"></a><aname="b1747970172618"></a>comboDev</strong>: channel ID, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry693552037170128p0"><aname="entry693552037170128p0"></a><aname="entry693552037170128p0"></a>Disables the MIPI clock.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1214231503170128"><aname="p1214231503170128"></a><aname="p1214231503170128"></a><strongid="b1043031153417"><aname="b1043031153417"></a><aname="b1043031153417"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p104793304170128"><aname="p104793304170128"></a><aname="p104793304170128"></a><strongid="b597920533269"><aname="b597920533269"></a><aname="b597920533269"></a>comboDev</strong>: channel ID, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry1692819512170128p0"><aname="entry1692819512170128p0"></a><aname="entry1692819512170128p0"></a>Resets the MIPI RX.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1883220887170128"><aname="p1883220887170128"></a><aname="p1883220887170128"></a><strongid="b1202156153016"><aname="b1202156153016"></a><aname="b1202156153016"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p114324757170128"><aname="p114324757170128"></a><aname="p114324757170128"></a><strongid="b105520153110"><aname="b105520153110"></a><aname="b105520153110"></a>comboDev</strong>: channel ID, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry1714667992170128p0"><aname="entry1714667992170128p0"></a><aname="entry1714667992170128p0"></a>Deasserts the reset of the MIPI RX.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p217879421170128"><aname="p217879421170128"></a><aname="p217879421170128"></a><strongid="b197181237203211"><aname="b197181237203211"></a><aname="b197181237203211"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p2098908158170128"><aname="p2098908158170128"></a><aname="p2098908158170128"></a><strongid="b12861154993218"><aname="b12861154993218"></a><aname="b12861154993218"></a>snsClkSource</strong>: number of the clock signal cable of the sensor, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1996780281170128"><aname="p1996780281170128"></a><aname="p1996780281170128"></a><strongid="b4445316347"><aname="b4445316347"></a><aname="b4445316347"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p2021170726170128"><aname="p2021170726170128"></a><aname="p2021170726170128"></a><strongid="b17971423820"><aname="b17971423820"></a><aname="b17971423820"></a>snsClkSource</strong>: number of the clock signal cable of the sensor, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p1065048089170128"><aname="p1065048089170128"></a><aname="p1065048089170128"></a><strongid="b19451631183417"><aname="b19451631183417"></a><aname="b19451631183417"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p998202090170128"><aname="p998202090170128"></a><aname="p998202090170128"></a><strongid="b10443111911384"><aname="b10443111911384"></a><aname="b10443111911384"></a>snsClkSource</strong>: number of the clock signal cable of the sensor, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry944835652170128p0"><aname="entry944835652170128p0"></a><aname="entry944835652170128p0"></a>Resets the sensor.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.2 "><pid="p416483731170128"><aname="p416483731170128"></a><aname="p416483731170128"></a><strongid="b178488417385"><aname="b178488417385"></a><aname="b178488417385"></a>cntlr</strong>: structure pointer to the MIPI CSI controller.</p>
<pid="p1988272362170128"><aname="p1988272362170128"></a><aname="p1988272362170128"></a><strongid="b6353246183818"><aname="b6353246183818"></a><aname="b6353246183818"></a>snsClkSource</strong>: number of the clock signal cable of the sensor, which is of the uint8_t type.</p>
<tdclass="cellrowborder"valign="top"width="20%"headers="mcps1.2.6.1.5 "><pid="entry791107803170128p0"><aname="entry791107803170128p0"></a><aname="entry791107803170128p0"></a>Deasserts the reset of a sensor.</p>
</td>
</tr>
</tbody>
</table>
## How to Develop<a name="section378858277170128"></a>
The MIPI CSI module adaptation involves the following steps:
1. Instantiate the driver entry.
- Instantiate the **HdfDriverEntry** structure.
- Call **HDF\_INIT** to register the **HdfDriverEntry** instance with the HDF.
2. Configure attribute files.
- Add the **deviceNode** information to the **device\_info.hcs** file.
-\(Optional\) Add the **mipicsi\_config.hcs** file.
3. Instantiate the MIPI CSI controller object.
- Initialize **MipiCsiCntlr**.
- Instantiate **MipiCsiCntlrMethod** in the **MipiCsiCntlr** object.
>For details, see [Available APIs](#section735525713405).
4. Debug the driver.
-\(Optional\) For new drivers, verify basic functions, for example, verify the information returned after the connect operation and whether data is successfully transmitted.
## Development Example<a name="section2049027816170128"></a>
The following uses **mipi\_rx\_hi35xx.c** as an example to present the contents that need to be provided by the vendor to implement device functions.
1. Generally, you need to configure the device attributes in **busxx\_config.hcs** and add the **deviceNode** information to the **device\_info.hcs** file. The device attribute values are closely related to the default values or value range of the **MipiCsiCntlr** members at the core layer. The **deviceNode** information is related to the driver entry registration.
>In this example, the MIPI controller attributes are defined in the source file. If required, add the **deviceMatchAttr** information to **deviceNode** in the **device\_info** file and add the** mipicsi\_config.hcs** file.
**device\_info.hcs** configuration reference:
```
root {
device_info {
match_attr = "hdf_manager";
platform :: host {
hostName = "platform_host";
priority = 50;
device_mipi_csi:: device {
device0 :: deviceNode {
policy = 0;
priority = 160;
permission = 0644;
moduleName = "HDF_MIPI_RX"; // (Mandatory) Driver name, which must be the same as the moduleName in the driver entry.
serviceName = "HDF_MIPI_RX";// (Mandatory) Unique name of the service published by the driver.
}
}
}
}
}
```
2. Instantiate the driver entry. The driver entry must be a global variable of the **HdfDriverEntry** type \(defined in **hdf\_device\_desc.h**\), and the value of **moduleName** must be the same as that in **device\_info.hcs**. The function pointer members of the **HdfDriverEntry** structure are filled by the vendors' operation functions. In the HDF, the start address of each **HdfDriverEntry** object of all loaded drivers is collected to form a segment address space similar to an array for the upper layer to invoke.
Generally, the HDF calls the **Bind** function and then the **Init** function to load a driver. If **Init** fails to be called, the HDF calls **Release** to release driver resources and exit.
MIPI CSI driver entry reference:
```
struct HdfDriverEntry g_mipiCsiDriverEntry = {
.moduleVersion = 1,
.Init = Hi35xxMipiCsiInit, // See the Init function.
.Release = Hi35xxMipiCsiRelease, //See the Release function.
.moduleName = "HDF_MIPI_RX", // (Mandatory) The value must be the same as that in the device_info.hcs file.
};
HDF_INIT(g_mipiCsiDriverEntry); // Call HDF_INIT to register the driver entry with the HDF.
```
3. Initialize the **MipiCsiCntlr** object at the core layer, including initializing the vendor custom structure \(passing parameters and data\), instantiating **MipiCsiCntlrMethod**\(used to call underlying functions of the driver\) in **MipiCsiCntlr**, and implementing the **HdfDriverEntry** member functions \(**Bind**, **Init**, and **Release**\).
>To the driver, the custom structure carries parameters and data. The values in the **config** file are used to initialize the structure members. In this example, the MIPI CSI attributes are defined in the source file. Therefore, the basic member structure is similar to that of **MipiCsiCntlr**.
```
typedef struct {
/** Data type: 8-bit, 10-bit, 12-bit, 14-bit, or 16-bit */
DataType inputDataType;
/** MIPI WDM mode */
MipiWdrMode wdrMode;
/** laneId: -1 - disabled */
short laneId[MIPI_LANE_NUM];
union {
/** Used for HI_MIPI_WDR_MODE_DT */
short dataType[WDR_VC_NUM];
};
} MipiDevAttr;
typedef struct {
/** Device number. */
uint8_t devno;
/** Input mode, which can be MIPI, LVDS, sub-LVDS, HiSPi, or DC. */
InputMode inputMode;
MipiDataRate dataRate;
/** Crop area of the MIPI RX device (same as the size of the input image of the sensor). */
ImgRect imgRect;
union {
MipiDevAttr mipiAttr;
LvdsDevAttr lvdsAttr;
};
} ComboDevAttr;
// MipiCsiCntlr is the core layer controller structure. Its members are assigned with values by using the Init function.
struct MipiCsiCntlr {
/** Send the service provided by this controller when the driver is bound to the HDF. */
struct IDeviceIoService service;
/** Pass the pointer to the device when the driver is bound to the HDF. */
struct HdfDeviceObject *device;
/** Device number */
unsigned int devNo;
/** All APIs provided by the controller */
struct MipiCsiCntlrMethod *ops;
/** All APIs for controller debugging. Set it to null if the driver is not implemented. */
struct MipiCsiCntlrDebugMethod *debugs;
/** Controller context variable. */
MipiDevCtx ctx;
/** Spinlock used when the controller context variable is accessed. */
OsalSpinlock ctxLock;
/** Lock method when the controller is managed */
struct OsalMutex lock;
/** Pointer to anonymous data, which is used to store the CSI device structure */
void *priv;
};
```
- **\(Important\)** Instantiate the callback function structure **MipiCsiCntlrMethod** in **MipiCsiCntlr**. Other members are initialized by using the **Init** function.
```
static struct MipiCsiCntlrMethod g_method = {
.setComboDevAttr = Hi35xxSetComboDevAttr,
.setPhyCmvmode = Hi35xxSetPhyCmvmode,
.setExtDataType = Hi35xxSetExtDataType,
.setHsMode = Hi35xxSetHsMode,
.enableClock = Hi35xxEnableClock,
.disableClock = Hi35xxDisableClock,
.resetRx = Hi35xxResetRx,
.unresetRx = Hi35xxUnresetRx,
.enableSensorClock = Hi35xxEnableSensorClock,
.disableSensorClock = Hi35xxDisableSensorClock,
.resetSensor = Hi35xxResetSensor,
.unresetSensor = Hi35xxUnresetSensor
};
```
- Init function
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
HDF\_STATUS \(The following table lists some status. For details about other status, see **HDF\_STATUS** in the **/drivers/framework/include/utils/hdf\_base.h** file.\)
g_mipiCsi.priv = NULL; // g_mipiTx is a global variable defined.
//static struct MipiCsiCntlr g_mipiCsi = {
//.devNo = 0
//};
g_mipiCsi.ops = &g_method; // Connect to the MipiCsiCntlrMethod instance.
#ifdef CONFIG_HI_PROC_SHOW_SUPPORT
g_mipiCsi.debugs = &g_debugMethod;
#endif
ret = MipiCsiRegisterCntlr(&g_mipiCsi, device); // (Mandatory) Call the function at the core layer and g_mipiTx to initialize global variables at the core layer.
cntlr->device = device; // Enable conversion between HdfDeviceObject and MipiCsiHandle.
device->service = &(cntlr->service); // Enable conversion between HdfDeviceObject and MipiCsiHandle.
cntlr->priv = NULL;
HDF_LOGI("%s: success.", __func__);
return HDF_SUCCESS;
}
HDF_LOGE("%s: cntlr already exists.", __func__);
return HDF_FAILURE;
}
```
- Release function
Input parameters:
**HdfDeviceObject**, an interface parameter exposed by the driver, contains the .hcs configuration file information.
Return values:
–
Function description:
Releases the memory and deletes the controller. This function assigns a value to the **Release** API in the driver entry structure. When the HDF fails to call the **Init** function to initialize the driver, the **Release** function can be called to release driver resources. All forced conversion operations for obtaining the corresponding object can be successful only when the **Init** function has the corresponding value assignment operations.
hiperf is a performance sampling and analysis tool provided for developers. It extends the user-mode capabilities based on the kernel perf mechanism and can conduct performance sampling of the specified application or the entire system.
You can run the **hiperf -h** command to display the commands supported by hiperf.
The following describes the common commands \(**list**, **stat**, **record**, and **report**\) supported by hiperf.
## list<a name="section121805449461"></a>
### Parameters<a name="section42124492494"></a>
The **list** command lists all the perf events supported by the device. The event names are used for the **-e** and **-g** parameters of the **stat** and **record** commands.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p343715244814"><aname="p343715244814"></a><aname="p343715244814"></a>Lists the hardware events supported by the performance monitoring unit (PMU).</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p84377213482"><aname="p84377213482"></a><aname="p84377213482"></a>Lists the cache events supported by the PMU.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p44372274819"><aname="p44372274819"></a><aname="p44372274819"></a>Lists the raw PMU events supported.</p>
</td>
</tr>
</tbody>
</table>
### Example<a name="section122129443486"></a>
List the hardware events supported by the PMU. The command also lists the events that are not supported by the PMU.
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p36451134216"><aname="p36451134216"></a><aname="p36451134216"></a>Collects the values of all threads and default performance counters of the system.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p147074321111"><aname="p147074321111"></a><aname="p147074321111"></a>Specifies the IDs of the CPUs to monitor. Use commas (,) to separate multiple CPU IDs, for example <strongid="b88710447518"><aname="b88710447518"></a><aname="b88710447518"></a>0,1,2</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p117073321117"><aname="p117073321117"></a><aname="p117073321117"></a>Specifies the monitoring period, in seconds.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p13707173261112"><aname="p13707173261112"></a><aname="p13707173261112"></a>Specifies the interval for printing the monitored events, in milliseconds.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p16443201119320"><aname="p16443201119320"></a><aname="p16443201119320"></a>Specifies the events to monitor. You can run the <strongid="b9161172815551"><aname="b9161172815551"></a><aname="b9161172815551"></a>list</strong> command to list all the events supported. <strongid="b111611225613"><aname="b111611225613"></a><aname="b111611225613"></a>event:u</strong> indicates an event in the user space, and <strongid="b2282748195610"><aname="b2282748195610"></a><aname="b2282748195610"></a>event:k</strong> indicates an event in the kernel space.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p20870204817311"><aname="p20870204817311"></a><aname="p20870204817311"></a>Specifies a group of events to monitor. The events in the same group are monitored by the same PMU.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p13323958634"><aname="p13323958634"></a><aname="p13323958634"></a>Leaves the sub-threads of the target thread or process not monitored.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p1270803261116"><aname="p1270803261116"></a><aname="p1270803261116"></a>Specifies the process IDs (PIDs) to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p47081632101118"><aname="p47081632101118"></a><aname="p47081632101118"></a>Specifies the thread IDs (TIDs) to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50.06%"headers="mcps1.1.3.1.2 "><pid="p137083323111"><aname="p137083323111"></a><aname="p137083323111"></a>Displays detailed report, including raw time data.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p47259563126"><aname="p47259563126"></a><aname="p47259563126"></a>Indicates the times that an event occurred.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p10725756151210"><aname="p10725756151210"></a><aname="p10725756151210"></a>Indicates the event name. You can run the <strongid="b1275144172219"><aname="b1275144172219"></a><aname="b1275144172219"></a>list</strong> command to list all the supported events. <strongid="b146319013236"><aname="b146319013236"></a><aname="b146319013236"></a>hw</strong> stands for hardware, and <strongid="b21781210132315"><aname="b21781210132315"></a><aname="b21781210132315"></a>sw</strong> stands for software.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p972514566125"><aname="p972514566125"></a><aname="p972514566125"></a>Provides values calculated from those in the <strongid="b3976203310251"><aname="b3976203310251"></a><aname="b3976203310251"></a>Count</strong> column for easy understanding. For example, the CPU frequency (<strongid="b17911439162616"><aname="b17911439162616"></a><aname="b17911439162616"></a>hw-cpu-cycles</strong>) is converted to <strongid="b415132419274"><aname="b415132419274"></a><aname="b415132419274"></a>0.832068</strong> GHz from <strongid="b1471832922712"><aname="b1471832922712"></a><aname="b1471832922712"></a>6994768</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p3725105621211"><aname="p3725105621211"></a><aname="p3725105621211"></a>Indicates the percentage of PMU resources occupied by the event. The number of events to be monitored by a PMU varies depending on the number of PMUs.</p>
</td>
</tr>
</tbody>
</table>
## record<a name="section168751927524"></a>
### Parameters<a name="section113617912522"></a>
The **record** command samples the specified application and saves the sampling data to a file \(**perf.data** by default\).
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p835041795311"><aname="p835041795311"></a><aname="p835041795311"></a>Samples all processes and threads in the system.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p2035071717539"><aname="p2035071717539"></a><aname="p2035071717539"></a>Leaves the hiperf process not sampled.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p8350117145310"><aname="p8350117145310"></a><aname="p8350117145310"></a>Specifies the IDs of the CPUs to sample.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p0350171719531"><aname="p0350171719531"></a><aname="p0350171719531"></a>Specifies the maximum percentage of CPU resources occupied by the sampling.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p73502017145313"><aname="p73502017145313"></a><aname="p73502017145313"></a>Specifies the sampling duration, in seconds.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p144811511083"><aname="p144811511083"></a><aname="p144811511083"></a>Specifies how often a sampling event is triggered. The default value is 4000 times/second.</p>
<pid="p1035001711532"><aname="p1035001711532"></a><aname="p1035001711532"></a>Note: A higher value indicates heavier CPU load but more sampling data.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p5350131725316"><aname="p5350131725316"></a><aname="p5350131725316"></a>Specifies the number of occurrence times of an event that triggers a sampling. That is, a sampling is performed once when the event occurs the specified number of times.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p20351171713531"><aname="p20351171713531"></a><aname="p20351171713531"></a>Specifies the events to monitor. You can run the <strongid="b176932255522"><aname="b176932255522"></a><aname="b176932255522"></a>list</strong> command to list all the events supported. <strongid="b2693625205220"><aname="b2693625205220"></a><aname="b2693625205220"></a>event:u</strong> indicates an event in the user space, and <strongid="b14693225145212"><aname="b14693225145212"></a><aname="b14693225145212"></a>event:k</strong> indicates an event in the kernel space.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p335181718535"><aname="p335181718535"></a><aname="p335181718535"></a>Specifies a group of events to monitor. The events in the same group are monitored by the same PMU.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p17351121712533"><aname="p17351121712533"></a><aname="p17351121712533"></a>Leaves the sub-threads of the target thread or process not monitored.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p535119176531"><aname="p535119176531"></a><aname="p535119176531"></a>Specifies the processes to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1735111716534"><aname="p1735111716534"></a><aname="p1735111716534"></a>Specifies the threads to monitor.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p23511017135310"><aname="p23511017135310"></a><aname="p23511017135310"></a>Monitors the CPU scheduling event, which is equivalent to the <strongid="b83471327125516"><aname="b83471327125516"></a><aname="b83471327125516"></a>--period 1 -e sched:sched_switch</strong> event.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p15351217125317"><aname="p15351217125317"></a><aname="p15351217125317"></a>Monitors the branch prediction events. Branch prediction tries to predict the next instruction to be executed if there are multiple <strongid="b1515010251521"><aname="b1515010251521"></a><aname="b1515010251521"></a>if else</strong> conditions.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p14351111735316"><aname="p14351111735316"></a><aname="p14351111735316"></a>Sets the user stack unwinding mode, which can be <strongid="b99242538156"><aname="b99242538156"></a><aname="b99242538156"></a>fp</strong> or <strongid="b18703165914151"><aname="b18703165914151"></a><aname="b18703165914151"></a>dwarf</strong>. If <strongid="b293334361618"><aname="b293334361618"></a><aname="b293334361618"></a>dwarf</strong> is used, you can specify the size of the user stack to be sampled. The default value is <strongid="b162942143188"><aname="b162942143188"></a><aname="b162942143188"></a>65528</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1135112171532"><aname="p1135112171532"></a><aname="p1135112171532"></a>Delays the stack unwinding till the sampling is complete.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p17351717115317"><aname="p17351717115317"></a><aname="p17351717115317"></a>Disables stack unwinding. The user register and stack data is stored in <strongid="b628502918229"><aname="b628502918229"></a><aname="b628502918229"></a>perf.data</strong> for offline stack unwinding.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p335171745314"><aname="p335171745314"></a><aname="p335171745314"></a>Disables the unwound call stack information from being combined or extended.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p7351717115312"><aname="p7351717115312"></a><aname="p7351717115312"></a>Sets the clock source for the sampling data. The options are <strongid="b11324454271"><aname="b11324454271"></a><aname="b11324454271"></a>monotonic</strong>, <strongid="b2095984822716"><aname="b2095984822716"></a><aname="b2095984822716"></a>boottime</strong>, and <strongid="b173918568274"><aname="b173918568274"></a><aname="b173918568274"></a>realtime</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1351181716532"><aname="p1351181716532"></a><aname="p1351181716532"></a>Specifies the directory of the symbol table. The specified symbol table will be preferentially used in stack unwinding.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p33521617165316"><aname="p33521617165316"></a><aname="p33521617165316"></a>Specifies the cache size, in pages. The default value is <strongid="b1541914432911"><aname="b1541914432911"></a><aname="b1541914432911"></a>1024</strong>. The parameter value must be a power of <strongid="b1731417117306"><aname="b1731417117306"></a><aname="b1731417117306"></a>2</strong>. The value range is [2 - 1024].</p>
<pid="p18627133351018"><aname="p18627133351018"></a><aname="p18627133351018"></a>Note: A higher value indicates a lower event loss rate but higher memory usage.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p1035251755316"><aname="p1035251755316"></a><aname="p1035251755316"></a>Specifies the bundle name of the target application to be sampled. The default timeout interval is 10 seconds. If the specified application does not exist, the hiperf process exits after 10 seconds.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p135211718536"><aname="p135211718536"></a><aname="p135211718536"></a>Specifies the maximum size of the sampling result, in KB, MB, or GB. By default, there is no limit on the size.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p935241711539"><aname="p935241711539"></a><aname="p935241711539"></a>Specifies the name of the sampling result file. It is <strongid="b1714216402339"><aname="b1714216402339"></a><aname="b1714216402339"></a>/data/local/tmp/perf.data</strong> by default.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p10352117175319"><aname="p10352117175319"></a><aname="p10352117175319"></a>Saves the output file in .gzip format.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p63529178537"><aname="p63529178537"></a><aname="p63529178537"></a>Displays detailed log information during sampling.</p>
</td>
</tr>
</tbody>
</table>
### Example<a name="section15998181516549"></a>
- Sample all processes in the system for 3 seconds and display detailed log information during the sampling process.
```
hiperf record -d 3 -a --verbose
```
- Enable stack unwinding in fp mode.
```
hiperf record -s fp -d 3 -a
```
- Enable stack unwinding in dwarf mode.
```
hiperf record -s dwarf -d 3 -a
```
- Sample offcpu events.
```
hiperf record --offcpu -s dwarf -d 3 -a
```
- Delay stack unwinding.
```
hiperf record -d 3 -s dwarf --delay-unwind -a
```
- Disable stack unwinding. In this case, the stack data is saved to the **perf.data** file.
```
hiperf record -d 3 -s dwarf --disable-unwind -a
```
- Monitor the **com.ohos.launch** application. The hiperf process exits after 10 seconds if the process corresponding to the specified bundle name does not exist.
```
hiperf record -d 3 -s dwarf --app com.ohos.launch
```
- Compress the sampling results.
```
hiperf record -z -s dwarf -d 3 -a
```
## report<a name="section16327635174818"></a>
The **report** command displays the sampling data that is captured by using **record**.
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p174873421063"><aname="p174873421063"></a><aname="p174873421063"></a>Specifies the directory of the symbol table.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p14487184216619"><aname="p14487184216619"></a><aname="p14487184216619"></a>Specifies the minimum percentage of the result to display. The result that is lower than the minimum percentage is not displayed.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p194879426610"><aname="p194879426610"></a><aname="p194879426610"></a>Specifies the minimum percentage of the call stack to display. The call stack that is lower than the minimum percentage is not displayed.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p174877426611"><aname="p174877426611"></a><aname="p174877426611"></a>Converts the <strongid="b7360121984613"><aname="b7360121984613"></a><aname="b7360121984613"></a>perf.data</strong> file into the proto format. The default file name is <strongid="b255114336468"><aname="b255114336468"></a><aname="b255114336468"></a>perf.proto</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p048720421068"><aname="p048720421068"></a><aname="p048720421068"></a>Converts the <strongid="b10736748154614"><aname="b10736748154614"></a><aname="b10736748154614"></a>perf.data</strong> file into the JSON format. The default file name is <strongid="b12526557144615"><aname="b12526557144615"></a><aname="b12526557144615"></a>perf.json</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p13487942561"><aname="p13487942561"></a><aname="p13487942561"></a>Displays the report based on the branch prediction result address instead of the IP address of the call stack.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p14871342165"><aname="p14871342165"></a><aname="p14871342165"></a>Filters and displays reports based on the given keywords. <strongid="b1718471815494"><aname="b1718471815494"></a><aname="b1718471815494"></a>keys</strong> can be <strongid="b652162620493"><aname="b652162620493"></a><aname="b652162620493"></a>comms</strong>, <strongid="b1926582944916"><aname="b1926582944916"></a><aname="b1926582944916"></a>pids</strong>, and <strongid="b12471434134911"><aname="b12471434134911"></a><aname="b12471434134911"></a>tids</strong>. For example, <strongid="b1794418482490"><aname="b1794418482490"></a><aname="b1794418482490"></a>--comms hiperf,hilog</strong> displays only the records whose process or thread name is <strongid="b195761830195014"><aname="b195761830195014"></a><aname="b195761830195014"></a>hiperf</strong> or <strongid="b2036334115014"><aname="b2036334115014"></a><aname="b2036334115014"></a>hilog</strong>.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p94870428610"><aname="p94870428610"></a><aname="p94870428610"></a>Sorts and displays information based on specified keywords, such as <strongid="b114664210512"><aname="b114664210512"></a><aname="b114664210512"></a>pid</strong>, <strongid="b319919248518"><aname="b319919248518"></a><aname="b319919248518"></a>tid</strong>, and <strongid="b1140053135118"><aname="b1140053135118"></a><aname="b1140053135118"></a>comm</strong>. Multiple keywords can be specified.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p948816422618"><aname="p948816422618"></a><aname="p948816422618"></a>Specifies the sampling data (<strongid="b165437587515"><aname="b165437587515"></a><aname="b165437587515"></a>perf.data</strong> by default).</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.1.3.1.2 "><pid="p74882421167"><aname="p74882421167"></a><aname="p74882421167"></a>Specifies the name of the report to output.</p>
</td>
</tr>
</tbody>
</table>
## Example<a name="section1197655116513"></a>
- Output the report of the sampling data \(**perf.data** by default\).