@grafana/scenes 6.34.0 → 6.35.0--canary.1240.17499066940.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -137,21 +137,21 @@ class UserActionEvent extends data.BusEventWithPayload {
137
137
  }
138
138
  UserActionEvent.type = "scene-object-user-action";
139
139
 
140
- var __typeError$4 = (msg) => {
140
+ var __typeError$5 = (msg) => {
141
141
  throw TypeError(msg);
142
142
  };
143
- var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
144
- var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
145
- var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
146
- var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
143
+ var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
144
+ var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
145
+ var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
146
+ var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
147
147
  var _ref;
148
148
  class SceneObjectRef {
149
149
  constructor(ref) {
150
- __privateAdd$4(this, _ref);
151
- __privateSet$4(this, _ref, ref);
150
+ __privateAdd$5(this, _ref);
151
+ __privateSet$5(this, _ref, ref);
152
152
  }
153
153
  resolve() {
154
- return __privateGet$4(this, _ref);
154
+ return __privateGet$5(this, _ref);
155
155
  }
156
156
  }
157
157
  _ref = new WeakMap();
@@ -600,13 +600,359 @@ function writeSceneLog(logger, message, ...rest) {
600
600
  }
601
601
  }
602
602
 
603
+ var __typeError$4 = (msg) => {
604
+ throw TypeError(msg);
605
+ };
606
+ var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
607
+ var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
608
+ var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
609
+ var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
610
+ var _profileInProgress$1, _profileStartTs, _trailAnimationFrameId, _recordedTrailingSpans, _visibilityChangeHandler;
611
+ const POST_STORM_WINDOW = 2e3;
612
+ const SPAN_THRESHOLD = 30;
613
+ const TAB_INACTIVE_THRESHOLD = 1e3;
614
+ class SceneRenderProfiler {
615
+ constructor(queryController) {
616
+ this.queryController = queryController;
617
+ __privateAdd$4(this, _profileInProgress$1, null);
618
+ __privateAdd$4(this, _profileStartTs, null);
619
+ __privateAdd$4(this, _trailAnimationFrameId, null);
620
+ // Will keep measured lengths trailing frames
621
+ __privateAdd$4(this, _recordedTrailingSpans, []);
622
+ __privateAdd$4(this, _visibilityChangeHandler, null);
623
+ this.measureTrailingFrames = (measurementStartTs, lastFrameTime, profileStartTs) => {
624
+ var _a;
625
+ const currentFrameTime = performance.now();
626
+ const frameLength = currentFrameTime - lastFrameTime;
627
+ if (frameLength > TAB_INACTIVE_THRESHOLD) {
628
+ writeSceneLog("SceneRenderProfiler", "Tab was inactive, cancelling profile measurement");
629
+ this.cancelProfile();
630
+ return;
631
+ }
632
+ __privateGet$4(this, _recordedTrailingSpans).push(frameLength);
633
+ if (currentFrameTime - measurementStartTs < POST_STORM_WINDOW) {
634
+ if (__privateGet$4(this, _profileInProgress$1)) {
635
+ __privateSet$4(this, _trailAnimationFrameId, requestAnimationFrame(
636
+ () => this.measureTrailingFrames(measurementStartTs, currentFrameTime, profileStartTs)
637
+ ));
638
+ }
639
+ } else {
640
+ const slowFrames = processRecordedSpans(__privateGet$4(this, _recordedTrailingSpans));
641
+ const slowFramesTime = slowFrames.reduce((acc, val) => acc + val, 0);
642
+ writeSceneLog(
643
+ this.constructor.name,
644
+ "Profile tail recorded, slow frames duration:",
645
+ slowFramesTime,
646
+ slowFrames,
647
+ __privateGet$4(this, _profileInProgress$1)
648
+ );
649
+ __privateSet$4(this, _recordedTrailingSpans, []);
650
+ const profileDuration = measurementStartTs - profileStartTs;
651
+ writeSceneLog(
652
+ this.constructor.name,
653
+ "Stoped recording, total measured time (network included):",
654
+ profileDuration + slowFramesTime
655
+ );
656
+ __privateSet$4(this, _trailAnimationFrameId, null);
657
+ const profileEndTs = profileStartTs + profileDuration + slowFramesTime;
658
+ if (!__privateGet$4(this, _profileInProgress$1)) {
659
+ return;
660
+ }
661
+ performance.measure(`DashboardInteraction ${__privateGet$4(this, _profileInProgress$1).origin}`, {
662
+ start: profileStartTs,
663
+ end: profileEndTs
664
+ });
665
+ const networkDuration = captureNetwork(profileStartTs, profileEndTs);
666
+ if (((_a = this.queryController) == null ? void 0 : _a.state.onProfileComplete) && __privateGet$4(this, _profileInProgress$1)) {
667
+ this.queryController.state.onProfileComplete({
668
+ origin: __privateGet$4(this, _profileInProgress$1).origin,
669
+ crumbs: __privateGet$4(this, _profileInProgress$1).crumbs,
670
+ duration: profileDuration + slowFramesTime,
671
+ networkDuration,
672
+ startTs: profileStartTs,
673
+ endTs: profileEndTs,
674
+ // @ts-ignore
675
+ jsHeapSizeLimit: performance.memory ? performance.memory.jsHeapSizeLimit : 0,
676
+ // @ts-ignore
677
+ usedJSHeapSize: performance.memory ? performance.memory.usedJSHeapSize : 0,
678
+ // @ts-ignore
679
+ totalJSHeapSize: performance.memory ? performance.memory.totalJSHeapSize : 0
680
+ });
681
+ __privateSet$4(this, _profileInProgress$1, null);
682
+ __privateSet$4(this, _trailAnimationFrameId, null);
683
+ }
684
+ if (window.__runs) {
685
+ window.__runs += `${Date.now()}, ${profileDuration + slowFramesTime}
686
+ `;
687
+ } else {
688
+ window.__runs = `${Date.now()}, ${profileDuration + slowFramesTime}
689
+ `;
690
+ }
691
+ }
692
+ };
693
+ this.setupVisibilityChangeHandler();
694
+ }
695
+ setQueryController(queryController) {
696
+ this.queryController = queryController;
697
+ }
698
+ setupVisibilityChangeHandler() {
699
+ if (__privateGet$4(this, _visibilityChangeHandler)) {
700
+ return;
701
+ }
702
+ __privateSet$4(this, _visibilityChangeHandler, () => {
703
+ if (document.hidden && __privateGet$4(this, _profileInProgress$1)) {
704
+ writeSceneLog("SceneRenderProfiler", "Tab became inactive, cancelling profile");
705
+ this.cancelProfile();
706
+ }
707
+ });
708
+ if (typeof document !== "undefined") {
709
+ document.addEventListener("visibilitychange", __privateGet$4(this, _visibilityChangeHandler));
710
+ }
711
+ }
712
+ cleanup() {
713
+ if (__privateGet$4(this, _visibilityChangeHandler) && typeof document !== "undefined") {
714
+ document.removeEventListener("visibilitychange", __privateGet$4(this, _visibilityChangeHandler));
715
+ __privateSet$4(this, _visibilityChangeHandler, null);
716
+ }
717
+ this.cancelProfile();
718
+ }
719
+ startProfile(name) {
720
+ if (document.hidden) {
721
+ writeSceneLog("SceneRenderProfiler", "Tab is inactive, skipping profile", name);
722
+ return;
723
+ }
724
+ if (__privateGet$4(this, _profileInProgress$1)) {
725
+ if (__privateGet$4(this, _trailAnimationFrameId)) {
726
+ this.cancelProfile();
727
+ this._startNewProfile(name, true);
728
+ } else {
729
+ this.addCrumb(name);
730
+ }
731
+ } else {
732
+ this._startNewProfile(name);
733
+ }
734
+ }
735
+ /**
736
+ * Starts a new profile for performance measurement.
737
+ *
738
+ * @param name - The origin/trigger of the profile (e.g., 'time_range_change', 'variable_value_changed')
739
+ * @param force - Whether this is a "forced" profile (true) or "clean" profile (false)
740
+ * - "forced": Started by canceling an existing profile that was recording trailing frames
741
+ * This happens when a new user interaction occurs before the previous one
742
+ * finished measuring its performance impact
743
+ * - "clean": Started when no profile is currently active
744
+ */
745
+ _startNewProfile(name, force = false) {
746
+ __privateSet$4(this, _profileInProgress$1, { origin: name, crumbs: [] });
747
+ __privateSet$4(this, _profileStartTs, performance.now());
748
+ writeSceneLog(
749
+ "SceneRenderProfiler",
750
+ `Profile started[${force ? "forced" : "clean"}]`,
751
+ __privateGet$4(this, _profileInProgress$1),
752
+ __privateGet$4(this, _profileStartTs)
753
+ );
754
+ }
755
+ recordProfileTail(measurementStartTime, profileStartTs) {
756
+ __privateSet$4(this, _trailAnimationFrameId, requestAnimationFrame(
757
+ () => this.measureTrailingFrames(measurementStartTime, measurementStartTime, profileStartTs)
758
+ ));
759
+ }
760
+ tryCompletingProfile() {
761
+ var _a;
762
+ writeSceneLog("SceneRenderProfiler", "Trying to complete profile", __privateGet$4(this, _profileInProgress$1));
763
+ if (((_a = this.queryController) == null ? void 0 : _a.runningQueriesCount()) === 0 && __privateGet$4(this, _profileInProgress$1)) {
764
+ writeSceneLog("SceneRenderProfiler", "All queries completed, stopping profile");
765
+ this.recordProfileTail(performance.now(), __privateGet$4(this, _profileStartTs));
766
+ }
767
+ }
768
+ isTailRecording() {
769
+ return Boolean(__privateGet$4(this, _trailAnimationFrameId));
770
+ }
771
+ cancelTailRecording() {
772
+ if (__privateGet$4(this, _trailAnimationFrameId)) {
773
+ cancelAnimationFrame(__privateGet$4(this, _trailAnimationFrameId));
774
+ __privateSet$4(this, _trailAnimationFrameId, null);
775
+ writeSceneLog("SceneRenderProfiler", "Cancelled recording frames, new profile started");
776
+ }
777
+ }
778
+ // cancel profile
779
+ cancelProfile() {
780
+ if (__privateGet$4(this, _profileInProgress$1)) {
781
+ writeSceneLog("SceneRenderProfiler", "Cancelling profile", __privateGet$4(this, _profileInProgress$1));
782
+ __privateSet$4(this, _profileInProgress$1, null);
783
+ if (__privateGet$4(this, _trailAnimationFrameId)) {
784
+ cancelAnimationFrame(__privateGet$4(this, _trailAnimationFrameId));
785
+ __privateSet$4(this, _trailAnimationFrameId, null);
786
+ }
787
+ __privateSet$4(this, _recordedTrailingSpans, []);
788
+ }
789
+ }
790
+ addCrumb(crumb) {
791
+ if (__privateGet$4(this, _profileInProgress$1)) {
792
+ writeSceneLog("SceneRenderProfiler", "Adding crumb:", crumb);
793
+ __privateGet$4(this, _profileInProgress$1).crumbs.push(crumb);
794
+ }
795
+ }
796
+ }
797
+ _profileInProgress$1 = new WeakMap();
798
+ _profileStartTs = new WeakMap();
799
+ _trailAnimationFrameId = new WeakMap();
800
+ _recordedTrailingSpans = new WeakMap();
801
+ _visibilityChangeHandler = new WeakMap();
802
+ function processRecordedSpans(spans) {
803
+ for (let i = spans.length - 1; i >= 0; i--) {
804
+ if (spans[i] > SPAN_THRESHOLD) {
805
+ return spans.slice(0, i + 1);
806
+ }
807
+ }
808
+ return [spans[0]];
809
+ }
810
+ function captureNetwork(startTs, endTs) {
811
+ const entries = performance.getEntriesByType("resource");
812
+ performance.clearResourceTimings();
813
+ const networkEntries = entries.filter(
814
+ (entry) => entry.startTime >= startTs && entry.startTime <= endTs && entry.responseEnd >= startTs && entry.responseEnd <= endTs
815
+ );
816
+ for (const entry of networkEntries) {
817
+ performance.measure("Network entry " + entry.name, {
818
+ start: entry.startTime,
819
+ end: entry.responseEnd
820
+ });
821
+ }
822
+ return calculateNetworkTime(networkEntries);
823
+ }
824
+ function calculateNetworkTime(requests) {
825
+ if (requests.length === 0) {
826
+ return 0;
827
+ }
828
+ requests.sort((a, b) => a.startTime - b.startTime);
829
+ let totalNetworkTime = 0;
830
+ let currentStart = requests[0].startTime;
831
+ let currentEnd = requests[0].responseEnd;
832
+ for (let i = 1; i < requests.length; i++) {
833
+ if (requests[i].startTime <= currentEnd) {
834
+ currentEnd = Math.max(currentEnd, requests[i].responseEnd);
835
+ } else {
836
+ totalNetworkTime += currentEnd - currentStart;
837
+ currentStart = requests[i].startTime;
838
+ currentEnd = requests[i].responseEnd;
839
+ }
840
+ }
841
+ totalNetworkTime += currentEnd - currentStart;
842
+ return totalNetworkTime;
843
+ }
844
+ const REFRESH_INTERACTION = "refresh";
845
+ const TIME_RANGE_CHANGE_INTERACTION = "time_range_change";
846
+ const FILTER_REMOVED_INTERACTION = "filter_removed";
847
+ const FILTER_CHANGED_INTERACTION = "filter_changed";
848
+ const FILTER_RESTORED_INTERACTION = "filter_restored";
849
+ const VARIABLE_VALUE_CHANGED_INTERACTION = "variable_value_changed";
850
+ const SCOPES_CHANGED_INTERACTION = "scopes_changed";
851
+
603
852
  var __typeError$3 = (msg) => {
604
853
  throw TypeError(msg);
605
854
  };
