Search Unity

How to make my Native Plugin show "GC.Alloc" in Profiler Hierarchy

Discussion in 'Scripting' started by FanqunABing, Sep 26, 2022.

  1. FanqunABing

    FanqunABing

    Joined:
    Sep 26, 2022
    Posts:
    2
    According to https://docs.unity3d.com/Manual/LowLevelNativePluginProfiler.html, I add ProfilerMarker API to my cpp library, but It's hard to analyze the native memory allocation of it bzc I don't know how to make my custom data display in Profiler Panel as I wish.

    upload_2022-9-26_18-56-25.png


    // Available since 2020.1
    UNITY_DECLARE_INTERFACE(IUnityProfiler)
    {
    void BeginSample(const UnityProfilerMarkerDesc* markerDesc)
    {
    (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, 0, NULL);
    }

    void BeginSample(const UnityProfilerMarkerDesc* markerDesc, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData)
    {
    (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeBegin, eventDataCount, eventData);
    }

    void EndSample(const UnityProfilerMarkerDesc* markerDesc)
    {
    (this->EmitEvent)(markerDesc, kUnityProfilerMarkerEventTypeEnd, 0, NULL);
    }

    void(UNITY_INTERFACE_API * EmitEvent)(const UnityProfilerMarkerDesc* markerDesc, UnityProfilerMarkerEventType eventType, uint16_t eventDataCount, const UnityProfilerMarkerData* eventData);

    int(UNITY_INTERFACE_API * IsEnabled)();
    int(UNITY_INTERFACE_API * IsAvailable)();

    int(UNITY_INTERFACE_API * CreateMarker)(const UnityProfilerMarkerDesc** desc, const char* name, UnityProfilerCategoryId category, UnityProfilerMarkerFlags flags, int eventDataCount);
    int(UNITY_INTERFACE_API * SetMarkerMetadataName)(const UnityProfilerMarkerDesc* desc, int index, const char* metadataName, UnityProfilerMarkerDataType metadataType, UnityProfilerMarkerDataUnit metadataUnit);

    int(UNITY_INTERFACE_API * RegisterThread)(UnityProfilerThreadId* threadId, const char* groupName, const char* name);
    int(UNITY_INTERFACE_API * UnregisterThread)(UnityProfilerThreadId threadId);
    };


    I have tried 'SetMarkerMetadataName' but It just change the Metadata formation from "0:44" to "Size:44".What should I do to make My UnityProfilerMarkerDesc display native memory allocation just like C# managed memory allocation.
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,456
    GC.Alloc is not using the Metadata API so you can't hack that to report memory that is not managed by the Mono/IL2CPP VM. There is a new native API for allocating native memory via Unity allocators, and thereby informing the Profiler about them, in 2022.2. The Docs for that are still being written.

    You can find the header in
    <EditorInstallPath>/Data/PluginAPI
    though.
     
  3. FanqunABing

    FanqunABing

    Joined:
    Sep 26, 2022
    Posts:
    2
    Thanks, I got the Header.(named IUnityMemoryManager.h right?) I'll try it in new version Unity later. Maybe it's a good chance to try new ECS,either.
     
    MartinTilo likes this.