CodeSampleX

Beispiel

github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc: profile.Profile

Verifiziertes Beispiel für golang github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc: profile.Profile. Der Vertrag lief auf go 1.26 · linux…

sha256:24f183e41dc418afa346e171cc4ebdb8dc740c72d21acc22d4e372fcf68d2de1

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-10-18

Fall

HOW
Ziel
verify profile.Profile in pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc
Pakete
Symbole
  • profile.Profile
Erstellt
2026-10-18T19:12:35Z

Contract

  1. profile.Profile.CheckValid returns nil when SampleType, Sample, Location, and Function references are consistent
  2. profile.Profile.WriteUncompressed serializes a valid Profile into wire format that profile.ParseData round-trips without data loss
  3. profile.Profile.Copy produces an independent deep copy and Scale multiplies Sample.Value entries without mutating the source Profile
  4. profile.Merge combines compatible Profile instances and sums Sample.Value slices for matching sample locations

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • 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 profile.Profile in pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc
Demonstrate these symbols/APIs:
  - profile.Profile

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:b878b77e22ea1331197610898d0be6604951597e10ce673e7043a1b79220c055","contract":["profile.Profile.CheckValid returns nil when SampleType, Sample, Location, and Function references are consistent","profile.Profile.WriteUncompressed serializes a valid Profile into wire format that profile.ParseData round-trips without data loss","profile.Profile.Copy produces an independent deep copy and Scale multiplies Sample.Value entries without mutating the source Profile","profile.Merge combines compatible Profile instances and sums Sample.Value slices for matching sample locations"],"goal":"verify profile.Profile in pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc"],"schemaVersion":1,"symbols":["profile.Profile"]},"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-20191218002539-d4f498aebedc"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc","symbols":["profile.Profile"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.21

require github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc
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-20191218002539-d4f498aebedc h1:DLpL8pWq0v4JYoRpEhDfsJhhJyGKCcQM2WPW2TJs31c=
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify profile.Profile in pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/pprof@v0.0.0-20191218002539-d4f498aebedc"
  ],
  "symbols": [
    "profile.Profile"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

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

func main() {
	fn := &profile.Function{
		ID:         1,
		Name:       "main.compute",
		SystemName: "main.compute",
		Filename:   "main.go",
		StartLine:  10,
	}
	loc := &profile.Location{
		ID:      1,
		Address: 0x1000,
		Line: []profile.Line{
			{Function: fn, Line: 15},
		},
	}
	prof := &profile.Profile{
		SampleType: []*profile.ValueType{
			{Type: "samples", Unit: "count"},
			{Type: "cpu", Unit: "nanoseconds"},
		},
		DefaultSampleType: "cpu",
		Sample: []*profile.Sample{
			{
				Location: []*profile.Location{loc},
				Value:    []int64{10, 5000000},
				Label: map[string][]string{
					"tag": {"worker"},
				},
			},
		},
		Location:      []*profile.Location{loc},
		Function:      []*profile.Function{fn},
		DurationNanos: 10000000,
		PeriodType:    &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
		Period:        100000,
	}

	if err := prof.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "initial CheckValid failed: %v\n", err)
		os.Exit(1)
	}

	var buf bytes.Buffer
	if err := prof.WriteUncompressed(&buf); err != nil {
		fmt.Fprintf(os.Stderr, "WriteUncompressed failed: %v\n", err)
		os.Exit(1)
	}

	parsed, err := profile.ParseData(buf.Bytes())
	if err != nil {
		fmt.Fprintf(os.Stderr, "ParseData failed: %v\n", err)
		os.Exit(1)
	}
	if err := parsed.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "parsed CheckValid failed: %v\n", err)
		os.Exit(1)
	}
	if len(parsed.Sample) != 1 || len(parsed.Sample[0].Value) != 2 || parsed.Sample[0].Value[1] != 5000000 {
		fmt.Fprintf(os.Stderr, "unexpected parsed sample values: %+v\n", parsed.Sample)
		os.Exit(1)
	}
	if parsed.Sample[0].Location[0].Line[0].Function.Name != "main.compute" {
		fmt.Fprintf(os.Stderr, "unexpected function name: %s\n", parsed.Sample[0].Location[0].Line[0].Function.Name)
		os.Exit(1)
	}

	copied := parsed.Copy()
	copied.Scale(2.0)
	if copied.Sample[0].Value[0] != 20 || copied.Sample[0].Value[1] != 10000000 {
		fmt.Fprintf(os.Stderr, "unexpected scaled values: %v\n", copied.Sample[0].Value)
		os.Exit(1)
	}
	if parsed.Sample[0].Value[0] != 10 {
		fmt.Fprintf(os.Stderr, "original mutated on scaled copy: %v\n", parsed.Sample[0].Value)
		os.Exit(1)
	}

	merged, err := profile.Merge([]*profile.Profile{parsed, copied})
	if err != nil {
		fmt.Fprintf(os.Stderr, "Merge failed: %v\n", err)
		os.Exit(1)
	}
	if err := merged.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "merged CheckValid failed: %v\n", err)
		os.Exit(1)
	}
	if len(merged.Sample) != 1 || merged.Sample[0].Value[0] != 30 || merged.Sample[0].Value[1] != 15000000 {
		fmt.Fprintf(os.Stderr, "unexpected merged sample values: %+v\n", merged.Sample[0].Value)
		os.Exit(1)
	}
}

Ursprungs-Seeder

anonym