CodeSampleX

サンプル

github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2: profile.Parse

検証済みサンプル — golang github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2: profile.Parse. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました.

sha256:32e62cfc3bf16c8c2bb93df3c6b235e34fadb12235505bc14d4ecca319ad3a15

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
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-30

ケース

HOW
ゴール
verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2
パッケージ
シンボル
  • github.com/google/pprof/profile.Parse
作成日
2026-10-30T21:30:53Z

コントラクト

  1. profile.Profile creates and validates a structured cpu/memory profile with CheckValid
  2. profile.Profile.Write serializes the profile into gzip-compressed protobuf format
  3. profile.Parse parses serialized profile data and restores samples, locations, and functions

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2
Demonstrate these symbols/APIs:
  - github.com/google/pprof/profile.Parse

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:84ac5f6917d09eb0d6847f6ef967c1c92f9ccbc717ff526abd59018e78dccf5a","contract":["profile.Profile creates and validates a structured cpu/memory profile with CheckValid","profile.Profile.Write serializes the profile into gzip-compressed protobuf format","profile.Parse parses serialized profile data and restores samples, locations, and functions"],"goal":"verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2","kind":"HOW","packages":["pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2"],"schemaVersion":1,"symbols":["github.com/google/pprof/profile.Parse"]},"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-20201203190320-1bf35d6f28c2"],"schemaVersion":1,"subject":"pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2","symbols":["github.com/google/pprof/profile.Parse"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.25.0

require github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2
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-20201203190320-1bf35d6f28c2 h1:HyOHhUtuB/Ruw/L5s5pG2D0kckkN2/IzBs9OClGHnHI=
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/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=
sample.go
package sample

import (
	"bytes"
	"io"

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

// BuildSampleProfile constructs a valid profile with sample type, functions, locations, and samples.
func BuildSampleProfile(functionName, filename string, line int64, sampleCount, cpuNanos int64) (*profile.Profile, error) {
	p := &profile.Profile{
		SampleType: []*profile.ValueType{
			{Type: "samples", Unit: "count"},
			{Type: "cpu", Unit: "nanoseconds"},
		},
		PeriodType: &profile.ValueType{Type: "cpu", Unit: "nanoseconds"},
		Period:     10000000,
	}

	fn := &profile.Function{
		ID:         1,
		Name:       functionName,
		SystemName: functionName,
		Filename:   filename,
		StartLine:  line,
	}
	p.Function = []*profile.Function{fn}

	loc := &profile.Location{
		ID: 1,
		Line: []profile.Line{
			{
				Function: fn,
				Line:     line + 5,
			},
		},
	}
	p.Location = []*profile.Location{loc}

	s := &profile.Sample{
		Location: []*profile.Location{loc},
		Value:    []int64{sampleCount, cpuNanos},
	}
	p.Sample = []*profile.Sample{s}

	if err := p.CheckValid(); err != nil {
		return nil, err
	}

	return p, nil
}

// SerializeProfile writes a Profile to an io.Writer in standard pprof format.
func SerializeProfile(p *profile.Profile, w io.Writer) error {
	return p.Write(w)
}

// ParseProfile parses a serialized pprof stream from an io.Reader.
func ParseProfile(r io.Reader) (*profile.Profile, error) {
	return profile.Parse(r)
}

// EncodeAndDecode serializes and re-parses a profile, returning the decoded profile.
func EncodeAndDecode(p *profile.Profile) (*profile.Profile, error) {
	var buf bytes.Buffer
	if err := p.Write(&buf); err != nil {
		return nil, err
	}
	return profile.Parse(&buf)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/google/pprof/profile.Parse in pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/pprof@v0.0.0-20201203190320-1bf35d6f28c2"
  ],
  "symbols": [
    "github.com/google/pprof/profile.Parse"
  ]
}
test/contract.go
package main

import (
	"bytes"
	"fmt"
	"os"

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

func main() {
	// Assertion 1: profile.Profile creates and validates a structured cpu/memory profile with CheckValid
	p, err := sample.BuildSampleProfile("worker.processTask", "worker.go", 10, 5, 50000000)
	if err != nil {
		fmt.Fprintf(os.Stderr, "BuildSampleProfile failed: %v\n", err)
		os.Exit(1)
	}

	var _ *profile.Profile = p
	if err := p.CheckValid(); err != nil {
		fmt.Fprintf(os.Stderr, "p.CheckValid failed: %v\n", err)
		os.Exit(1)
	}

	if len(p.Sample) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 sample, got %d\n", len(p.Sample))
		os.Exit(1)
	}

	// Assertion 2: profile.Profile.Write serializes the profile into gzip-compressed protobuf format
	var buf bytes.Buffer
	if err := p.Write(&buf); err != nil {
		fmt.Fprintf(os.Stderr, "p.Write failed: %v\n", err)
		os.Exit(1)
	}

	if buf.Len() == 0 {
		fmt.Fprintf(os.Stderr, "serialized buffer is empty\n")
		os.Exit(1)
	}

	// Assertion 3: profile.Parse parses serialized profile data and restores samples, locations, and functions
	parsed, err := profile.Parse(&buf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "profile.Parse failed: %v\n", err)
		os.Exit(1)
	}

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

	if len(parsed.Sample) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 sample in parsed profile, got %d\n", len(parsed.Sample))
		os.Exit(1)
	}

	if parsed.Sample[0].Value[0] != 5 || parsed.Sample[0].Value[1] != 50000000 {
		fmt.Fprintf(os.Stderr, "parsed sample values mismatch: got %v, expected [5, 50000000]\n", parsed.Sample[0].Value)
		os.Exit(1)
	}

	if len(parsed.Function) != 1 || parsed.Function[0].Name != "worker.processTask" {
		fmt.Fprintf(os.Stderr, "parsed function mismatch\n")
		os.Exit(1)
	}

	if len(parsed.Location) != 1 || len(parsed.Location[0].Line) != 1 || parsed.Location[0].Line[0].Line != 15 {
		fmt.Fprintf(os.Stderr, "parsed location line mismatch\n")
		os.Exit(1)
	}

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

オリジンシーダー

匿名