新增載入時間記錄函式

請務必記錄遊戲何時執行載入事件,原因有二:

  1. 避免在載入過程中汙染影格時間資料。
  2. 分析載入時間,找出載入時間超出可接受範圍的時間和位置。

載入事件可以有關聯的中繼資料:

typedef struct TuningFork_LoadingTimeMetadata {
    enum LoadingState {
        UNKNOWN_STATE = 0,
        // The first time the game is run
        FIRST_RUN = 1,
        // App is not backgrounded
        COLD_START = 2,
        // App is backgrounded
        WARM_START = 3,
        // App is backgrounded, least work needed
        HOT_START = 4,
        // Asset loading between levels
        INTER_LEVEL = 5
    } state;
    enum LoadingSource {
        UNKNOWN_SOURCE = 0,
        // Uncompressing data.
        MEMORY = 1,
        // Reading assets from APK bundle.
        APK = 2,
        // Reading assets from device storage.
        DEVICE_STORAGE = 3,
        // Reading assets from external storage, e.g. SD card.
        EXTERNAL_STORAGE = 4,
        // Loading assets from the network.
        NETWORK = 5,
        // Shader compilation.
        SHADER_COMPILATION = 6,
        // Time spent between process starting and onCreate.
        PRE_ACTIVITY = 7,
        // Total time spent between process starting and first render frame.
        FIRST_TOUCH_TO_FIRST_FRAME = 8
    } source;
    int32_t compression_level;  // 0 = no compression, 100 = max compression
    enum NetworkConnectivity {
        UNKNOWN = 0,
        WIFI = 1,
        CELLULAR_NETWORK = 2
    } network_connectivity;
    uint64_t network_transfer_speed_bps;  // bandwidth in bits per second
    uint64_t network_latency_ns;          // latency in nanoseconds
} TuningFork_LoadingTimeMetadata;

凡是與需求無關的欄位都可以是零。

載入事件也可以有關聯的註解。定義的方式與影格時間註解相同,在 dev_tuningfork.proto 檔案的 Annotation 訊息中使用一或多個欄位。

TuningFork_ErrorCode TuningFork_startRecordingLoadingTime( const TuningFork_LoadingTimeMetadata* eventMetadata, uint32_t eventMetadataSize, const TuningFork_CProtobufSerialization* annotation, TuningFork_LoadingEventHandle* handle);

這個函式會開始記錄與指定中繼資料和註解相關聯的載入時間事件,並填入要用於 TuningFork_stopRecordingLoadingTime() 函式的 handle

TuningFork_ErrorCode TuningFork_stopRecordingLoadingTime( TuningFork_LoadingEventHandle handle);

這個函式會停止記錄先前由 TuningFork_startRecordingLoadingTime() 啟動的事件。系統會在下一個工作階段清除時上傳事件。

TuningFork_ErrorCode TuningFork_recordLoadingTime( uint64_t time_ns, const TuningFork_LoadingTimeMetadata* eventMetadata, uint32_t eventMetadataSize, const TuningFork_CProtobufSerialization* annotation);

我們強烈建議您直接使用上述的開始和停止函式。不過,如果無法執行此操作,您可以呼叫這個函式來記錄時間長度及相關聯的中繼資料和註解。

載入群組函式

在遊戲中,您可以針對使用者看到的單一載入期間記錄多個載入事件。相關範例包括但不限於檔案載入、解壓縮和著色器編譯。

請務必告知 Tuning Fork,載入事件屬於這類群組,藉此取得更高品質的深入分析資料。針對下列開始和停止函式加入載入事件以執行此作業。

TuningFork_ErrorCode TuningFork_startLoadingGroup( const TuningFork_LoadingTimeMetadata* eventMetadata, uint32_t eventMetadataSize, const TuningFork_CProtobufSerialization* annotation, TuningFork_LoadingEventHandle* handle);

這個函式會啟動與指定中繼資料和註解相關聯的載入群組,並填入要用於 TuningFork_stopLoadingGroup() 函式的 handle。中繼資料和註解目前並未用於 Play 後端,可以設為 nullptr。所有後續載入事件都會標上專屬的群組 ID。

TuningFork_ErrorCode TuningFork_stopLoadingGroup( TuningFork_LoadingEventHandle handle);

這個函式會停止先前在 TuningFork_startLoadingGroup() 啟動的載入群組。除非再次呼叫 TuningFork_startLoadingGroup(),否則後續的載入事件都不會有群組 ID。

圖 1:載入群組的範例。