Giter VIP home page Giter VIP logo

loli_profiler's Introduction

Overview

LoliProfiler is a C/C++ memory profiling tool for Android games and applications.

LoliProfiler supports profiling debuggable applications out of box. And offers engine specific (UnrealEngine4/Unity) modifications to enable profiling complex or production level games.

Features

  • Profiler client supports Windows 10/7 and Mac OSX Mojave and newer.
  • Work with debuggable applications out of box.
  • Support attaching to running application.
  • Support multiple back-trace implementations.
  • Support profiling complex games by doing some mods with your game engine.
  • Support detecting c++ code memory leaks(Tested with Unreal Engine 4.26).
  • Support profiling release build applications on rooted devices.
  • Multiple data view modes: tree map/call tree/memory fragmentation.

Documents

Special Thanks

License

See LICENSE File.

loli_profiler's People

Contributors

chenyangchenyang avatar d34d633f avatar danielmelody avatar sindney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loli_profiler's Issues

unity 2019 "-fno-omit-frame-pointer" 选项可以做到debug包才生效吗?

如题,我们这边可以修改uniyt引擎的源码,但是这个改动希望只对debug包生效,请问有什么办法吗?

改动:

// 修改文件: Tools/Bee/Bee.Toolchain.Android/AndroidNdkCompiler.cs
// if (Optimization != OptimizationLevel.None)
// {
// // important for performance. Frame pointer is only useful for profiling, but
// // introduces additional instructions into the prologue and epilogue of each function
// // and leaves one less usable register.
// yield return "-fomit-frame-pointer";
// }
yield return "-fno-omit-frame-pointer"; // <- 打开Framepointer选项

Integrate Matrix Backtrace Component

Tencent/matrix#595

Matrix for Android v1.0 updates:
Add Memory Hook. A native memory leak detection tool for Android.
Add Pthread Hook. A Java and native thread leak detection tool for Android.
Add Matrix Backtrace Component. A fast native backtrace unwind library based on quicken unwind tables.

It's way faster than libunwind, and if we support this method by default, the usability of loliprofiler will be enhanced.

为什么使用Show Leaks却展示不出来内存泄漏

大神,您好,对于Show Leaks这个功能的使用,我有些不明白。
image

下面是您文档上写的操作方法:
image

下面是我的操作。在选中的这段时间内,是存在内存泄漏的,为什么使用Show Leaks却展示不出来内存泄漏?
image

unity 2019.4解析不出来

unity2019.4,unity和libil2cpp一直解析不出来,看到有生成libil2cpp.so.txt和libunity.so.txt都是有符号的
image

Connection lost ...

Starting application ...
Application Started!
Connecting to application server ... 
Connection lost ...
Kill your app or re-plug USB cable and try again.

image

Show merged Callbacks展示效果的优化建议

Show merged Callbacks功能我有两个优化意见,供你参考:

  1. Show merged Callbacks的调用栈很长,点击一次展开一级非常麻烦,能不能点击一下一次性自动展开所有的调用堆栈呢?
  2. Show merged Callbacks显示合并后,有种类型的调用堆栈。这两种堆栈其实前面的都是相同的,只有后面几个方法不同,但是分成了两类展示,这里的展示方式可以优化一下:
    image
    image

captured 0 records

i cannot captured records when i debug my debugable app.
i want to konw is it caused by my UNROOT phone?

and loliprofiler show,
Starting application ...
Application Started!
Connecting to application server ...
Cached 0 records.
Captured 0 records.

能否对MarkTime操作做一些优化

在检查时间段Leak时提示需要mark time,但这个操作在ui和文档里都没有看到有做提示,最后阅读源码才看到是Shift+拖拽。

能否改成默认拖拽就是mark Time,Ctrl+拖拽是移动坐标轴;或者是hover时候弹窗提示一下组合键,这个键位组合确实不容易发现,也缺少指引。

为什么malloc的内存被free了,但是在Persistent选项中还是可以看到?如何监控app的内存泄漏?

你好。我写一个demo测试了一下。在我的demo中,有一个按钮,每点击一次,都会创建一个线程;在这个线程中,通过jni调用了setValue()方法。
在setValue()方法中,有一个for循环,每1s钟通过malloc()分配了一个3.8M的内存;在setValue()的末尾又调用free()方法释放了内存;

我的问题是:

  1. 为什么所有malloc的内存都free了,但是在Persistent选项中,还是看到了malloc()分配的内存?我看文档说,Persistent 选项会筛选出常驻内存,即未被释放的内存申请记录。这里的内存释放了,应该不是常驻内存的。
  2. 为什么loli_profiler监控到的malloc()的调用次数比我实际在代码中调用的malloc()的次数要少得多?是因为有采样处理吗?
  3. 如果我的so中有内存泄漏,我怎么样通过loli_profiler定位到呢?

image

image

不能Launch只能Attach

