# Debug 内存与性能问题

如果感觉到内存和性能上有问题，可以用 mosdns 内置的 pprof 工具进行分析。

## 自己分析

如果有相关知识和能力的话，可自行使用 pprof。

1. 配置文件中填入 api.http 地址。启用 api 服务器。
2. pprof 位于  `http://<api_addr>/debug/pprof/` 。

## 提交给开发者

如果发现内存和性能问题，将 pprof 数据提交给开发者可以帮助他们快速定位问题。下载数据的方式非常简单。

* 确保配置文件中填入了 api.http 地址。mosdns 已启用 api 服务器。
* 出现异常时 (比如 cpu 持续 100%，或者内存已爆炸)，浏览器访问以下网址，下载采样数据。

```
# <api_addr> 替换成 api 服务器的地址。
# 内存采样数据
http://<api_addr>/debug/pprof/allocs
http://<api_addr>/debug/pprof/goroutine
http://<api_addr>/debug/pprof/heap

# CPU 采样，仅 CPU 占用异常时需要
http://<api_addr>/debug/pprof/profile?seconds=5
```

* 将采样数据上传给开发者。

补充:

* 采样数据仅包含程序代码层面运行次数统计(某行代码运行了多久，占用了多少内存)，不是内存数据，不包含任何用户信息，可以随便分享。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://irine-sistiana.gitbook.io/mosdns-wiki/mosdns-v5/debug-nei-cun-yu-xing-neng-wen-ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
