Skip to content

generate_summary_report获取不到OC对象类型 #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cjwyl1 opened this issue Aug 11, 2020 · 0 comments
Open

generate_summary_report获取不到OC对象类型 #514

cjwyl1 opened this issue Aug 11, 2020 · 0 comments

Comments

@cjwyl1
Copy link

cjwyl1 commented Aug 11, 2020

我在项目接入Matrix时,使用generate_summary_report获取内存分配情况。其中get_object_name_by_type方法无法获取OC对象类型:

allocation_category *new_category = new allocation_category();
const char *type_name = get_object_name_by_type(object_type_reader, event.object_type);
if (type_name != NULL) {
    if (event.alloca_type & memory_logging_type_vm_allocate) {
        char vm_type_name[128] = {0};
        snprintf(vm_type_name, sizeof(vm_type_name), "VM: %s", type_name);
        new_category->name = vm_type_name;
    } else {
        new_category->name = type_name;
    }
} else {
    char buff[128] = {0};
    if (org_address == 0) {
        sprintf(buff, "Alloc Fail");
        new_category->name = buff;
    } else if (event.alloca_type & memory_logging_type_alloc) {
        if (event.size < 1024) {
            sprintf(buff, "Malloc %u Bytes", event.size);
        } else if (event.size < 1024 * 1024) {
            sprintf(buff, "Malloc %0.02f KiB", event.size / 1024.0);
        } else {
            sprintf(buff, "Malloc %0.02f MiB", event.size / (1024.0 * 1024.0));
        }
        new_category->name = buff;
    } else if (event.alloca_type & memory_logging_type_vm_allocate) {
        sprintf(buff, "All Anonymous VM");
        new_category->name = buff;
    } else {
        sprintf(buff, "Unknow");
        new_category->name = buff;
    }
}

最终获取的对象内存占用情况如下:

name:VM: CoreGraphics Data
name:VM: CoreAnimation (LayerKit)
name:VM: TCMalloc
name:VM: ImageIO_PNG_Data
name:All Anonymous VM
name:VM: VM_MEMORY_STACK
name:Malloc 64.01 KiB
name:Malloc 87.06 KiB
name:Malloc 8.00 KiB
name:Malloc 4.00 KiB
name:Malloc 117.19 KiB
name:__NSDictionaryI
name:Malloc 16.01 KiB
name:Malloc 16.06 KiB
name:VM: Accelerate
name:Malloc 40.52 KiB
name:Malloc 5.00 KiB
name:CFBasicHash (value-store)
name:Malloc 43.80 KiB
name:CFBasicHash (key-store)
name:Malloc 32.00 KiB
name:Malloc 64.00 KiB
name:Malloc 16.00 KiB
name:CFData (store)
name:Malloc 8.73 KiB
name:CFData
name:Malloc 26.85 KiB
name:Malloc 52.51 KiB
name:Malloc 15.17 KiB
name:Malloc 13.24 KiB 
name:Malloc 43.40 KiB
name:Malloc 42.19 KiB
name:Malloc 37.50 KiB
name:LXLexicon
name:Malloc 9.11 KiB
name:Malloc 16.98 KiB
name:Malloc 26.92 KiB
name:Malloc 13.42 KiB
name:Malloc 26.79 KiB
name:Malloc 26.73 KiB
name:Malloc 26.17 KiB
name:Malloc 24.00 KiB
name:Malloc 5.98 KiB
name:_NSInlineData
name:Malloc 6.98 KiB
name:Malloc 4.01 KiB
name:Malloc 9.86 KiB
name:Malloc 9.25 KiB
name:Malloc 6.00 KiB
name:Malloc 4.91 KiB
name:Malloc 12.64 KiB
name:__NSSetI
name:VM: JavaScript Jit Executable Allocator
name:Malloc 5.65 KiB
name:Malloc 4.52 KiB
name:Malloc 4.16 KiB size:4.16 KiB 

看上去OC对象通过get_object_name_by_type获取的type_name均为NULL,想请教下原因。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant