88 "fmt"
99 "log"
1010 "os"
11- "strconv"
1211
1312 "runtime"
1413 "sync"
@@ -247,6 +246,21 @@ func startupActivityUpdate(firstLaunch bool) {
247246 shellType = "error"
248247 shellVersion = ""
249248 }
249+ userSetOnce := & telemetrydata.TEventUserProps {
250+ ClientInitialVersion : "v" + WaveVersion ,
251+ }
252+ tosTs := telemetry .GetTosAgreedTs ()
253+ var cohortTime time.Time
254+ if tosTs > 0 {
255+ cohortTime = time .UnixMilli (tosTs )
256+ } else {
257+ cohortTime = time .Now ()
258+ }
259+ cohortMonth := cohortTime .Format ("2006-01" )
260+ year , week := cohortTime .ISOWeek ()
261+ cohortISOWeek := fmt .Sprintf ("%04d-W%02d" , year , week )
262+ userSetOnce .CohortMonth = cohortMonth
263+ userSetOnce .CohortISOWeek = cohortISOWeek
250264 props := telemetrydata.TEventProps {
251265 UserSet : & telemetrydata.TEventUserProps {
252266 ClientVersion : "v" + WaveVersion ,
@@ -259,9 +273,7 @@ func startupActivityUpdate(firstLaunch bool) {
259273 LocalShellType : shellType ,
260274 LocalShellVersion : shellVersion ,
261275 },
262- UserSetOnce : & telemetrydata.TEventUserProps {
263- ClientInitialVersion : "v" + WaveVersion ,
264- },
276+ UserSetOnce : userSetOnce ,
265277 }
266278 if firstLaunch {
267279 props .AppFirstLaunch = true
@@ -339,18 +351,19 @@ func clearTempFiles() error {
339351 return nil
340352}
341353
342- func maybeStartPprofServer () error {
343- pprofPortStr := os .Getenv ("WAVETERM_PPROFPORT" )
344- if pprofPortStr == "" {
345- return nil
354+ func maybeStartPprofServer () {
355+ settings := wconfig .GetWatcher ().GetFullConfig ().Settings
356+ if settings .DebugPprofMemProfileRate != nil {
357+ runtime .MemProfileRate = * settings .DebugPprofMemProfileRate
358+ log .Printf ("set runtime.MemProfileRate to %d\n " , runtime .MemProfileRate )
346359 }
347- defer os .Unsetenv ("WAVETERM_PPROFPORT" )
348- pprofPort , err := strconv .Atoi (pprofPortStr )
349- if err != nil {
350- return fmt .Errorf ("invalid WAVETERM_PPROFPORT value '%s': %v" , pprofPortStr , err )
360+ if settings .DebugPprofPort == nil {
361+ return
351362 }
363+ pprofPort := * settings .DebugPprofPort
352364 if pprofPort < 1 || pprofPort > 65535 {
353- return fmt .Errorf ("WAVETERM_PPROFPORT must be between 1 and 65535, got %d" , pprofPort )
365+ log .Printf ("[error] debug:pprofport must be between 1 and 65535, got %d\n " , pprofPort )
366+ return
354367 }
355368 go func () {
356369 addr := fmt .Sprintf ("localhost:%d" , pprofPort )
@@ -359,22 +372,15 @@ func maybeStartPprofServer() error {
359372 log .Printf ("[error] pprof server failed: %v\n " , err )
360373 }
361374 }()
362- return nil
363375}
364376
365377func main () {
366- err := maybeStartPprofServer ()
367- if err != nil {
368- log .Printf ("[error] %v\n " , err )
369- return
370- }
371-
372378 log .SetFlags (log .LstdFlags | log .Lmicroseconds )
373379 log .SetPrefix ("[wavesrv] " )
374380 wavebase .WaveVersion = WaveVersion
375381 wavebase .BuildTime = BuildTime
376382
377- err = grabAndRemoveEnvVars ()
383+ err : = grabAndRemoveEnvVars ()
378384 if err != nil {
379385 log .Printf ("[error] %v\n " , err )
380386 return
@@ -463,6 +469,7 @@ func main() {
463469 sigutil .InstallShutdownSignalHandlers (doShutdown )
464470 sigutil .InstallSIGUSR1Handler ()
465471 startConfigWatcher ()
472+ maybeStartPprofServer ()
466473 go stdinReadWatch ()
467474 go telemetryLoop ()
468475 go updateTelemetryCountsLoop ()
0 commit comments