606
855
  var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
607
- var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
856
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), member.get(obj));
608
857
  var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
609
858
  var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
859
+ var _profileInProgress;
860
+ function isInteractionProfiler(obj) {
861
+ return obj && typeof obj === "object" && "isInteractionProfiler" in obj;
862
+ }
863
+ class SceneInteractionProfiler extends SceneObjectBase {
864
+ constructor() {
865
+ super(...arguments);
866
+ this.isInteractionProfiler = true;
867
+ __privateAdd$3(this, _profileInProgress, null);
868
+ }
869
+ startProfile(interaction) {
870
+ if (!this.state.enableProfiling) {
871
+ return;
872
+ }
873
+ if (__privateGet$3(this, _profileInProgress)) {
874
+ this.cancelProfile();
875
+ }
876
+ __privateSet$3(this, _profileInProgress, {
877
+ interaction,
878
+ startTs: performance.now()
879
+ });
880
+ writeSceneLog("SceneInteractionProfiler", "Started profiling interaction:", interaction);
881
+ }
882
+ stopProfile() {
883
+ if (!__privateGet$3(this, _profileInProgress)) {
884
+ return;
885
+ }
886
+ const endTs = performance.now();
887
+ const interactionDuration = endTs - __privateGet$3(this, _profileInProgress).startTs;
888
+ const networkDuration = captureNetwork(__privateGet$3(this, _profileInProgress).startTs, endTs);
889
+ const result = {
890
+ interaction: __privateGet$3(this, _profileInProgress).interaction,
891
+ interactionDuration,
892
+ networkDuration,
893
+ startTs: __privateGet$3(this, _profileInProgress).startTs,
894
+ endTs
895
+ };
896
+ writeSceneLog("SceneInteractionProfiler", "Completed profile:", result);
897
+ if (this.state.onProfileComplete) {
898
+ this.state.onProfileComplete(result);
899
+ }
900
+ performance.mark(`${__privateGet$3(this, _profileInProgress).interaction}_start`, {
901
+ startTime: __privateGet$3(this, _profileInProgress).startTs
902
+ });
903
+ performance.mark(`${__privateGet$3(this, _profileInProgress).interaction}_end`, {
904
+ startTime: endTs
905
+ });
906
+ performance.measure(
907
+ `Interaction_${__privateGet$3(this, _profileInProgress).interaction}`,
908
+ `${__privateGet$3(this, _profileInProgress).interaction}_start`,
909
+ `${__privateGet$3(this, _profileInProgress).interaction}_end`
910
+ );
911
+ __privateSet$3(this, _profileInProgress, null);
912
+ }
913
+ cancelProfile() {
914
+ if (__privateGet$3(this, _profileInProgress)) {
915
+ writeSceneLog("SceneInteractionProfiler", "Cancelled profile:", __privateGet$3(this, _profileInProgress).interaction);
916
+ __privateSet$3(this, _profileInProgress, null);
917
+ }
918
+ }
919
+ isProfileActive() {
920
+ return __privateGet$3(this, _profileInProgress) !== null;
921
+ }
922
+ getCurrentInteraction() {
923
+ var _a, _b;
924
+ return (_b = (_a = __privateGet$3(this, _profileInProgress)) == null ? void 0 : _a.interaction) != null ? _b : null;
925
+ }
926
+ }
927
+ _profileInProgress = new WeakMap();
928
+ const USER_INTERACTIONS = {
929
+ ADHOC_KEYS_DROPDOWN: "adhoc_keys_dropdown",
930
+ ADHOC_VALUES_DROPDOWN: "adhoc_values_dropdown",
931
+ GROUPBY_DROPDOWN: "groupby_dropdown"
932
+ };
933
+
934
+ function getInteractionProfiler(sceneObject) {
935
+ let parent = sceneObject;
936
+ while (parent) {
937
+ if (parent.state.$behaviors) {
938
+ for (const behavior of parent.state.$behaviors) {
939
+ if (isInteractionProfiler(behavior)) {
940
+ return behavior;
941
+ }
942
+ }
943
+ }
944
+ parent = parent.parent;
945
+ }
946
+ return void 0;
947
+ }
948
+
949
+ var __typeError$2 = (msg) => {
950
+ throw TypeError(msg);
951
+ };
952
+ var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
953
+ var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
954
+ var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
955
+ var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
610
956
  var _running, _tryCompleteProfileFrameId;
