diff --git a/pkg/goroutineinstance/bundle.go b/pkg/goroutineinstance/bundle.go new file mode 100644 index 0000000..16a7c24 --- /dev/null +++ b/pkg/goroutineinstance/bundle.go @@ -0,0 +1,14 @@ +package goroutineinstance + +import ( + _ "embed" +) + +//go:embed site/index.html +var IndexHtmlEmbed []byte + +//go:embed site/bundle.js +var BundleJsEmbed []byte + +//go:embed site/bundle.js.map +var BundleJsMapEmbed []byte diff --git a/pkg/goroutineinstance/instance.go b/pkg/goroutineinstance/instance.go index fcdb138..83735c8 100644 --- a/pkg/goroutineinstance/instance.go +++ b/pkg/goroutineinstance/instance.go @@ -5,13 +5,13 @@ import ( "flag" "log" "net/http" + "path" "sync" "github.com/DataDog/gostackparse" - "github.com/a-h/templ" "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" "github.com/rs/xid" - "tuxpa.in/a/pprofweb/pkg/goroutineinstance/site" ) type Instance struct { @@ -30,8 +30,14 @@ func (i *Instance) Id() xid.ID { func (i *Instance) ServeHTTP(tw http.ResponseWriter, tr *http.Request) { i.once.Do(func() { r := chi.NewRouter() - indexHandler := templ.Handler(site.Index()) - r.Get("/", indexHandler.ServeHTTP) + r.Use(middleware.StripSlashes) + r.Get("/", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, path.Join(r.URL.Path, "app"), http.StatusSeeOther) + }) + r.Get("/app", func(w http.ResponseWriter, r *http.Request) { + w.Write(IndexHtmlEmbed) + }) + r.Get("/raw", func(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(i.dat) }) diff --git a/pkg/goroutineinstance/site/.gitignore b/pkg/goroutineinstance/site/.gitignore new file mode 100644 index 0000000..6d8d8f7 --- /dev/null +++ b/pkg/goroutineinstance/site/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +bundle.js.map diff --git a/pkg/goroutineinstance/site/bundle.js b/pkg/goroutineinstance/site/bundle.js new file mode 100644 index 0000000..88d1a3e --- /dev/null +++ b/pkg/goroutineinstance/site/bundle.js @@ -0,0 +1,2 @@ +"use strict";(()=>{var G,l,xt,it,P,gt,St,tt,ot,et,nt,Yt,M={},Ct=[],te=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,rt=Array.isArray;function H(e,t){for(var n in t)e[n]=t[n];return e}function Et(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function ee(e,t,n){var i,o,r,f={};for(r in t)r=="key"?i=t[r]:r=="ref"?o=t[r]:f[r]=t[r];if(arguments.length>2&&(f.children=arguments.length>3?G.call(arguments,2):n),typeof e=="function"&&e.defaultProps!=null)for(r in e.defaultProps)f[r]===void 0&&(f[r]=e.defaultProps[r]);return V(e,f,i,o,null)}function V(e,t,n,i,o){var r={type:e,props:t,key:n,ref:i,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:o==null?++xt:o,__i:-1,__u:0};return o==null&&l.vnode!=null&&l.vnode(r),r}function E(e){return e.children}function N(e,t){this.props=e,this.context=t}function $(e,t){if(t==null)return e.__?$(e.__,e.__i+1):null;for(var n;tt&&P.sort(tt));q.__r=0}function Ht(e,t,n,i,o,r,f,s,c,u,v){var _,k,a,g,S,w=i&&i.__k||Ct,h=t.length;for(n.__d=c,ne(n,t,w),c=n.__d,_=0;_0?V(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):o).__=e,o.__b=e.__b+1,r=null,(s=o.__i=ie(o,n,f,v))!==-1&&(v--,(r=n[s])&&(r.__u|=131072)),r==null||r.__v===null?(s==-1&&_--,typeof o.type!="function"&&(o.__u|=65536)):s!==f&&(s==f-1?_--:s==f+1?_++:(s>f?_--:_++,o.__u|=65536))):o=e.__k[i]=null;if(v)for(i=0;i(c!=null&&!(131072&c.__u)?1:0))for(;f>=0||s=0){if((c=t[f])&&!(131072&c.__u)&&o==c.key&&r===c.type)return f;f--}if(s=n.__.length&&n.__.push({}),n.__[e]}function Z(e,t){var n=Rt(J++,3);!m.__s&&Vt(n.__H,t)&&(n.__=e,n.i=t,x.__H.__h.push(n))}function at(e,t){var n=Rt(J++,7);return Vt(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function _e(){for(var e;e=Ot.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(z),e.__H.__h.forEach(st),e.__H.__h=[]}catch(t){e.__H.__h=[],m.__e(t,e.__v)}}m.__b=function(e){x=null,At&&At(e)},m.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Lt&&Lt(e,t)},m.__r=function(e){jt&&jt(e),J=0;var t=(x=e.__c).__H;t&&(ut===x?(t.__h=[],x.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.i=n.__N=void 0})):(t.__h.forEach(z),t.__h.forEach(st),t.__h=[],J=0)),ut=x},m.diffed=function(e){Mt&&Mt(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ot.push(t)!==1&&Dt===m.requestAnimationFrame||((Dt=m.requestAnimationFrame)||fe)(_e)),t.__H.__.forEach(function(n){n.i&&(n.__H=n.i),n.i=void 0})),ut=x=null},m.__c=function(e,t){t.some(function(n){try{n.__h.forEach(z),n.__h=n.__h.filter(function(i){return!i.__||st(i)})}catch(i){t.some(function(o){o.__h&&(o.__h=[])}),t=[],m.__e(i,n.__v)}}),Wt&&Wt(e,t)},m.unmount=function(e){It&&It(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(i){try{z(i)}catch(o){t=o}}),n.__H=void 0,t&&m.__e(t,n.__v))};var Bt=typeof requestAnimationFrame=="function";function fe(e){var t,n=function(){clearTimeout(i),Bt&&cancelAnimationFrame(t),setTimeout(e)},i=setTimeout(n,100);Bt&&(t=requestAnimationFrame(n))}function z(e){var t=x,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),x=t}function st(e){var t=x;e.__c=e.__(),x=t}function Vt(e,t){return!e||e.length!==t.length||t.some(function(n,i){return n!==e[i]})}var ue=Symbol.for("preact-signals");function lt(){if(F>1)F--;else{for(var e,t=!1;W!==void 0;){var n=W;for(W=void 0,ct++;n!==void 0;){var i=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Gt(n))try{n.c()}catch(o){t||(e=o,t=!0)}n=i}}if(ct=0,F--,t)throw e}}var p=void 0;var W=void 0,F=0,ct=0,K=0;function qt(e){if(p!==void 0){var t=e.n;if(t===void 0||t.t!==p)return t={i:0,S:e,p:p.s,n:void 0,t:p,e:void 0,x:void 0,r:t},p.s!==void 0&&(p.s.n=t),p.s=t,e.n=t,32&p.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=p.s,t.n=void 0,p.s.n=t,p.s=t),t}}function b(e){this.v=e,this.i=0,this.n=void 0,this.t=void 0}b.prototype.brand=ue;b.prototype.h=function(){return!0};b.prototype.S=function(e){this.t!==e&&e.e===void 0&&(e.x=this.t,this.t!==void 0&&(this.t.e=e),this.t=e)};b.prototype.U=function(e){if(this.t!==void 0){var t=e.e,n=e.x;t!==void 0&&(t.x=n,e.e=void 0),n!==void 0&&(n.e=t,e.x=void 0),e===this.t&&(this.t=n)}};b.prototype.subscribe=function(e){var t=this;return Q(function(){var n=t.value,i=p;p=void 0;try{e(n)}finally{p=i}})};b.prototype.valueOf=function(){return this.value};b.prototype.toString=function(){return this.value+""};b.prototype.toJSON=function(){return this.value};b.prototype.peek=function(){var e=p;p=void 0;try{return this.value}finally{p=e}};Object.defineProperty(b.prototype,"value",{get:function(){var e=qt(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ct>100)throw new Error("Cycle detected");this.v=e,this.i++,K++,F++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{lt()}}}});function vt(e){return new b(e)}function Gt(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function zt(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function Jt(e){for(var t=e.s,n=void 0;t!==void 0;){var i=t.p;t.i===-1?(t.S.U(t),i!==void 0&&(i.n=t.n),t.n!==void 0&&(t.n.p=i)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=i}e.s=n}function D(e){b.call(this,void 0),this.x=e,this.s=void 0,this.g=K-1,this.f=4}(D.prototype=new b).h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===K))return!0;if(this.g=K,this.f|=1,this.i>0&&!Gt(this))return this.f&=-2,!0;var e=p;try{zt(this),p=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return p=e,Jt(this),this.f&=-2,!0};D.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}b.prototype.S.call(this,e)};D.prototype.U=function(e){if(this.t!==void 0&&(b.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};D.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(D.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=qt(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function Zt(e){return new D(e)}function Kt(e){var t=e.u;if(e.u=void 0,typeof t=="function"){F++;var n=p;p=void 0;try{t()}catch(i){throw e.f&=-2,e.f|=8,pt(e),i}finally{p=n,lt()}}}function pt(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Kt(e)}function se(e){if(p!==this)throw new Error("Out-of-order effect");Jt(this),p=e,this.f&=-2,8&this.f&&pt(this),lt()}function I(e){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}I.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{e()}};I.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Kt(this),zt(this),F++;var e=p;return p=this,se.bind(this,e)};I.prototype.N=function(){2&this.f||(this.f|=2,this.o=W,W=this)};I.prototype.d=function(){this.f|=8,1&this.f||pt(this)};function Q(e){var t=new I(e);try{t.c()}catch(n){throw t.d(),n}return t.d.bind(t)}var dt,ht;function T(e,t){l[e]=t.bind(null,l[e]||function(){})}function X(e){ht&&ht(),ht=e&&e.S()}function Qt(e){var t=this,n=e.data,i=yt(n);i.value=n;var o=at(function(){for(var r=t.__v;r=r.__;)if(r.__c){r.__c.__$f|=4;break}return t.__$u.c=function(){var f;!it(o.peek())&&((f=t.base)==null?void 0:f.nodeType)===3?t.base.data=o.peek():(t.__$f|=1,t.setState({}))},Zt(function(){var f=i.value.value;return f===0?0:f===!0?"":f||""})},[]);return o.value}Qt.displayName="_st";Object.defineProperties(b.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Qt},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});T("__b",function(e,t){if(typeof t.type=="string"){var n,i=t.props;for(var o in i)if(o!=="children"){var r=i[o];r instanceof b&&(n||(t.__np=n={}),n[o]=r,i[o]=r.peek())}}e(t)});T("__r",function(e,t){X();var n,i=t.__c;i&&(i.__$f&=-2,(n=i.__$u)===void 0&&(i.__$u=n=function(o){var r;return Q(function(){r=this}),r.c=function(){i.__$f|=1,i.setState({})},r}())),dt=i,X(n),e(t)});T("__e",function(e,t,n,i){X(),dt=void 0,e(t,n,i)});T("diffed",function(e,t){X(),dt=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var i=t.__np,o=t.props;if(i){var r=n.U;if(r)for(var f in r){var s=r[f];s!==void 0&&!(f in i)&&(s.d(),r[f]=void 0)}else n.U=r={};for(var c in i){var u=r[c],v=i[c];u===void 0?(u=ae(n,c,v,o),r[c]=u):u.o(v,o)}}}e(t)});function ae(e,t,n,i){var o=t in e&&e.ownerSVGElement===void 0,r=vt(n);return{o:function(f,s){r.value=f,i=s},d:Q(function(){var f=r.value.value;i[t]!==f&&(i[t]=f,o?e[t]=f:f?e.setAttribute(t,f):e.removeAttribute(t))})}}T("unmount",function(e,t){if(typeof t.type=="string"){var n=t.__e;if(n){var i=n.U;if(i){n.U=void 0;for(var o in i){var r=i[o];r&&r.d()}}}}else{var f=t.__c;if(f){var s=f.__$u;s&&(f.__$u=void 0,s.d())}}e(t)});T("__h",function(e,t,n,i){(i<3||i===9)&&(t.__$f|=2),e(t,n,i)});N.prototype.shouldComponentUpdate=function(e,t){var n=this.__$u;if(!(n&&n.s!==void 0||4&this.__$f)||3&this.__$f)return!0;for(var i in t)return!0;for(var o in e)if(o!=="__source"&&e[o]!==this.props[o])return!0;for(var r in this.props)if(!(r in e))return!0;return!1};function yt(e){return at(function(){return vt(e)},[])}var ce=0,Se=Array.isArray;function y(e,t,n,i,o,r){t||(t={});var f,s,c=t;"ref"in t&&(f=t.ref,delete t.ref);var u={type:e,props:c,key:n,ref:f,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:--ce,__i:-1,__u:0,__source:o,__self:r};if(typeof e=="function"&&(f=e.defaultProps))for(s in f)c[s]===void 0&&(c[s]=f[s]);return l.vnode&&l.vnode(u),u}var le=e=>{let{frame:t}=e;return y(E,{children:y("div",{class:"flex flex-row gap-2",children:[y("div",{children:t.Func}),y("div",{children:t.File}),y("div",{children:t.Line})]})})};function ve(){let e=yt([]),t=async()=>{let o=await(await fetch("./raw")).json();o=o.map(r=>(r.Wait=Number(BigInt(r.Wait)/BigInt(1e6)),r)),e.value=o};return Z(()=>{t()},[]),Z(()=>{e&&console.log(e)},[e]),e?y(E,{children:y("div",{class:"flex flex-col",children:[y("div",{class:"flex flex-row gap-2",children:[y("div",{children:"length:"}),y("div",{children:e.value.length})]}),y("div",{children:e.value.map((n,i)=>y("div",{id:"id-".concat(n.ID),class:"flex flex-row gap-2",children:[y("div",{children:n.ID}),y("div",{children:n.Wait}),y("div",{children:n.Stack}),n.CreatedBy&&y("div",{children:y(le,{frame:n.CreatedBy})})]}))})]})}):y(E,{children:y("div",{children:"fetching"})})}var Xt=document.getElementById("root");Xt?Ft(y(ve,{}),Xt):console.error("no root element found");})(); +//# sourceMappingURL=bundle.js.map diff --git a/pkg/goroutineinstance/site/esbuild.config.js b/pkg/goroutineinstance/site/esbuild.config.js new file mode 100644 index 0000000..c7e5264 --- /dev/null +++ b/pkg/goroutineinstance/site/esbuild.config.js @@ -0,0 +1,11 @@ +import { build } from 'esbuild' + +build({ + entryPoints: ['src/index.tsx'], + bundle: true, + minify: true, + sourcemap: true, + target: ['chrome58', 'firefox57', 'safari11', 'edge18'], + outfile: 'bundle.js', + plugins: [], +}) diff --git a/pkg/goroutineinstance/site/generate.go b/pkg/goroutineinstance/site/generate.go index f00dd96..d680fef 100644 --- a/pkg/goroutineinstance/site/generate.go +++ b/pkg/goroutineinstance/site/generate.go @@ -1,3 +1,4 @@ package site -//go:generate go run github.com/a-h/templ/cmd/templ@latest generate +//go:generate npm i +//go:generate npm run build diff --git a/pkg/goroutineinstance/site/layout.templ b/pkg/goroutineinstance/site/index.html similarity index 63% rename from pkg/goroutineinstance/site/layout.templ rename to pkg/goroutineinstance/site/index.html index e2ee7d5..6ad8a03 100644 --- a/pkg/goroutineinstance/site/layout.templ +++ b/pkg/goroutineinstance/site/index.html @@ -1,16 +1,12 @@ -package site - - -templ layout(contents templ.Component) { goroutine explorer + - @contents +
+
- -} diff --git a/pkg/goroutineinstance/site/index.templ b/pkg/goroutineinstance/site/index.templ deleted file mode 100644 index 6acc2f8..0000000 --- a/pkg/goroutineinstance/site/index.templ +++ /dev/null @@ -1,11 +0,0 @@ -package site - - - -templ Index() { - @layout() { -
- gmorning -
- } -} diff --git a/pkg/goroutineinstance/site/index_templ.go b/pkg/goroutineinstance/site/index_templ.go deleted file mode 100644 index e237b18..0000000 --- a/pkg/goroutineinstance/site/index_templ.go +++ /dev/null @@ -1,58 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.778 -package site - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import templruntime "github.com/a-h/templ/runtime" - -func Index() templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
hi
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) - templ_7745c5c3_Err = layout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/pkg/goroutineinstance/site/layout_templ.go b/pkg/goroutineinstance/site/layout_templ.go deleted file mode 100644 index 7638c9e..0000000 --- a/pkg/goroutineinstance/site/layout_templ.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by templ - DO NOT EDIT. - -// templ: version: v0.2.778 -package site - -//lint:file-ignore SA4006 This context is only used if a nested component is present. - -import "github.com/a-h/templ" -import templruntime "github.com/a-h/templ/runtime" - -func layout(contents templ.Component) templ.Component { - return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { - templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context - if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { - return templ_7745c5c3_CtxErr - } - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) - if !templ_7745c5c3_IsBuffer { - defer func() { - templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) - if templ_7745c5c3_Err == nil { - templ_7745c5c3_Err = templ_7745c5c3_BufErr - } - }() - } - ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var1 := templ.GetChildren(ctx) - if templ_7745c5c3_Var1 == nil { - templ_7745c5c3_Var1 = templ.NopComponent - } - ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("goroutine explorer") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = contents.Render(ctx, templ_7745c5c3_Buffer) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - return templ_7745c5c3_Err - }) -} - -var _ = templruntime.GeneratedTemplate diff --git a/pkg/goroutineinstance/site/package-lock.json b/pkg/goroutineinstance/site/package-lock.json new file mode 100644 index 0000000..d6af9d4 --- /dev/null +++ b/pkg/goroutineinstance/site/package-lock.json @@ -0,0 +1,477 @@ +{ + "name": "site", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "site", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@preact/signals": "^1.3.0", + "esbuild": "^0.24.0", + "preact": "^10.24.3" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.0.tgz", + "integrity": "sha512-WtKdFM7ls47zkKHFVzMz8opM7LkcsIp9amDUBIAWirg70RM71WRSjdILPsY5Uv1D42ZpUfaPILDlfactHgsRkw==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.0.tgz", + "integrity": "sha512-arAtTPo76fJ/ICkXWetLCc9EwEHKaeya4vMrReVlEIUCAUncH7M4bhMQ+M9Vf+FFOZJdTNMXNBrWwW+OXWpSew==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.0.tgz", + "integrity": "sha512-Vsm497xFM7tTIPYK9bNTYJyF/lsP590Qc1WxJdlB6ljCbdZKU9SY8i7+Iin4kyhV/KV5J2rOKsBQbB77Ab7L/w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.0.tgz", + "integrity": "sha512-t8GrvnFkiIY7pa7mMgJd7p8p8qqYIz1NYiAoKc75Zyv73L3DZW++oYMSHPRarcotTKuSs6m3hTOa5CKHaS02TQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.0.tgz", + "integrity": "sha512-CKyDpRbK1hXwv79soeTJNHb5EiG6ct3efd/FTPdzOWdbZZfGhpbcqIpiD0+vwmpu0wTIL97ZRPZu8vUt46nBSw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.0.tgz", + "integrity": "sha512-rgtz6flkVkh58od4PwTRqxbKH9cOjaXCMZgWD905JOzjFKW+7EiUObfd/Kav+A6Gyud6WZk9w+xu6QLytdi2OA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.0.tgz", + "integrity": "sha512-6Mtdq5nHggwfDNLAHkPlyLBpE5L6hwsuXZX8XNmHno9JuL2+bg2BX5tRkwjyfn6sKbxZTq68suOjgWqCicvPXA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.0.tgz", + "integrity": "sha512-D3H+xh3/zphoX8ck4S2RxKR6gHlHDXXzOf6f/9dbFt/NRBDIE33+cVa49Kil4WUjxMGW0ZIYBYtaGCa2+OsQwQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.0.tgz", + "integrity": "sha512-gJKIi2IjRo5G6Glxb8d3DzYXlxdEj2NlkixPsqePSZMhLudqPhtZ4BUrpIuTjJYXxvF9njql+vRjB2oaC9XpBw==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.0.tgz", + "integrity": "sha512-TDijPXTOeE3eaMkRYpcy3LarIg13dS9wWHRdwYRnzlwlA370rNdZqbcp0WTyyV/k2zSxfko52+C7jU5F9Tfj1g==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.0.tgz", + "integrity": "sha512-K40ip1LAcA0byL05TbCQ4yJ4swvnbzHscRmUilrmP9Am7//0UjPreh4lpYzvThT2Quw66MhjG//20mrufm40mA==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.0.tgz", + "integrity": "sha512-0mswrYP/9ai+CU0BzBfPMZ8RVm3RGAN/lmOMgW4aFUSOQBjA31UP8Mr6DDhWSuMwj7jaWOT0p0WoZ6jeHhrD7g==", + "cpu": [ + "loong64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.0.tgz", + "integrity": "sha512-hIKvXm0/3w/5+RDtCJeXqMZGkI2s4oMUGj3/jM0QzhgIASWrGO5/RlzAzm5nNh/awHE0A19h/CvHQe6FaBNrRA==", + "cpu": [ + "mips64el" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.0.tgz", + "integrity": "sha512-HcZh5BNq0aC52UoocJxaKORfFODWXZxtBaaZNuN3PUX3MoDsChsZqopzi5UupRhPHSEHotoiptqikjN/B77mYQ==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.0.tgz", + "integrity": "sha512-bEh7dMn/h3QxeR2KTy1DUszQjUrIHPZKyO6aN1X4BCnhfYhuQqedHaa5MxSQA/06j3GpiIlFGSsy1c7Gf9padw==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.0.tgz", + "integrity": "sha512-ZcQ6+qRkw1UcZGPyrCiHHkmBaj9SiCD8Oqd556HldP+QlpUIe2Wgn3ehQGVoPOvZvtHm8HPx+bH20c9pvbkX3g==", + "cpu": [ + "s390x" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.0.tgz", + "integrity": "sha512-vbutsFqQ+foy3wSSbmjBXXIJ6PL3scghJoM8zCL142cGaZKAdCZHyf+Bpu/MmX9zT9Q0zFBVKb36Ma5Fzfa8xA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.0.tgz", + "integrity": "sha512-hjQ0R/ulkO8fCYFsG0FZoH+pWgTTDreqpqY7UnQntnaKv95uP5iW3+dChxnx7C3trQQU40S+OgWhUVwCjVFLvg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.0.tgz", + "integrity": "sha512-MD9uzzkPQbYehwcN583yx3Tu5M8EIoTD+tUgKF982WYL9Pf5rKy9ltgD0eUgs8pvKnmizxjXZyLt0z6DC3rRXg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.0.tgz", + "integrity": "sha512-4ir0aY1NGUhIC1hdoCzr1+5b43mw99uNwVzhIq1OY3QcEwPDO3B7WNXBzaKY5Nsf1+N11i1eOfFcq+D/gOS15Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.0.tgz", + "integrity": "sha512-jVzdzsbM5xrotH+W5f1s+JtUy1UWgjU0Cf4wMvffTB8m6wP5/kx0KiaLHlbJO+dMgtxKV8RQ/JvtlFcdZ1zCPA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.0.tgz", + "integrity": "sha512-iKc8GAslzRpBytO2/aN3d2yb2z8XTVfNV0PjGlCxKo5SgWmNXx82I/Q3aG1tFfS+A2igVCY97TJ8tnYwpUWLCA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.0.tgz", + "integrity": "sha512-vQW36KZolfIudCcTnaTpmLQ24Ha1RjygBo39/aLkM2kmjkWmZGEJ5Gn9l5/7tzXA42QGIoWbICfg6KLLkIw6yw==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.0.tgz", + "integrity": "sha512-7IAFPrjSQIJrGsK6flwg7NFmwBoSTyF3rl7If0hNUFQU4ilTsEPL6GuMuU9BfIWVVGuRnuIidkSMC+c0Otu8IA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@preact/signals": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@preact/signals/-/signals-1.3.0.tgz", + "integrity": "sha512-EOMeg42SlLS72dhoq6Vjq08havnLseWmPQ8A0YsgIAqMgWgx7V1a39+Pxo6i7SY5NwJtH4849JogFq3M67AzWg==", + "license": "MIT", + "dependencies": { + "@preact/signals-core": "^1.7.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + }, + "peerDependencies": { + "preact": "10.x" + } + }, + "node_modules/@preact/signals-core": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/@preact/signals-core/-/signals-core-1.8.0.tgz", + "integrity": "sha512-OBvUsRZqNmjzCZXWLxkZfhcgT+Fk8DDcT/8vD6a1xhDemodyy87UJRJfASMuSD8FaAIeGgGm85ydXhm7lr4fyA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, + "node_modules/esbuild": { + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.0.tgz", + "integrity": "sha512-FuLPevChGDshgSicjisSooU0cemp/sGXR841D5LHMB7mTVOmsEHcAxaH3irL53+8YDIeVNQEySh4DaYU/iuPqQ==", + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.24.0", + "@esbuild/android-arm": "0.24.0", + "@esbuild/android-arm64": "0.24.0", + "@esbuild/android-x64": "0.24.0", + "@esbuild/darwin-arm64": "0.24.0", + "@esbuild/darwin-x64": "0.24.0", + "@esbuild/freebsd-arm64": "0.24.0", + "@esbuild/freebsd-x64": "0.24.0", + "@esbuild/linux-arm": "0.24.0", + "@esbuild/linux-arm64": "0.24.0", + "@esbuild/linux-ia32": "0.24.0", + "@esbuild/linux-loong64": "0.24.0", + "@esbuild/linux-mips64el": "0.24.0", + "@esbuild/linux-ppc64": "0.24.0", + "@esbuild/linux-riscv64": "0.24.0", + "@esbuild/linux-s390x": "0.24.0", + "@esbuild/linux-x64": "0.24.0", + "@esbuild/netbsd-x64": "0.24.0", + "@esbuild/openbsd-arm64": "0.24.0", + "@esbuild/openbsd-x64": "0.24.0", + "@esbuild/sunos-x64": "0.24.0", + "@esbuild/win32-arm64": "0.24.0", + "@esbuild/win32-ia32": "0.24.0", + "@esbuild/win32-x64": "0.24.0" + } + }, + "node_modules/preact": { + "version": "10.24.3", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.24.3.tgz", + "integrity": "sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + } + } +} diff --git a/pkg/goroutineinstance/site/package.json b/pkg/goroutineinstance/site/package.json new file mode 100644 index 0000000..4b5c836 --- /dev/null +++ b/pkg/goroutineinstance/site/package.json @@ -0,0 +1,18 @@ +{ + "name": "site", + "version": "1.0.0", + "type": "module", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "build": "node esbuild.config.js" + }, + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "@preact/signals": "^1.3.0", + "esbuild": "^0.24.0", + "preact": "^10.24.3" + } +} diff --git a/pkg/goroutineinstance/site/src/index.tsx b/pkg/goroutineinstance/site/src/index.tsx new file mode 100644 index 0000000..f9abcd9 --- /dev/null +++ b/pkg/goroutineinstance/site/src/index.tsx @@ -0,0 +1,101 @@ +import {render} from "preact"; +import {useEffect, useState} from "preact/hooks"; +import { Frame, Goroutine } from "./lib/goroutines"; +import { useSignal, useComputed } from "@preact/signals"; + +const FrameView = (props: { frame: Frame }) => { + const {frame} = props + return <> +
+
+ {frame.Func} +
+
+ {frame.File} +
+
+ {frame.Line} +
+
+ + +} + +function Main() { + //const [goroutines, setGoroutines] = useState(undefined) + const goroutines = useSignal([]) + + + const fetchGoroutines = async () => { + const res = await fetch("./raw") + const json = await res.json() + let routines: Goroutine[] = json + routines = routines.map(x=>{ + // divide by 1000000 + x.Wait = Number(BigInt(x.Wait) / BigInt(1000000)) + return x + }) + goroutines.value = routines + } + + useEffect(() => { + fetchGoroutines() + },[]) + + useEffect(() => { + if(!goroutines) { + return + } + console.log(goroutines) + },[goroutines]) + if(!goroutines) { + return <> +
+ fetching +
+ + } + return <> +
+
+
+ length: +
+
+ {goroutines.value.length} +
+
+
+ {goroutines.value.map((x, idx)=>{ + + + return
+
+ {x.ID} +
+
+ {x.Wait} +
+
+ {x.Stack} +
+ {x.CreatedBy && +
+ +
+ } +
+ })} +
+
+ +} + + + +const rootElement = document.getElementById("root") +if(rootElement) { + render(
, rootElement); +}else { + console.error("no root element found") +} diff --git a/pkg/goroutineinstance/site/src/lib/goroutines.ts b/pkg/goroutineinstance/site/src/lib/goroutines.ts new file mode 100644 index 0000000..fd68213 --- /dev/null +++ b/pkg/goroutineinstance/site/src/lib/goroutines.ts @@ -0,0 +1,37 @@ +export interface Frame { + // Func is the name of the function, including package name, e.g. "main.main" + // or "net/http.(*Server).Serve". + Func: string; + // File is the absolute path of source file e.g. + // "/go/src/example.org/example/main.go". + File: string; + // Line is the line number of inside of the source file that was active when + // the sample was taken. + Line: number; +} + +export interface Goroutine { + // ID is the goroutine id (aka `goid`). + ID: number; + // State is the `atomicstatus` of the goroutine, or if "waiting" the + // `waitreason`. + State: string; + // Wait is the approximate duration a goroutine has been waiting or in a + // syscall as determined by the first gc after the wait started. Aka + // `waitsince`. + Wait: number; + // LockedToThread is true if the goroutine is locked by a thread, aka + // `lockedm`. + LockedToThread: boolean; + // Stack is the stack trace of the goroutine. + Stack: Frame[]; + // FramesElided is true if the stack trace contains a message indicating that + // additional frames were elided. This happens when the stack depth exceeds + // 100. + FramesElided: boolean; + // CreatedBy is the frame that created this goroutine, nil for main(). + CreatedBy: Frame | null; + // Ancestors are the Goroutines that created this goroutine. + // See GODEBUG=tracebackancestors=n in https://pkg.go.dev/runtime. + Ancestor?: Goroutine; // The `json:"Ancestor,omitempty"` tag is represented by the optional `?` in TypeScript +} diff --git a/pkg/goroutineinstance/site/tsconfig.json b/pkg/goroutineinstance/site/tsconfig.json new file mode 100644 index 0000000..fd522f0 --- /dev/null +++ b/pkg/goroutineinstance/site/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "preact", + "lib": [ + "esnext" + ], + "plugins": [ + { + "transform": "typia/lib/transform" + } + ], + "strictNullChecks": true, + "strict": true + } +} \ No newline at end of file diff --git a/pkg/pprofweb/pprofweb.go b/pkg/pprofweb/pprofweb.go index 7af136b..bbb8fee 100644 --- a/pkg/pprofweb/pprofweb.go +++ b/pkg/pprofweb/pprofweb.go @@ -56,6 +56,16 @@ func (s *Server) HandleHTTP() func(chi.Router) { r.HandleFunc("/*", s.ServeProfileInstance) }) }) + r.Route("/static/goroutine", func(r chi.Router) { + r.Get("/bundle.js", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/javascript") + w.Write(goroutineinstance.BundleJsEmbed) + }) + r.Get("/bundle.js.map", func(w http.ResponseWriter, r *http.Request) { + w.Write(goroutineinstance.BundleJsMapEmbed) + }) + + }) r.Route("/goroutine", func(r chi.Router) { r.Route("/{xid}", func(r chi.Router) { r.HandleFunc("/", s.ServeGoroutineInstance)