mirror of
				https://github.com/tailscale/tailscale.git
				synced 2025-11-04 09:25:11 +00:00 
			
		
		
		
	This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
		
			
				
	
	
		
			46 lines
		
	
	
		
			942 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			942 B
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright (c) Tailscale Inc & AUTHORS
 | 
						|
// SPDX-License-Identifier: BSD-3-Clause
 | 
						|
 | 
						|
//go:build !js
 | 
						|
 | 
						|
// Package logheap logs a heap pprof profile.
 | 
						|
package logheap
 | 
						|
 | 
						|
import (
 | 
						|
	"bytes"
 | 
						|
	"context"
 | 
						|
	"log"
 | 
						|
	"net/http"
 | 
						|
	"runtime"
 | 
						|
	"runtime/pprof"
 | 
						|
	"time"
 | 
						|
)
 | 
						|
 | 
						|
// LogHeap uploads a JSON logtail record with the base64 heap pprof by means
 | 
						|
// of an HTTP POST request to the endpoint referred to in postURL.
 | 
						|
func LogHeap(postURL string) {
 | 
						|
	if postURL == "" {
 | 
						|
		return
 | 
						|
	}
 | 
						|
	runtime.GC()
 | 
						|
	buf := new(bytes.Buffer)
 | 
						|
	if err := pprof.WriteHeapProfile(buf); err != nil {
 | 
						|
		log.Printf("LogHeap: %v", err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 | 
						|
	defer cancel()
 | 
						|
	req, err := http.NewRequestWithContext(ctx, "POST", postURL, buf)
 | 
						|
	if err != nil {
 | 
						|
		log.Printf("LogHeap: %v", err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
	res, err := http.DefaultClient.Do(req)
 | 
						|
	if err != nil {
 | 
						|
		log.Printf("LogHeap: %v", err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
	defer res.Body.Close()
 | 
						|
}
 |