611
957
  function isQueryController(s) {
612
958
  return "isQueryController" in s;
@@ -616,10 +962,10 @@ class SceneQueryController extends SceneObjectBase {
616
962
  super({ ...state, isRunning: false });
617
963
  this.profiler = profiler;
618
964
  this.isQueryController = true;
619
- __privateAdd$3(this, _running, /* @__PURE__ */ new Set());
620
- __privateAdd$3(this, _tryCompleteProfileFrameId, null);
965
+ __privateAdd$2(this, _running, /* @__PURE__ */ new Set());
966
+ __privateAdd$2(this, _tryCompleteProfileFrameId, null);
621
967
  this.runningQueriesCount = () => {
622
- return __privateGet$3(this, _running).size;
968
+ return __privateGet$2(this, _running).size;
623
969
  };
624
970
  if (profiler) {
625
971
  this.profiler = profiler;
@@ -628,7 +974,7 @@ class SceneQueryController extends SceneObjectBase {
628
974
  this.addActivationHandler(() => {
629
975
  var _a;
630
976
  (_a = this.profiler) == null ? void 0 : _a.setQueryController(this);
631
- return () => __privateGet$3(this, _running).clear();
977
+ return () => __privateGet$2(this, _running).clear();
632
978
  });
633
979
  }
634
980
  startProfile(name) {
@@ -643,19 +989,19 @@ class SceneQueryController extends SceneObjectBase {
643
989
  (_a = this.profiler) == null ? void 0 : _a.cancelProfile();
644
990
  }
645
991
  queryStarted(entry) {
646
- __privateGet$3(this, _running).add(entry);
992
+ __privateGet$2(this, _running).add(entry);
647
993
  this.changeRunningQueryCount(1, entry);
648
994
  if (!this.state.isRunning) {
649
995
  this.setState({ isRunning: true });
650
996
  }
651
997
  }
652
998
  queryCompleted(entry) {
653
- if (!__privateGet$3(this, _running).has(entry)) {
999
+ if (!__privateGet$2(this, _running).has(entry)) {
654
1000
  return;
655
1001
  }
656
- __privateGet$3(this, _running).delete(entry);
1002
+ __privateGet$2(this, _running).delete(entry);
657
1003
  this.changeRunningQueryCount(-1);
658
- if (__privateGet$3(this, _running).size === 0) {
1004
+ if (__privateGet$2(this, _running).size === 0) {
659
1005
  this.setState({ isRunning: false });
660
1006
  }
661
1007
  }
@@ -672,10 +1018,10 @@ class SceneQueryController extends SceneObjectBase {
672
1018
  }
673
1019
  }
674
1020
  if (this.state.enableProfiling) {
675
- if (__privateGet$3(this, _tryCompleteProfileFrameId)) {
676
- cancelAnimationFrame(__privateGet$3(this, _tryCompleteProfileFrameId));
1021
+ if (__privateGet$2(this, _tryCompleteProfileFrameId)) {
1022
+ cancelAnimationFrame(__privateGet$2(this, _tryCompleteProfileFrameId));
677
1023
  }
678
- __privateSet$3(this, _tryCompleteProfileFrameId, requestAnimationFrame(() => {
1024
+ __privateSet$2(this, _tryCompleteProfileFrameId, requestAnimationFrame(() => {
679
1025
  var _a2;
680
1026
  (_a2 = this.profiler) == null ? void 0 : _a2.tryCompletingProfile();
681
1027
  }));
@@ -683,7 +1029,7 @@ class SceneQueryController extends SceneObjectBase {
683
1029
  }
684
1030
  cancelAll() {
685
1031
  var _a;
686
- for (const entry of __privateGet$3(this, _running).values()) {
1032
+ for (const entry of __privateGet$2(this, _running).values()) {
687
1033
  (_a = entry.cancel) == null ? void 0 : _a.call(entry);
688
1034
  }
689
1035
  }
@@ -853,255 +1199,6 @@ function isValid$1(value, roundUp, timeZone) {
853
1199
  return parsed.isValid();
854
1200
  }
855
1201
 
856
- var __typeError$2 = (msg) => {
857
- throw TypeError(msg);
858
- };
859
- var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
860
- var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
861
- var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
862
- var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
863
- var _profileInProgress, _profileStartTs, _trailAnimationFrameId, _recordedTrailingSpans, _visibilityChangeHandler;
864
- const POST_STORM_WINDOW = 2e3;
865
- const SPAN_THRESHOLD = 30;
866
- const TAB_INACTIVE_THRESHOLD = 1e3;
867
- class SceneRenderProfiler {
868
- constructor(queryController) {
869
- this.queryController = queryController;
870
- __privateAdd$2(this, _profileInProgress, null);
871
- __privateAdd$2(this, _profileStartTs, null);
872
- __privateAdd$2(this, _trailAnimationFrameId, null);
873
- // Will keep measured lengths trailing frames
874
- __privateAdd$2(this, _recordedTrailingSpans, []);
875
- __privateAdd$2(this, _visibilityChangeHandler, null);
876
- this.measureTrailingFrames = (measurementStartTs, lastFrameTime, profileStartTs) => {
877
- var _a;
878
- const currentFrameTime = performance.now();
879
- const frameLength = currentFrameTime - lastFrameTime;
880
- if (frameLength > TAB_INACTIVE_THRESHOLD) {
881
- writeSceneLog("SceneRenderProfiler", "Tab was inactive, cancelling profile measurement");
882
- this.cancelProfile();
883
- return;
884
- }
885
- __privateGet$2(this, _recordedTrailingSpans).push(frameLength);
886
- if (currentFrameTime - measurementStartTs < POST_STORM_WINDOW) {
887
- if (__privateGet$2(this, _profileInProgress)) {
888
- __privateSet$2(this, _trailAnimationFrameId, requestAnimationFrame(
889
- () => this.measureTrailingFrames(measurementStartTs, currentFrameTime, profileStartTs)
890
- ));
891
- }
892
- } else {
893
- const slowFrames = processRecordedSpans(__privateGet$2(this, _recordedTrailingSpans));
894
- const slowFramesTime = slowFrames.reduce((acc, val) => acc + val, 0);
895
- writeSceneLog(
896
- this.constructor.name,
897
- "Profile tail recorded, slow frames duration:",
898
- slowFramesTime,
899
- slowFrames,
900
- __privateGet$2(this, _profileInProgress)
901
- );
902
- __privateSet$2(this, _recordedTrailingSpans, []);
903
- const profileDuration = measurementStartTs - profileStartTs;
904
- writeSceneLog(
905
- this.constructor.name,
906
- "Stoped recording, total measured time (network included):",
907
- profileDuration + slowFramesTime
908
- );
909
- __privateSet$2(this, _trailAnimationFrameId, null);
910
- const profileEndTs = profileStartTs + profileDuration + slowFramesTime;
911
- if (!__privateGet$2(this, _profileInProgress)) {
912
- return;
913
- }
914
- performance.measure(`DashboardInteraction ${__privateGet$2(this, _profileInProgress).origin}`, {
915
- start: profileStartTs,
916
- end: profileEndTs
917
- });
918
- const networkDuration = captureNetwork(profileStartTs, profileEndTs);
919
- if (((_a = this.queryController) == null ? void 0 : _a.state.onProfileComplete) && __privateGet$2(this, _profileInProgress)) {
920
- this.queryController.state.onProfileComplete({
921
- origin: __privateGet$2(this, _profileInProgress).origin,
922
- crumbs: __privateGet$2(this, _profileInProgress).crumbs,
923
- duration: profileDuration + slowFramesTime,
924
- networkDuration,
925
- startTs: profileStartTs,
926
- endTs: profileEndTs,
927
- // @ts-ignore
928
- jsHeapSizeLimit: performance.memory ? performance.memory.jsHeapSizeLimit : 0,
929
- // @ts-ignore
930
- usedJSHeapSize: performance.memory ? performance.memory.usedJSHeapSize : 0,
931
- // @ts-ignore
932
- totalJSHeapSize: performance.memory ? performance.memory.totalJSHeapSize : 0
933
- });
934
- __privateSet$2(this, _profileInProgress, null);
935
- __privateSet$2(this, _trailAnimationFrameId, null);
936
- }
937
- if (window.__runs) {
938
- window.__runs += `${Date.now()}, ${profileDuration + slowFramesTime}
939
- `;
940
- } else {
941
- window.__runs = `${Date.now()}, ${profileDuration + slowFramesTime}
942
- `;
943
- }
944
- }
945
- };
946
- this.setupVisibilityChangeHandler();
947
- }
948
- setQueryController(queryController) {
949
- this.queryController = queryController;
950
- }
951
- setupVisibilityChangeHandler() {
952
- if (__privateGet$2(this, _visibilityChangeHandler)) {
953
- return;
954
- }
955
- __privateSet$2(this, _visibilityChangeHandler, () => {
956
- if (document.hidden && __privateGet$2(this, _profileInProgress)) {
957
- writeSceneLog("SceneRenderProfiler", "Tab became inactive, cancelling profile");
958
- this.cancelProfile();
959
- }
960
- });
961
- if (typeof document !== "undefined") {
962
- document.addEventListener("visibilitychange", __privateGet$2(this, _visibilityChangeHandler));
963
- }
964
- }
965
- cleanup() {
966
- if (__privateGet$2(this, _visibilityChangeHandler) && typeof document !== "undefined") {
967
- document.removeEventListener("visibilitychange", __privateGet$2(this, _visibilityChangeHandler));
968
- __privateSet$2(this, _visibilityChangeHandler, null);
969
- }
970
- this.cancelProfile();
971
- }
972
- startProfile(name) {
973
- if (document.hidden) {
974
- writeSceneLog("SceneRenderProfiler", "Tab is inactive, skipping profile", name);
975
- return;
976
- }
977
- if (__privateGet$2(this, _profileInProgress)) {
978
- if (__privateGet$2(this, _trailAnimationFrameId)) {
979
- this.cancelProfile();
980
- this._startNewProfile(name, true);
981
- } else {
982
- this.addCrumb(name);
983
- }
984
- } else {
985
- this._startNewProfile(name);
986
- }
987
- }
988
- /**
989
- * Starts a new profile for performance measurement.
990
- *
991
- * @param name - The origin/trigger of the profile (e.g., 'time_range_change', 'variable_value_changed')
992
- * @param force - Whether this is a "forced" profile (true) or "clean" profile (false)
993
- * - "forced": Started by canceling an existing profile that was recording trailing frames
994
- * This happens when a new user interaction occurs before the previous one
995
- * finished measuring its performance impact
996
- * - "clean": Started when no profile is currently active
997
- */
998
- _startNewProfile(name, force = false) {
999
- __privateSet$2(this, _profileInProgress, { origin: name, crumbs: [] });
1000
- __privateSet$2(this, _profileStartTs, performance.now());
1001
- writeSceneLog(
1002
- "SceneRenderProfiler",
1003
- `Profile started[${force ? "forced" : "clean"}]`,
1004
- __privateGet$2(this, _profileInProgress),
1005
- __privateGet$2(this, _profileStartTs)
1006
- );
1007
- }
1008
- recordProfileTail(measurementStartTime, profileStartTs) {
1009
- __privateSet$2(this, _trailAnimationFrameId, requestAnimationFrame(
1010
- () => this.measureTrailingFrames(measurementStartTime, measurementStartTime, profileStartTs)
1011
- ));
1012
- }
1013
- tryCompletingProfile() {
1014
- var _a;
1015
- writeSceneLog("SceneRenderProfiler", "Trying to complete profile", __privateGet$2(this, _profileInProgress));
1016
- if (((_a = this.queryController) == null ? void 0 : _a.runningQueriesCount()) === 0 && __privateGet$2(this, _profileInProgress)) {
1017
- writeSceneLog("SceneRenderProfiler", "All queries completed, stopping profile");
1018
- this.recordProfileTail(performance.now(), __privateGet$2(this, _profileStartTs));
1019
- }
1020
- }
1021
- isTailRecording() {
1022
- return Boolean(__privateGet$2(this, _trailAnimationFrameId));
1023
- }
1024
- cancelTailRecording() {
1025
- if (__privateGet$2(this, _trailAnimationFrameId)) {
1026
- cancelAnimationFrame(__privateGet$2(this, _trailAnimationFrameId));
1027
- __privateSet$2(this, _trailAnimationFrameId, null);
1028
- writeSceneLog("SceneRenderProfiler", "Cancelled recording frames, new profile started");
1029
- }
1030
- }
1031
- // cancel profile
1032
- cancelProfile() {
1033
- if (__privateGet$2(this, _profileInProgress)) {
1034
- writeSceneLog("SceneRenderProfiler", "Cancelling profile", __privateGet$2(this, _profileInProgress));
1035
- __privateSet$2(this, _profileInProgress, null);
1036
- if (__privateGet$2(this, _trailAnimationFrameId)) {
1037
- cancelAnimationFrame(__privateGet$2(this, _trailAnimationFrameId));
1038
- __privateSet$2(this, _trailAnimationFrameId, null);
1039
- }
1040
- __privateSet$2(this, _recordedTrailingSpans, []);
1041
- }
1042
- }
1043
- addCrumb(crumb) {
1044
- if (__privateGet$2(this, _profileInProgress)) {
1045
- writeSceneLog("SceneRenderProfiler", "Adding crumb:", crumb);
1046
- __privateGet$2(this, _profileInProgress).crumbs.push(crumb);
1047
- }
1048
- }
1049
- }
1050
- _profileInProgress = new WeakMap();
1051
- _profileStartTs = new WeakMap();
1052
- _trailAnimationFrameId = new WeakMap();
1053
- _recordedTrailingSpans = new WeakMap();
1054
- _visibilityChangeHandler = new WeakMap();
1055
- function processRecordedSpans(spans) {
1056
- for (let i = spans.length - 1; i >= 0; i--) {
1057
- if (spans[i] > SPAN_THRESHOLD) {
1058
- return spans.slice(0, i + 1);
1059
- }
1060
- }
1061
- return [spans[0]];
1062
- }
1063
- function captureNetwork(startTs, endTs) {
1064
- const entries = performance.getEntriesByType("resource");
1065
- performance.clearResourceTimings();
1066
- const networkEntries = entries.filter(
1067
- (entry) => entry.startTime >= startTs && entry.startTime <= endTs && entry.responseEnd >= startTs && entry.responseEnd <= endTs
1068
- );
1069
- for (const entry of networkEntries) {
1070
- performance.measure("Network entry " + entry.name, {
1071
- start: entry.startTime,
1072
- end: entry.responseEnd
1073
- });
1074
- }
1075
- return calculateNetworkTime(networkEntries);
1076
- }
1077
- function calculateNetworkTime(requests) {
1078
- if (requests.length === 0) {
1079
- return 0;
1080
- }
1081
- requests.sort((a, b) => a.startTime - b.startTime);
1082
- let totalNetworkTime = 0;
1083
- let currentStart = requests[0].startTime;
1084
- let currentEnd = requests[0].responseEnd;
1085
- for (let i = 1; i < requests.length; i++) {
1086
- if (requests[i].startTime <= currentEnd) {
1087
- currentEnd = Math.max(currentEnd, requests[i].responseEnd);
1088
- } else {
1089
- totalNetworkTime += currentEnd - currentStart;
1090
- currentStart = requests[i].startTime;
1091
- currentEnd = requests[i].responseEnd;
1092
- }
1093
- }
1094
- totalNetworkTime += currentEnd - currentStart;
1095
- return totalNetworkTime;
1096
- }
1097
- const REFRESH_INTERACTION = "refresh";
1098
- const TIME_RANGE_CHANGE_INTERACTION = "time_range_change";
1099
- const FILTER_REMOVED_INTERACTION = "filter_removed";
1100
- const FILTER_CHANGED_INTERACTION = "filter_changed";
1101
- const FILTER_RESTORED_INTERACTION = "filter_restored";
1102
- const VARIABLE_VALUE_CHANGED_INTERACTION = "variable_value_changed";
1103
- const SCOPES_CHANGED_INTERACTION = "scopes_changed";
1104
-
1105
1202
  class SceneTimeRange extends SceneObjectBase {
1106
1203
  constructor(state = {}) {
1107
1204
  var _a;
@@ -3687,10 +3784,13 @@ function GroupByVariableRenderer({ model }) {
3687
3784
  setUncommittedValue(newValue);
3688
3785
  },
3689
3786
  onOpenMenu: async () => {
3787
+ const profiler = getInteractionProfiler(model);
3788
+ profiler == null ? void 0 : profiler.startProfile(USER_INTERACTIONS.GROUPBY_DROPDOWN);
3690
3789
  setIsFetchingOptions(true);
3691
3790
  await rxjs.lastValueFrom(model.validateAndUpdate());
3692
3791
  setIsFetchingOptions(false);
3693
3792
  setIsOptionsOpen(true);
3793
+ profiler == null ? void 0 : profiler.stopProfile();
3694
3794
  },
3695
3795
  onCloseMenu: () => {
3696
3796
  setIsOptionsOpen(false);
@@ -3740,10 +3840,13 @@ function GroupByVariableRenderer({ model }) {
3740
3840
  }
3741
3841
  },
3742
3842
  onOpenMenu: async () => {
3843
+ const profiler = getInteractionProfiler(model);
3844
+ profiler == null ? void 0 : profiler.startProfile(USER_INTERACTIONS.GROUPBY_DROPDOWN);
3743
3845
  setIsFetchingOptions(true);
3744
3846
  await rxjs.lastValueFrom(model.validateAndUpdate());
3745
3847
  setIsFetchingOptions(false);
3746
3848
  setIsOptionsOpen(true);
3849
+ profiler == null ? void 0 : profiler.stopProfile();
3747
3850
  },
3748
3851
  onCloseMenu: () => {
3749
3852
  setIsOptionsOpen(false);
@@ -4908,6 +5011,11 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4908
5011
  const handleFetchOptions = React.useCallback(
4909
5012
  async (inputType) => {
4910
5013
  var _a2;
5014
+ const profiler = getInteractionProfiler(model);
5015
+ const interactionName = inputType === "key" ? USER_INTERACTIONS.ADHOC_KEYS_DROPDOWN : USER_INTERACTIONS.ADHOC_VALUES_DROPDOWN;
5016
+ if (inputType !== "operator") {
5017
+ profiler == null ? void 0 : profiler.startProfile(interactionName);
5018
+ }
4911
5019
  setOptionsError(false);
4912
5020
  setOptionsLoading(true);
4913
5021
  setOptions([]);
@@ -4921,6 +5029,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4921
5029
  options2 = await model._getValuesFor(filter);
4922
5030
  }
4923
5031
  if (filterInputTypeRef.current !== inputType) {
5032
+ profiler == null ? void 0 : profiler.stopProfile();
4924
5033
  return;
4925
5034
  }
4926
5035
  setOptions(options2);
@@ -4933,6 +5042,7 @@ const AdHocCombobox = React.forwardRef(function AdHocCombobox2({ filter, model,
4933
5042
  setOptionsError(true);
4934
5043
  }
4935
5044
  setOptionsLoading(false);
5045
+ profiler == null ? void 0 : profiler.stopProfile();
4936
5046
  },
4937
5047
  [filter, model]
4938
5048
  );
@@ -7980,6 +8090,7 @@ const sceneGraph = {
7980
8090
  findAllObjects,
7981
8091
  getAncestor,
7982
8092
  getQueryController,
8093
+ getInteractionProfiler,
7983
8094
  findDescendents,
7984
8095
  getScopes
7985
8096
  };
@@ -9479,6 +9590,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
9479
9590
  ActWhenVariableChanged: ActWhenVariableChanged,
9480
9591
  CursorSync: CursorSync,
9481
9592
  LiveNowTimer: LiveNowTimer,
9593
+ SceneInteractionProfiler: SceneInteractionProfiler,
9482
9594
  SceneQueryController: SceneQueryController
9483
9595
  });
9484
9596