CodeSampleX

Beispiel

github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38: profile.Line

Verifiziertes Beispiel für golang github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38: profile.Line. Der Vertrag lief auf go 1.26 · linux debian/x64 …

sha256:e57202934062e3fed0a38fab5feaf996fea010f19110f234c9dda2b84f9222e4

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-04

Fall

HOW
Ziel
verify github.com/google/pprof/profile.Line in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38
Pakete
Symbole
  • github.com/google/pprof/profile.Line
Erstellt
2026-09-04T12:16:23Z

Contract

  1. profile.Line associates a function with a specific source line number in a profile location
  2. Location supports multiple profile.Line entries representing inlined function call frames
  3. profile.CheckValid enforces that profile.Line references a non-nil function defined in the profile
  4. Profile serialization and parsing preserves profile.Line function associations and line numbers across round trips

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • line.go
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/google/pprof/profile.Line in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38
Demonstrate these symbols/APIs:
  - github.com/google/pprof/profile.Line

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:707f082c736120f6d54c2d47e9ad1cf0fc7964f387cb5dc795f674e8ab2004ce","contract":["profile.Line associates a function with a specific source line number in a profile location","Location supports multiple profile.Line entries representing inlined function call frames","profile.CheckValid enforces that profile.Line references a non-nil function defined in the profile","Profile serialization and parsing preserves profile.Line function associations and line numbers across round trips"],"goal":"verify github.com/google/pprof/profile.Line in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38"],"schemaVersion":1,"symbols":["github.com/google/pprof/profile.Line"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38","symbols":["github.com/google/pprof/profile.Line"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.22

require github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38
go.sum
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
line.go
package sample

import (
	"bytes"
	"fmt"

	"github.com/google/pprof/profile"
)

// NewLine creates a profile.Line associating a function with a source line number.
func NewLine(fn *profile.Function, line int64) profile.Line {
	return profile.Line{
		Function: fn,
		Line:     line,
	}
}

// NewInlinedLocation creates a profile.Location containing multiple inlined lines.
func NewInlinedLocation(id uint64, lines []profile.Line) *profile.Location {
	return &profile.Location{
		ID:   id,
		Line: lines,
	}
}

// CreateProfileWithLocation builds a valid minimal profile containing the provided location and functions.
func CreateProfileWithLocation(loc *profile.Location, fns []*profile.Function) *profile.Profile {
	return &profile.Profile{
		SampleType: []*profile.ValueType{
			{Type: "samples", Unit: "count"},
		},
		PeriodType: &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
		Period:     10000000,
		Function:   fns,
		Location:   []*profile.Location{loc},
		Sample: []*profile.Sample{
			{
				Location: []*profile.Location{loc},
				Value:    []int64{1},
			},
		},
	}
}

// RoundTripProfile serializes a profile to gzip protobuf bytes and parses it back.
func RoundTripProfile(p *profile.Profile) (*profile.Profile, error) {
	var buf bytes.Buffer
	if err := p.Write(&buf); err != nil {
		return nil, fmt.Errorf("failed to write profile: %w", err)
	}
	parsed, err := profile.Parse(&buf)
	if err != nil {
		return nil, fmt.Errorf("failed to parse profile: %w", err)
	}
	return parsed, nil
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/pprof/profile.Line in pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/pprof@v0.0.0-20210407192527-94a9f03dee38"
  ],
  "symbols": [
    "github.com/google/pprof/profile.Line"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/google/pprof/profile"
	"sample"
)

func main() {
	// Assertion 1: profile.Line associates a function with a specific source line number in a profile location
	fn := &profile.Function{
		ID:         1,
		Name:       "computeHash",
		SystemName: "computeHash",
		Filename:   "hash.go",
		StartLine:  10,
	}
	line := sample.NewLine(fn, 25)
	if line.Function != fn {
		fmt.Fprintf(os.Stderr, "line function mismatch: got %v, want %v\n", line.Function, fn)
		os.Exit(1)
	}
	if line.Line != 25 {
		fmt.Fprintf(os.Stderr, "line number mismatch: got %d, want 25\n", line.Line)
		os.Exit(1)
	}

	// Assertion 2: Location supports multiple profile.Line entries representing inlined function call frames
	callerFn := &profile.Function{
		ID:         2,
		Name:       "processRequest",
		SystemName: "processRequest",
		Filename:   "server.go",
		StartLine:  50,
	}
	lines := []profile.Line{
		sample.NewLine(fn, 25),       // innermost inlined frame
		sample.NewLine(callerFn, 72), // caller frame
	}
	loc := sample.NewInlinedLocation(1, lines)
	if len(loc.Line) != 2 {
		fmt.Fprintf(os.Stderr, "expected 2 lines in location, got %d\n", len(loc.Line))
		os.Exit(1)
	}
	if loc.Line[0].Function.Name != "computeHash" || loc.Line[0].Line != 25 {
		fmt.Fprintf(os.Stderr, "innermost frame mismatch: got func %s line %d\n", loc.Line[0].Function.Name, loc.Line[0].Line)
		os.Exit(1)
	}
	if loc.Line[1].Function.Name != "processRequest" || loc.Line[1].Line != 72 {
		fmt.Fprintf(os.Stderr, "caller frame mismatch: got func %s line %d\n", loc.Line[1].Function.Name, loc.Line[1].Line)
		os.Exit(1)
	}

	// Assertion 3: profile.CheckValid enforces that profile.Line references a non-nil function defined in the profile
	p := sample.CreateProfileWithLocation(loc, []*profile.Function{fn, callerFn})
	if err := p.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "valid profile CheckValid failed: %v\n", err)
		os.Exit(1)
	}

	invalidLocNilFn := &profile.Location{
		ID: 2,
		Line: []profile.Line{
			{Function: nil, Line: 10},
		},
	}
	pInvalidNil := sample.CreateProfileWithLocation(invalidLocNilFn, []*profile.Function{fn, callerFn})
	if err := pInvalidNil.CheckValid(); err == nil {
		fmt.Fprintf(os.Stderr, "expected CheckValid error for nil Line.Function, got nil\n")
		os.Exit(1)
	}

	unknownFn := &profile.Function{ID: 99, Name: "orphan", Filename: "orphan.go"}
	invalidLocUnlistedFn := &profile.Location{
		ID: 3,
		Line: []profile.Line{
			{Function: unknownFn, Line: 15},
		},
	}
	pInvalidUnlisted := sample.CreateProfileWithLocation(invalidLocUnlistedFn, []*profile.Function{fn, callerFn})
	if err := pInvalidUnlisted.CheckValid(); err == nil {
		fmt.Fprintf(os.Stderr, "expected CheckValid error for unlisted Line.Function, got nil\n")
		os.Exit(1)
	}

	// Assertion 4: Profile serialization and parsing preserves profile.Line function associations and line numbers across round trips
	rtProfile, err := sample.RoundTripProfile(p)
	if err != nil {
		fmt.Fprintf(os.Stderr, "round trip serialization failed: %v\n", err)
		os.Exit(1)
	}
	if err := rtProfile.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "round trip profile CheckValid failed: %v\n", err)
		os.Exit(1)
	}
	if len(rtProfile.Location) != 1 || len(rtProfile.Location[0].Line) != 2 {
		fmt.Fprintf(os.Stderr, "round trip line count mismatch: got %d locations\n", len(rtProfile.Location))
		os.Exit(1)
	}
	rtLines := rtProfile.Location[0].Line
	if rtLines[0].Function == nil || rtLines[0].Function.Name != "computeHash" || rtLines[0].Line != 25 {
		fmt.Fprintf(os.Stderr, "round trip innermost line mismatch\n")
		os.Exit(1)
	}
	if rtLines[1].Function == nil || rtLines[1].Function.Name != "processRequest" || rtLines[1].Line != 72 {
		fmt.Fprintf(os.Stderr, "round trip caller line mismatch\n")
		os.Exit(1)
	}

	fmt.Println("All profile.Line contract assertions passed.")
}

Ursprungs-Seeder

anonym