// Copyright 2025 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package traceimport ()// timestamp is an unprocessed timestamp.type timestamp uint64// batch represents a batch of trace events.// It is unparsed except for its header.type batch struct { m threadID time timestamp data []byte}// threadID is the runtime-internal M structure's ID. This is unique// for each OS thread.type threadID int64// readBatch copies b and parses the trace batch header inside.// Returns the batch, the generation, bytes read, and an error.func readBatch( []byte) (batch, uint64, uint64, error) {iflen() == 0 {returnbatch{}, 0, 0, fmt.Errorf("batch is empty") } := make([]byte, len())if := copy(, ); != len() {returnbatch{}, 0, 0, fmt.Errorf("unexpected error copying batch") }// Read batch header byte.if := tracev2.EventType([0]); != tracev2.EvEventBatch && != tracev2.EvExperimentalBatch {returnbatch{}, 0, 1, fmt.Errorf("expected batch event, got event %d", ) }// Read the batch header: gen (generation), thread (M) ID, base timestamp // for the batch. := 1 = [1:] , , := readUvarint()if != nil {returnbatch{}, , uint64( + ), fmt.Errorf("error reading batch gen: %w", ) } += = [:] , , := readUvarint()if != nil {returnbatch{}, , uint64( + ), fmt.Errorf("error reading batch M ID: %w", ) } += = [:] , , := readUvarint()if != nil {returnbatch{}, , uint64( + ), fmt.Errorf("error reading batch timestamp: %w", ) } += = [:]// Read in the size of the batch to follow. , , := readUvarint()if != nil {returnbatch{}, , uint64( + ), fmt.Errorf("error reading batch size: %w", ) }if > tracev2.MaxBatchSize {returnbatch{}, , uint64( + ), fmt.Errorf("invalid batch size %d, maximum is %d", , tracev2.MaxBatchSize) } += += int() = [:]// Return the batch.returnbatch{m: threadID(),time: timestamp(),data: , }, , uint64(), nil}
The pages are generated with Goldsv0.7.7-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.