You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.1 KiB

  1. // Copyright (c) 2017 Couchbase, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package scorch
  15. import (
  16. "encoding/json"
  17. "reflect"
  18. "sync/atomic"
  19. )
  20. // Stats tracks statistics about the index, fields that are
  21. // prefixed like CurXxxx are gauges (can go up and down),
  22. // and fields that are prefixed like TotXxxx are monotonically
  23. // increasing counters.
  24. type Stats struct {
  25. TotUpdates uint64
  26. TotDeletes uint64
  27. TotBatches uint64
  28. TotBatchesEmpty uint64
  29. TotBatchIntroTime uint64
  30. MaxBatchIntroTime uint64
  31. CurRootEpoch uint64
  32. LastPersistedEpoch uint64
  33. LastMergedEpoch uint64
  34. TotOnErrors uint64
  35. TotAnalysisTime uint64
  36. TotIndexTime uint64
  37. TotIndexedPlainTextBytes uint64
  38. TotTermSearchersStarted uint64
  39. TotTermSearchersFinished uint64
  40. TotEventTriggerStarted uint64
  41. TotEventTriggerCompleted uint64
  42. TotIntroduceLoop uint64
  43. TotIntroduceSegmentBeg uint64
  44. TotIntroduceSegmentEnd uint64
  45. TotIntroducePersistBeg uint64
  46. TotIntroducePersistEnd uint64
  47. TotIntroduceMergeBeg uint64
  48. TotIntroduceMergeEnd uint64
  49. TotIntroduceRevertBeg uint64
  50. TotIntroduceRevertEnd uint64
  51. TotIntroducedItems uint64
  52. TotIntroducedSegmentsBatch uint64
  53. TotIntroducedSegmentsMerge uint64
  54. TotPersistLoopBeg uint64
  55. TotPersistLoopErr uint64
  56. TotPersistLoopProgress uint64
  57. TotPersistLoopWait uint64
  58. TotPersistLoopWaitNotified uint64
  59. TotPersistLoopEnd uint64
  60. TotPersistedItems uint64
  61. TotItemsToPersist uint64
  62. TotPersistedSegments uint64
  63. TotPersisterSlowMergerPause uint64
  64. TotPersisterSlowMergerResume uint64
  65. TotPersisterNapPauseCompleted uint64
  66. TotPersisterMergerNapBreak uint64
  67. TotFileMergeLoopBeg uint64
  68. TotFileMergeLoopErr uint64
  69. TotFileMergeLoopEnd uint64
  70. TotFileMergeForceOpsStarted uint64
  71. TotFileMergeForceOpsCompleted uint64
  72. TotFileMergePlan uint64
  73. TotFileMergePlanErr uint64
  74. TotFileMergePlanNone uint64
  75. TotFileMergePlanOk uint64
  76. TotFileMergePlanTasks uint64
  77. TotFileMergePlanTasksDone uint64
  78. TotFileMergePlanTasksErr uint64
  79. TotFileMergePlanTasksSegments uint64
  80. TotFileMergePlanTasksSegmentsEmpty uint64
  81. TotFileMergeSegmentsEmpty uint64
  82. TotFileMergeSegments uint64
  83. TotFileSegmentsAtRoot uint64
  84. TotFileMergeWrittenBytes uint64
  85. TotFileMergeZapBeg uint64
  86. TotFileMergeZapEnd uint64
  87. TotFileMergeZapTime uint64
  88. MaxFileMergeZapTime uint64
  89. TotFileMergeZapIntroductionTime uint64
  90. MaxFileMergeZapIntroductionTime uint64
  91. TotFileMergeIntroductions uint64
  92. TotFileMergeIntroductionsDone uint64
  93. TotFileMergeIntroductionsSkipped uint64
  94. TotFileMergeIntroductionsObsoleted uint64
  95. CurFilesIneligibleForRemoval uint64
  96. TotSnapshotsRemovedFromMetaStore uint64
  97. TotMemMergeBeg uint64
  98. TotMemMergeErr uint64
  99. TotMemMergeDone uint64
  100. TotMemMergeZapBeg uint64
  101. TotMemMergeZapEnd uint64
  102. TotMemMergeZapTime uint64
  103. MaxMemMergeZapTime uint64
  104. TotMemMergeSegments uint64
  105. TotMemorySegmentsAtRoot uint64
  106. }
  107. // atomically populates the returned map
  108. func (s *Stats) ToMap() map[string]interface{} {
  109. m := map[string]interface{}{}
  110. sve := reflect.ValueOf(s).Elem()
  111. svet := sve.Type()
  112. for i := 0; i < svet.NumField(); i++ {
  113. svef := sve.Field(i)
  114. if svef.CanAddr() {
  115. svefp := svef.Addr().Interface()
  116. m[svet.Field(i).Name] = atomic.LoadUint64(svefp.(*uint64))
  117. }
  118. }
  119. return m
  120. }
  121. // MarshalJSON implements json.Marshaler, and in contrast to standard
  122. // json marshaling provides atomic safety
  123. func (s *Stats) MarshalJSON() ([]byte, error) {
  124. return json.Marshal(s.ToMap())
  125. }