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.

stats.go 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. TotIntroduceLoop uint64
  41. TotIntroduceSegmentBeg uint64
  42. TotIntroduceSegmentEnd uint64
  43. TotIntroducePersistBeg uint64
  44. TotIntroducePersistEnd uint64
  45. TotIntroduceMergeBeg uint64
  46. TotIntroduceMergeEnd uint64
  47. TotIntroduceRevertBeg uint64
  48. TotIntroduceRevertEnd uint64
  49. TotIntroducedItems uint64
  50. TotIntroducedSegmentsBatch uint64
  51. TotIntroducedSegmentsMerge uint64
  52. TotPersistLoopBeg uint64
  53. TotPersistLoopErr uint64
  54. TotPersistLoopProgress uint64
  55. TotPersistLoopWait uint64
  56. TotPersistLoopWaitNotified uint64
  57. TotPersistLoopEnd uint64
  58. TotPersistedItems uint64
  59. TotItemsToPersist uint64
  60. TotPersistedSegments uint64
  61. TotPersisterSlowMergerPause uint64
  62. TotPersisterSlowMergerResume uint64
  63. TotPersisterNapPauseCompleted uint64
  64. TotPersisterMergerNapBreak uint64
  65. TotFileMergeLoopBeg uint64
  66. TotFileMergeLoopErr uint64
  67. TotFileMergeLoopEnd uint64
  68. TotFileMergePlan uint64
  69. TotFileMergePlanErr uint64
  70. TotFileMergePlanNone uint64
  71. TotFileMergePlanOk uint64
  72. TotFileMergePlanTasks uint64
  73. TotFileMergePlanTasksDone uint64
  74. TotFileMergePlanTasksErr uint64
  75. TotFileMergePlanTasksSegments uint64
  76. TotFileMergePlanTasksSegmentsEmpty uint64
  77. TotFileMergeSegmentsEmpty uint64
  78. TotFileMergeSegments uint64
  79. TotFileSegmentsAtRoot uint64
  80. TotFileMergeWrittenBytes uint64
  81. TotFileMergeZapBeg uint64
  82. TotFileMergeZapEnd uint64
  83. TotFileMergeZapTime uint64
  84. MaxFileMergeZapTime uint64
  85. TotFileMergeZapIntroductionTime uint64
  86. MaxFileMergeZapIntroductionTime uint64
  87. TotFileMergeIntroductions uint64
  88. TotFileMergeIntroductionsDone uint64
  89. TotFileMergeIntroductionsSkipped uint64
  90. CurFilesIneligibleForRemoval uint64
  91. TotSnapshotsRemovedFromMetaStore uint64
  92. TotMemMergeBeg uint64
  93. TotMemMergeErr uint64
  94. TotMemMergeDone uint64
  95. TotMemMergeZapBeg uint64
  96. TotMemMergeZapEnd uint64
  97. TotMemMergeZapTime uint64
  98. MaxMemMergeZapTime uint64
  99. TotMemMergeSegments uint64
  100. TotMemorySegmentsAtRoot uint64
  101. }
  102. // atomically populates the returned map
  103. func (s *Stats) ToMap() map[string]interface{} {
  104. m := map[string]interface{}{}
  105. sve := reflect.ValueOf(s).Elem()
  106. svet := sve.Type()
  107. for i := 0; i < svet.NumField(); i++ {
  108. svef := sve.Field(i)
  109. if svef.CanAddr() {
  110. svefp := svef.Addr().Interface()
  111. m[svet.Field(i).Name] = atomic.LoadUint64(svefp.(*uint64))
  112. }
  113. }
  114. return m
  115. }
  116. // MarshalJSON implements json.Marshaler, and in contrast to standard
  117. // json marshaling provides atomic safety
  118. func (s *Stats) MarshalJSON() ([]byte, error) {
  119. return json.Marshal(s.ToMap())
  120. }