Lanuch形式启动时,应该是jdwp不好使 log里显示 ERROR/jdwp : [-] Exception: unpack requires a string argument of length 11。

我换Attach方式启动却好使(说明我配置什么的都正确了)。

这是为什么呢,怎么才能解决launch那个报错呢

支持命令行调用吗

你好,我们想集成到自动化测试中,想了解下是否支持命令行调用的方式

一直提示Connection lost,无法抓取数据

一直提示如下:
Starting application ...
Application Started!
Connecting to application server ...
Connection lost ...
Kill your app or re-plug USB cable and try again.

翻了下FQA说是可能无法连接 apk中 的服务器,需要提供网络权限。目前判断网络权限应该是的,可以正常连接游戏服务器。是不是还需要前置的集成工作才能使用?logcat没有捕捉到相关的日志

测试大型项目时,运行几分钟后会失去tcp连接。

我在用strict模式测试大型项目,内存申请频繁。
一般连接成功后用几分钟就会弹出:

Print("Connection lost ...");
Print("Kill your app or re-plug USB cable and try again.");

是否意味着我的程序内存申请过多,又为什么会导致断开连接。(这时我的程序没有退出,只是断开连接了)

无法进行连接上设备Connection lost

重启Android机器和电脑也无法连接上设备进行调试,报错信息
Starting application ...
Application Started!
Connecting to application server ...
Connection lost ...
Kill your app or re-plug USB cable and try again.

loli_profile可以定位出unity3d c#内存泄露代码吗?

如题,这边使用了unity3d c#写了一个可能内存泄露的地方,采用il2cpp编译,监控的so库是v8a的;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Demo : MonoBehaviour
{
private static Sprite leakOne;
public Sprite testSprite;
// Start is called before the first frame update
void Start()
{
leakOne = testSprite;
}

// Update is called once per frame
void Update()
{
    
}

}

launch后采集几秒钟数据就断开了

每次launch成功后几秒钟就断连接了,日志如下:
Starting application ...
Application Started!
Connecting to application server ...
Connection lost ...
Kill your app or re-plug USB cable and try again.
Error occurred when capturing screenshot ...
下面是我的配置
image

MainWindow::InterpretRecordLibrary 代码临时变量命名可优化

如下代码 for 中 定义int i。 在嵌套的另一个for中又定义一个 int i。
c++ 这么写没有问题。
但不便于维护代码和后期修改。

