shithub: mycel

Download patch

ref: 5c9c01c88b125f9235fd0c3722aa2c1ff5f7472f
parent: 478bbdf54aed1ab65ec5cc7ec13d82b0d4d5a0c9
author: Philip Silva <philip.silva@protonmail.com>
date: Fri Dec 10 13:16:37 EST 2021

mem profiling

--- a/browser/browser.go
+++ b/browser/browser.go
@@ -671,7 +671,7 @@
 }
 
 func (el *Element) Mouse(dui *duit.DUI, self *duit.Kid, m draw.Mouse, origM draw.Mouse, orig image.Point) (r duit.Result) {
-	if m.Buttons == 3 {
+	if m.Buttons == 4 {
 		if el == nil {
 			log.Infof("inspect nil element")
 		} else {
--- a/cmd/opossum/main.go
+++ b/cmd/opossum/main.go
@@ -13,6 +13,7 @@
 	"net/url"
 	"os"
 	"os/signal"
+	"runtime"
 	"runtime/pprof"
 	"strings"
 	"time"
@@ -22,6 +23,7 @@
 	dui        *duit.DUI
 	b          *browser.Browser
 	cpuprofile string
+	memprofile string
 	loc        string = "http://9p.io"
 	dbg        bool
 	v          View
@@ -164,7 +166,7 @@
 }
 
 func render() {
-	white, err := dui.Display.AllocImage(image.Rect(0, 0, 10, 10), draw.ARGB32, true, 0xffffffff)
+	white, err := dui.Display.AllocImage(image.Rect(0, 0, 1, 1), draw.ARGB32, true, 0xffffffff)
 	if err != nil {
 		log.Errorf("%v", err)
 	}
@@ -244,7 +246,7 @@
 }
 
 func usage() {
-	fmt.Printf("usage: opossum [-v|-vv] [-h] [-jsinsecure] [-cpuprofile fn] [startPage]\n")
+	fmt.Printf("usage: opossum [-v|-vv] [-h] [-jsinsecure] [-cpu|-mem fn] [startPage]\n")
 	os.Exit(1)
 }
 
@@ -266,8 +268,10 @@
 		case "-jsinsecure":
 			browser.ExperimentalJsInsecure = true
 			args = args[1:]
-		case "-cpuprofile":
-			cpuprofile, args = args[0], args[2:]
+		case "-cpu":
+			cpuprofile, args = args[1], args[2:]
+		case "-mem":
+			memprofile, args = args[1], args[2:]
 		default:
 			if len(args) > 1 {
 				usage()
@@ -289,6 +293,21 @@
 		go func() {
 			<-time.After(time.Minute)
 			pprof.StopCPUProfile()
+			f.Close()
+			os.Exit(2)
+		}()
+	}
+
+	if memprofile != "" {
+		f, err := os.Create(memprofile)
+		if err != nil {
+			log.Fatal(err)
+		}
+		go func() {
+			<-time.After(time.Minute)
+			runtime.GC()
+			pprof.WriteHeapProfile(f)
+			f.Close()
 			os.Exit(2)
 		}()
 	}