void MainWindow::InterpretRecordLibrary(StackRecord& record, StacktraceData& data) {
auto it = callStackMap_.find(record.uuid_);
if (it == callStackMap_.end())
return;
auto& callStack = it.value();
for (int i = 0; i < callStack.size(); i++) {
auto& libName = callStack[i].first;
auto& funcAddr = callStack[i].second;
bool found = false;
for (int i = 0; i < sMapsCache_.size(); i++) {
const auto& cache = sMapsCache_[i];

merged call stack 内容疑似错乱

framepointer模式
threshold设置成0byte
如此便有大量的cache文件
stop后 loadsymbol

发现merged callstack的tree里面的堆栈错乱,怀疑是不是由于record量较大导致引起了bug?

captured 0 records:Error dlopen,试了好多设备都是如此

mZ0Eq6I7UP
试了好多设备都是如此,比如

  1. Android 12,没root的 onePlus 9 pro 骁龙888
  2. Android 12,root的 mi10 pro 骁龙865
  3. Android 10,root的 mi8 骁龙845

用的是Ue4的 Demo工程,adb logcat -s Loli输出,求楼主看看还有救吗?祈求回复阿
C:\Users\luo>adb logcat -s Loli
--------- beginning of system
--------- beginning of main
11-24 09:41:11.508 7137 7137 I Loli : JNI_OnLoad
11-24 09:41:11.509 7137 7137 I Loli : mode: 1, build: default, minRecSize: 10240, blacklist: 0, hookLibs: libUE4.so,
11-24 09:41:11.510 7137 7137 I Loli : loli start status 0
11-24 09:41:11.512 7137 7241 I Loli : libUE4.so (/data/app/com.YourCompany.luo-NgvYhgqdItpy03Kvqg0OPA==/lib/arm64/libUE4.so) is loaded
11-24 09:41:11.526 7137 7241 I Loli : loaded in Android at 0x6ff93000
11-24 09:41:11.526 7137 7241 E Loli : failed to open
11-24 09:41:11.526 7137 7241 I Loli : Error dlopen:
11-24 09:41:11.541 7137 7241 I Loli : All desired libraries are loaded.

Cached 0 records.

adb logcat -s Loli
--------- beginning of system
--------- beginning of main
10-25 12:52:29.793 11204 12234 I Loli : Client disconnected, ecode: 0
10-25 12:53:21.589 12742 12742 I Loli : JNI_OnLoad
10-25 12:53:21.589 12742 12742 I Loli : mode: 0, build: default, minRecSize: 256, blacklist: 0, hookLibs: libunity,libil2cpp,
10-25 12:53:21.589 12742 12742 I Loli : loli start status 0
10-25 12:53:24.429 12742 14281 I Loli : Client connected
10-25 12:54:17.871 12742 14281 I Loli : Client disconnected, ecode: 0

adb logcat -s xhook
--------- beginning of system
--------- beginning of main

OS: Android 10.
Device: HONOR ViewPad 6

长时间运行,发现meminfo的nativeheap和我自己累加的不一样,是否是swapdirty未记录导致?

引用网上的资料中的一句话: PSS中已经包含了Private Dirty和Private Clean,但是没包含swapped dirty,所以最终衡量你的进程对物理内存的占用应该是取PSS+Swapped Dirty。

但是看loli的源码中 折线图里面 nativeHeap读的是meminfo dump里的 private dirty 或者psstotal 反正代码应该是没计算 swapped dirty。

这里是否应该加上swapped dirty的值呢?

Captured 0 records

image

image

9-18 17:55:51.428 25222 25222 I Loli    : JNI_OnLoad
09-18 17:55:51.428 25222 25222 I Loli    : mode: 0, build: default, minRecSize: 256, blacklist: 0, hookLibs: libunity,libil2cpp,libmtmap.so,libtbtengine.so,
09-18 17:55:51.429 25222 25222 I Loli    : loli start status 0
09-18 17:55:51.432 25222 25342 I Loli    : libxxx.so (/data/app/com.) is loaded
09-18 17:55:51.432 25222 25342 I Loli    : libxxx.so (/data/app/com.) is loaded
09-18 17:55:51.441 25222 25342 I Loli    :  loaded in Android at 0x07061000
09-18 17:55:51.441 25222 25342 E Loli    : failed to open
09-18 17:55:51.441 25222 25342 I Loli    : Error dlopen:
09-18 17:55:51.441 25222 25342 I Loli    :  loaded in Android at 0x07061000
09-18 17:55:51.441 25222 25342 E Loli    : failed to open
09-18 17:55:51.441 25222 25342 I Loli    : Error dlopen:
09-18 17:55:51.441 25222 25342 I Loli    :  loaded in Android at 0x07061000
09-18 17:55:51.441 25222 25342 E Loli    : failed to open
09-18 17:55:51.441 25222 25342 I Loli    : Error dlopen:
09-18 17:55:51.441 25222 25342 I Loli    :  loaded in Android at 0x07061000
09-18 17:55:51.441 25222 25342 E Loli    : failed to open
09-18 17:55:51.441 25222 25342 I Loli    : Error dlopen:
09-18 17:55:53.789 25222 25341 I Loli    : Client connected
09-18 17:58:11.492 25222 25341 I Loli    : Client disconnected, ecode: 0

这个框架应该是夸大了它的能力,实际来看只能分析android原生场景的native内存泄露,对于unity是分析不了的,unreal的情况也抓不到任何数据

你好,这个框架说是有unity排查内存泄露的能力,实验下来是不行的,询问后又说需要unity mono层自己定位,unity是自己有profiler可以定位的,但是框架的开发目的就是替代这些能力;
是这样的如果做不到这些能力的话不应该写到readme里面来抬高自己框架的价值,谢谢!!

UE4.27通过MallocBinned2.cpp不能跟踪

按照文档:https://github.com/Tencent/loli_profiler/blob/master/docs/GAME_ENGINE_CN.md 修改UE 4.27源码,测试下来发现:
- 修改MallocBinned2.h MallocBinned2.cpp 不能跟踪到实际内存分配
- 修改MallocBinned3.h MallocBinned3.cpp 不能跟踪到

去修改AndroidPlatformMemory.cppx强制降级为FMallocAnsi,可以跟踪到,但发现跟踪到内存增量只有47MB, 但实际PSS增长100MB,有50多MB没跟踪到,求大神解答?

image

能不能增加一个体现native虚拟内存的曲线

大神,我还有一个问题。在我的Demo中,有一个按钮,每点击一次,就使用malloc()分配了100M的内存,并且没有使用free()释放;我连续点击了很多次,但是在这个NativeHeap曲线上没有任何变化,一直是平的。经过验证,我发现NativeHeap是PSS内存,代表的是物理内存的大小,而malloc()分配的内存在没有写入内容前,是虚拟内存。
实际上,在App的使用中,也存在很多这个使用malloc()分配虚拟内存导致的泄漏,能不能增加一个体现native虚拟内存的曲线呢?
image

关于 docs/GAME_ENGINE.md 这个说明的不懂之处

大神 ,我想把文档都看懂一遍, Instrumented 和 Frame pointer 这两个优化的介绍我没太懂。
Unreal Engine 4 和 Unity Engine,是游戏引擎吗,是不是我们项目中没有用Unreal Engine 4 、Unity Engine这两个 ,我就不用看
Instrumented 和 Frame pointer 这俩优化的介绍了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.