@itwin/core-backend 3.4.0-dev.8 → 3.5.0-dev.4

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.
Files changed (261) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -17
  3. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  4. package/lib/cjs/AliCloudStorageService.js +71 -68
  5. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  6. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  7. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  8. package/lib/cjs/BackendHubAccess.js +41 -41
  9. package/lib/cjs/BackendHubAccess.js.map +1 -1
  10. package/lib/cjs/BackendLoggerCategory.d.ts +91 -87
  11. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  12. package/lib/cjs/BackendLoggerCategory.js +99 -95
  13. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  14. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  15. package/lib/cjs/BisCoreSchema.js +60 -60
  16. package/lib/cjs/BisCoreSchema.js.map +1 -1
  17. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  18. package/lib/cjs/BriefcaseManager.js +405 -405
  19. package/lib/cjs/BriefcaseManager.js.map +1 -1
  20. package/lib/cjs/Category.d.ts +153 -153
  21. package/lib/cjs/Category.js +243 -243
  22. package/lib/cjs/Category.js.map +1 -1
  23. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  24. package/lib/cjs/ChangeSummaryManager.js +445 -445
  25. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  26. package/lib/cjs/ChangedElementsDb.d.ts +99 -98
  27. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  28. package/lib/cjs/ChangedElementsDb.js +165 -165
  29. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  30. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  31. package/lib/cjs/ChangedElementsManager.js +88 -88
  32. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  33. package/lib/cjs/CheckpointManager.d.ts +120 -122
  34. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  35. package/lib/cjs/CheckpointManager.js +343 -354
  36. package/lib/cjs/CheckpointManager.js.map +1 -1
  37. package/lib/cjs/ClassRegistry.d.ts +71 -71
  38. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  39. package/lib/cjs/ClassRegistry.js +215 -213
  40. package/lib/cjs/ClassRegistry.js.map +1 -1
  41. package/lib/cjs/CloudSqlite.d.ts +350 -0
  42. package/lib/cjs/CloudSqlite.d.ts.map +1 -0
  43. package/lib/cjs/CloudSqlite.js +152 -0
  44. package/lib/cjs/CloudSqlite.js.map +1 -0
  45. package/lib/cjs/CloudStorageBackend.d.ts +58 -46
  46. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  47. package/lib/cjs/CloudStorageBackend.js +173 -164
  48. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  49. package/lib/cjs/CodeService.d.ts +397 -0
  50. package/lib/cjs/CodeService.d.ts.map +1 -0
  51. package/lib/cjs/CodeService.js +64 -0
  52. package/lib/cjs/CodeService.js.map +1 -0
  53. package/lib/cjs/CodeSpecs.d.ts +50 -50
  54. package/lib/cjs/CodeSpecs.js +112 -112
  55. package/lib/cjs/CodeSpecs.js.map +1 -1
  56. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  57. package/lib/cjs/ConcurrentQuery.js +30 -30
  58. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  59. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  60. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  61. package/lib/cjs/CustomViewState3dCreator.js +113 -98
  62. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  63. package/lib/cjs/DevTools.d.ts +71 -71
  64. package/lib/cjs/DevTools.d.ts.map +1 -1
  65. package/lib/cjs/DevTools.js +154 -154
  66. package/lib/cjs/DevTools.js.map +1 -1
  67. package/lib/cjs/DisplayStyle.d.ts +106 -106
  68. package/lib/cjs/DisplayStyle.js +256 -256
  69. package/lib/cjs/DisplayStyle.js.map +1 -1
  70. package/lib/cjs/ECDb.d.ts +191 -191
  71. package/lib/cjs/ECDb.js +350 -350
  72. package/lib/cjs/ECDb.js.map +1 -1
  73. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  74. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  76. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  77. package/lib/cjs/ECSqlStatement.js +791 -791
  78. package/lib/cjs/ECSqlStatement.js.map +1 -1
  79. package/lib/cjs/Element.d.ts +1109 -1109
  80. package/lib/cjs/Element.d.ts.map +1 -1
  81. package/lib/cjs/Element.js +1420 -1417
  82. package/lib/cjs/Element.js.map +1 -1
  83. package/lib/cjs/ElementAspect.d.ts +156 -156
  84. package/lib/cjs/ElementAspect.js +178 -178
  85. package/lib/cjs/ElementAspect.js.map +1 -1
  86. package/lib/cjs/ElementGraphics.d.ts +9 -9
  87. package/lib/cjs/ElementGraphics.js +41 -41
  88. package/lib/cjs/ElementGraphics.js.map +1 -1
  89. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  90. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  91. package/lib/cjs/ElementTreeWalker.js +409 -409
  92. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  93. package/lib/cjs/Entity.d.ts +76 -76
  94. package/lib/cjs/Entity.js +82 -82
  95. package/lib/cjs/Entity.js.map +1 -1
  96. package/lib/cjs/ExportGraphics.d.ts +317 -317
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  98. package/lib/cjs/ExportGraphics.js +208 -208
  99. package/lib/cjs/ExportGraphics.js.map +1 -1
  100. package/lib/cjs/ExternalSource.d.ts +94 -94
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  102. package/lib/cjs/ExternalSource.js +125 -125
  103. package/lib/cjs/ExternalSource.js.map +1 -1
  104. package/lib/cjs/GeoCoordConfig.d.ts +19 -13
  105. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  106. package/lib/cjs/GeoCoordConfig.js +82 -73
  107. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  108. package/lib/cjs/GeometrySummary.d.ts +4 -4
  109. package/lib/cjs/GeometrySummary.js +380 -380
  110. package/lib/cjs/GeometrySummary.js.map +1 -1
  111. package/lib/cjs/HubMock.d.ts +93 -93
  112. package/lib/cjs/HubMock.d.ts.map +1 -1
  113. package/lib/cjs/HubMock.js +190 -190
  114. package/lib/cjs/HubMock.js.map +1 -1
  115. package/lib/cjs/IModelCloneContext.d.ts +85 -85
  116. package/lib/cjs/IModelCloneContext.js +150 -150
  117. package/lib/cjs/IModelCloneContext.js.map +1 -1
  118. package/lib/cjs/IModelDb.d.ts +1164 -1151
  119. package/lib/cjs/IModelDb.d.ts.map +1 -1
  120. package/lib/cjs/IModelDb.js +2324 -2286
  121. package/lib/cjs/IModelDb.js.map +1 -1
  122. package/lib/cjs/IModelHost.d.ts +361 -347
  123. package/lib/cjs/IModelHost.d.ts.map +1 -1
  124. package/lib/cjs/IModelHost.js +489 -455
  125. package/lib/cjs/IModelHost.js.map +1 -1
  126. package/lib/cjs/IModelJsFs.d.ts +62 -62
  127. package/lib/cjs/IModelJsFs.d.ts.map +1 -1
  128. package/lib/cjs/IModelJsFs.js +140 -140
  129. package/lib/cjs/IModelJsFs.js.map +1 -1
  130. package/lib/cjs/IpcHost.d.ts +98 -98
  131. package/lib/cjs/IpcHost.js +234 -234
  132. package/lib/cjs/IpcHost.js.map +1 -1
  133. package/lib/cjs/LineStyle.d.ts +311 -311
  134. package/lib/cjs/LineStyle.js +295 -295
  135. package/lib/cjs/LineStyle.js.map +1 -1
  136. package/lib/cjs/LocalHub.d.ts +162 -162
  137. package/lib/cjs/LocalHub.js +587 -587
  138. package/lib/cjs/LocalHub.js.map +1 -1
  139. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  140. package/lib/cjs/LocalhostIpcHost.js +81 -81
  141. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  142. package/lib/cjs/Material.d.ts +103 -101
  143. package/lib/cjs/Material.d.ts.map +1 -1
  144. package/lib/cjs/Material.js +147 -145
  145. package/lib/cjs/Material.js.map +1 -1
  146. package/lib/cjs/Model.d.ts +386 -386
  147. package/lib/cjs/Model.d.ts.map +1 -1
  148. package/lib/cjs/Model.js +471 -468
  149. package/lib/cjs/Model.js.map +1 -1
  150. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  151. package/lib/cjs/NativeAppStorage.js +202 -202
  152. package/lib/cjs/NativeAppStorage.js.map +1 -1
  153. package/lib/cjs/NativeHost.d.ts +52 -52
  154. package/lib/cjs/NativeHost.js +168 -168
  155. package/lib/cjs/NativeHost.js.map +1 -1
  156. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  157. package/lib/cjs/NavigationRelationship.js +225 -225
  158. package/lib/cjs/NavigationRelationship.js.map +1 -1
  159. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  160. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  161. package/lib/cjs/PromiseMemoizer.js +101 -95
  162. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  163. package/lib/cjs/PropertyStore.d.ts +133 -0
  164. package/lib/cjs/PropertyStore.d.ts.map +1 -0
  165. package/lib/cjs/PropertyStore.js +12 -0
  166. package/lib/cjs/PropertyStore.js.map +1 -0
  167. package/lib/cjs/Relationship.d.ts +400 -400
  168. package/lib/cjs/Relationship.js +465 -465
  169. package/lib/cjs/Relationship.js.map +1 -1
  170. package/lib/cjs/RpcBackend.d.ts +28 -28
  171. package/lib/cjs/RpcBackend.js +126 -126
  172. package/lib/cjs/RpcBackend.js.map +1 -1
  173. package/lib/cjs/SQLiteDb.d.ts +219 -173
  174. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  175. package/lib/cjs/SQLiteDb.js +214 -211
  176. package/lib/cjs/SQLiteDb.js.map +1 -1
  177. package/lib/cjs/Schema.d.ts +55 -55
  178. package/lib/cjs/Schema.js +83 -83
  179. package/lib/cjs/Schema.js.map +1 -1
  180. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  181. package/lib/cjs/ServerBasedLocks.js +168 -168
  182. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  183. package/lib/cjs/SqliteStatement.d.ts +283 -271
  184. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  185. package/lib/cjs/SqliteStatement.js +448 -426
  186. package/lib/cjs/SqliteStatement.js.map +1 -1
  187. package/lib/cjs/Texture.d.ts +58 -58
  188. package/lib/cjs/Texture.js +82 -82
  189. package/lib/cjs/Texture.js.map +1 -1
  190. package/lib/cjs/TileStorage.d.ts +19 -0
  191. package/lib/cjs/TileStorage.d.ts.map +1 -0
  192. package/lib/cjs/TileStorage.js +91 -0
  193. package/lib/cjs/TileStorage.js.map +1 -0
  194. package/lib/cjs/TxnManager.d.ts +202 -202
  195. package/lib/cjs/TxnManager.d.ts.map +1 -1
  196. package/lib/cjs/TxnManager.js +356 -353
  197. package/lib/cjs/TxnManager.js.map +1 -1
  198. package/lib/cjs/ViewDefinition.d.ts +435 -435
  199. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  200. package/lib/cjs/ViewDefinition.js +635 -629
  201. package/lib/cjs/ViewDefinition.js.map +1 -1
  202. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  203. package/lib/cjs/ViewStateHydrator.js +103 -103
  204. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  205. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  206. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  207. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -21
  208. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  209. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  210. package/lib/cjs/core-backend.d.ts +182 -175
  211. package/lib/cjs/core-backend.d.ts.map +1 -1
  212. package/lib/cjs/core-backend.js +202 -195
  213. package/lib/cjs/core-backend.js.map +1 -1
  214. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  215. package/lib/cjs/domains/FunctionalElements.js +145 -145
  216. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  217. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  218. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  219. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  220. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  221. package/lib/cjs/domains/GenericElements.js +263 -263
  222. package/lib/cjs/domains/GenericElements.js.map +1 -1
  223. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  224. package/lib/cjs/domains/GenericSchema.js +28 -28
  225. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  226. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  227. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  228. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  229. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  230. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  231. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -20
  233. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  234. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -195
  235. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  237. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  238. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -165
  239. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  241. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  242. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  243. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  245. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  246. package/lib/cjs/workspace/Settings.d.ts +186 -186
  247. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  248. package/lib/cjs/workspace/Settings.js +155 -152
  249. package/lib/cjs/workspace/Settings.js.map +1 -1
  250. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  251. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  252. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  253. package/lib/cjs/workspace/Workspace.d.ts +414 -401
  254. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  255. package/lib/cjs/workspace/Workspace.js +543 -534
  256. package/lib/cjs/workspace/Workspace.js.map +1 -1
  257. package/package.json +19 -20
  258. package/lib/cjs/IModelSchemaLoader.d.ts +0 -26
  259. package/lib/cjs/IModelSchemaLoader.d.ts.map +0 -1
  260. package/lib/cjs/IModelSchemaLoader.js +0 -122
  261. package/lib/cjs/IModelSchemaLoader.js.map +0 -1
@@ -1,155 +1,155 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.DevTools = exports.DevToolsStatsFormatter = void 0;
8
- const os = require("os");
9
- const process = require("process");
10
- const core_bentley_1 = require("@itwin/core-bentley");
11
- const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
12
- const IModelHost_1 = require("./IModelHost");
13
- // cspell:ignore ppid elap
14
- const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.DevTools;
15
- /** Utility to format the JSON created by DevTools.stats() to include the appropriate units
16
- * @internal
17
- */
18
- class DevToolsStatsFormatter {
19
- /** Converts the input stats to another JSON object with the appropriate units setup for various fields */
20
- static toFormattedJson(stats) {
21
- // Serialize the stats to a string with a replacer that sets up units during the serialization
22
- const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);
23
- // Deserialize back to JSON
24
- return JSON.parse(statsStr);
25
- }
26
- }
27
- exports.DevToolsStatsFormatter = DevToolsStatsFormatter;
28
- DevToolsStatsFormatter._megaByteProps = ["totalmem", "freemem", "rss", "heapTotal", "heapUsed", "external"];
29
- DevToolsStatsFormatter._percentProps = ["user", "nice", "sys", "idle", "irq", "cpuUsage"];
30
- DevToolsStatsFormatter._mHzProps = ["speed"];
31
- DevToolsStatsFormatter._secondsProps = ["uptime"];
32
- /** Replacer that includes units - can be used with JSON.stringify() */
33
- DevToolsStatsFormatter._replacer = (key, value) => {
34
- if (DevToolsStatsFormatter._megaByteProps.includes(key))
35
- return `${value.toFixed()} MB`;
36
- if (DevToolsStatsFormatter._percentProps.includes(key))
37
- return `${value.toFixed()}%`;
38
- if (DevToolsStatsFormatter._mHzProps.includes(key))
39
- return `${value.toString()} MHz`;
40
- if (DevToolsStatsFormatter._secondsProps.includes(key))
41
- return `${value.toFixed()} secs`;
42
- return value;
43
- };
44
- /**
45
- * Internal diagnostic utility
46
- * @internal
47
- */
48
- class DevTools {
49
- /** Receives a ping and returns true */
50
- static ping() {
51
- core_bentley_1.Logger.logInfo(loggerCategory, "Received ping at backend");
52
- return true;
53
- }
54
- static hrtimeToMS(hrtime) {
55
- return hrtime[0] * 1000 + hrtime[1] / 1000000;
56
- }
57
- static bytesToMegaBytes(bytes) {
58
- const megaBytes = bytes / Math.pow(1024, 2);
59
- return Math.round(megaBytes * 100) / 100;
60
- }
61
- static evaluateCpuUsage() {
62
- const NUMBER_OF_CPUS = os.cpus().length;
63
- const startTime = process.hrtime();
64
- const startUsage = process.cpuUsage();
65
- // spin the CPU for 500 milliseconds
66
- const now = Date.now();
67
- while (Date.now() - now < 500)
68
- ;
69
- const elapTime = process.hrtime(startTime);
70
- const elapUsage = process.cpuUsage(startUsage);
71
- const elapTimeMS = this.hrtimeToMS(elapTime);
72
- const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds
73
- const elapSystMS = elapUsage.system / 1000;
74
- const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));
75
- return cpuPercent;
76
- }
77
- static evaluateCpus() {
78
- // Create a clone
79
- const srcCpus = os.cpus();
80
- const cpus = new Array(srcCpus.length);
81
- let ii = 0;
82
- for (const srcCpu of srcCpus)
83
- cpus[ii++] = { ...srcCpu };
84
- // Evaluate cpu usage as percentages
85
- for (const cpu of Object.values(cpus)) {
86
- const total = Object.values(cpu.times).reduce((_total, currValue) => _total += currValue, 0);
87
- const cpuTimes = cpu.times;
88
- for (const type of Object.keys(cpuTimes)) {
89
- const cpuPercent = Math.round(100 * cpuTimes[type] / total);
90
- cpuTimes[type] = cpuPercent;
91
- }
92
- }
93
- return cpus;
94
- }
95
- static evaluateMemoryUsage() {
96
- // Create a clone
97
- const memUsage = { ...process.memoryUsage() };
98
- const memUsageObj = memUsage;
99
- // Evaluate memory usage as mega bytes
100
- for (const type of Object.keys(memUsageObj)) {
101
- memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);
102
- }
103
- return memUsage;
104
- }
105
- static evaluateProcessStats() {
106
- return {
107
- uptime: process.uptime(),
108
- pid: process.pid,
109
- ppid: process.ppid,
110
- memoryUsage: this.evaluateMemoryUsage(),
111
- };
112
- }
113
- static evaluateOsStats() {
114
- return {
115
- platform: os.platform(),
116
- hostname: os.hostname(),
117
- totalmem: this.bytesToMegaBytes(os.totalmem()),
118
- freemem: this.bytesToMegaBytes(os.freemem()),
119
- uptime: os.uptime(),
120
- cpus: this.evaluateCpus(),
121
- cpuUsage: this.evaluateCpuUsage(),
122
- };
123
- }
124
- /** Returns JSON object with backend statistics */
125
- static stats() {
126
- try {
127
- const stats = {
128
- os: this.evaluateOsStats(),
129
- process: this.evaluateProcessStats(),
130
- };
131
- return stats;
132
- }
133
- catch (error) {
134
- core_bentley_1.Logger.logError(loggerCategory, "Could not fetch stats at backend");
135
- throw error;
136
- }
137
- }
138
- /** Sets up a log level at the backend and returns the old log level */
139
- static setLogLevel(inLoggerCategory, newLevel) {
140
- const oldLevel = core_bentley_1.Logger.getLevel(inLoggerCategory);
141
- core_bentley_1.Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));
142
- core_bentley_1.Logger.setLevel(inLoggerCategory, newLevel);
143
- IModelHost_1.IModelHost.platform.clearLogLevelCache();
144
- return oldLevel;
145
- }
146
- /** Obtains the backend application and iTwin.js Core versions */
147
- static versions() {
148
- return {
149
- application: IModelHost_1.IModelHost.applicationVersion,
150
- iTwinJs: require("../../package.json").version, // eslint-disable-line @typescript-eslint/no-var-requires
151
- };
152
- }
153
- }
154
- exports.DevTools = DevTools;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DevTools = exports.DevToolsStatsFormatter = void 0;
8
+ const os = require("os");
9
+ const process = require("process");
10
+ const core_bentley_1 = require("@itwin/core-bentley");
11
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
12
+ const IModelHost_1 = require("./IModelHost");
13
+ // cspell:ignore ppid elap
14
+ const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.DevTools;
15
+ /** Utility to format the JSON created by DevTools.stats() to include the appropriate units
16
+ * @internal
17
+ */
18
+ class DevToolsStatsFormatter {
19
+ /** Converts the input stats to another JSON object with the appropriate units setup for various fields */
20
+ static toFormattedJson(stats) {
21
+ // Serialize the stats to a string with a replacer that sets up units during the serialization
22
+ const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);
23
+ // Deserialize back to JSON
24
+ return JSON.parse(statsStr);
25
+ }
26
+ }
27
+ exports.DevToolsStatsFormatter = DevToolsStatsFormatter;
28
+ DevToolsStatsFormatter._megaByteProps = ["totalmem", "freemem", "rss", "heapTotal", "heapUsed", "external"];
29
+ DevToolsStatsFormatter._percentProps = ["user", "nice", "sys", "idle", "irq", "cpuUsage"];
30
+ DevToolsStatsFormatter._mHzProps = ["speed"];
31
+ DevToolsStatsFormatter._secondsProps = ["uptime"];
32
+ /** Replacer that includes units - can be used with JSON.stringify() */
33
+ DevToolsStatsFormatter._replacer = (key, value) => {
34
+ if (DevToolsStatsFormatter._megaByteProps.includes(key))
35
+ return `${value.toFixed()} MB`;
36
+ if (DevToolsStatsFormatter._percentProps.includes(key))
37
+ return `${value.toFixed()}%`;
38
+ if (DevToolsStatsFormatter._mHzProps.includes(key))
39
+ return `${value.toString()} MHz`;
40
+ if (DevToolsStatsFormatter._secondsProps.includes(key))
41
+ return `${value.toFixed()} secs`;
42
+ return value;
43
+ };
44
+ /**
45
+ * Internal diagnostic utility
46
+ * @internal
47
+ */
48
+ class DevTools {
49
+ /** Receives a ping and returns true */
50
+ static ping() {
51
+ core_bentley_1.Logger.logInfo(loggerCategory, "Received ping at backend");
52
+ return true;
53
+ }
54
+ static hrtimeToMS(hrtime) {
55
+ return hrtime[0] * 1000 + hrtime[1] / 1000000;
56
+ }
57
+ static bytesToMegaBytes(bytes) {
58
+ const megaBytes = bytes / Math.pow(1024, 2);
59
+ return Math.round(megaBytes * 100) / 100;
60
+ }
61
+ static evaluateCpuUsage() {
62
+ const NUMBER_OF_CPUS = os.cpus().length;
63
+ const startTime = process.hrtime();
64
+ const startUsage = process.cpuUsage();
65
+ // spin the CPU for 500 milliseconds
66
+ const now = Date.now();
67
+ while (Date.now() - now < 500)
68
+ ;
69
+ const elapTime = process.hrtime(startTime);
70
+ const elapUsage = process.cpuUsage(startUsage);
71
+ const elapTimeMS = this.hrtimeToMS(elapTime);
72
+ const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds
73
+ const elapSystMS = elapUsage.system / 1000;
74
+ const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));
75
+ return cpuPercent;
76
+ }
77
+ static evaluateCpus() {
78
+ // Create a clone
79
+ const srcCpus = os.cpus();
80
+ const cpus = new Array(srcCpus.length);
81
+ let ii = 0;
82
+ for (const srcCpu of srcCpus)
83
+ cpus[ii++] = { ...srcCpu };
84
+ // Evaluate cpu usage as percentages
85
+ for (const cpu of Object.values(cpus)) {
86
+ const total = Object.values(cpu.times).reduce((_total, currValue) => _total += currValue, 0);
87
+ const cpuTimes = cpu.times;
88
+ for (const type of Object.keys(cpuTimes)) {
89
+ const cpuPercent = Math.round(100 * cpuTimes[type] / total);
90
+ cpuTimes[type] = cpuPercent;
91
+ }
92
+ }
93
+ return cpus;
94
+ }
95
+ static evaluateMemoryUsage() {
96
+ // Create a clone
97
+ const memUsage = { ...process.memoryUsage() };
98
+ const memUsageObj = memUsage;
99
+ // Evaluate memory usage as mega bytes
100
+ for (const type of Object.keys(memUsageObj)) {
101
+ memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);
102
+ }
103
+ return memUsage;
104
+ }
105
+ static evaluateProcessStats() {
106
+ return {
107
+ uptime: process.uptime(),
108
+ pid: process.pid,
109
+ ppid: process.ppid,
110
+ memoryUsage: this.evaluateMemoryUsage(),
111
+ };
112
+ }
113
+ static evaluateOsStats() {
114
+ return {
115
+ platform: os.platform(),
116
+ hostname: os.hostname(),
117
+ totalmem: this.bytesToMegaBytes(os.totalmem()),
118
+ freemem: this.bytesToMegaBytes(os.freemem()),
119
+ uptime: os.uptime(),
120
+ cpus: this.evaluateCpus(),
121
+ cpuUsage: this.evaluateCpuUsage(),
122
+ };
123
+ }
124
+ /** Returns JSON object with backend statistics */
125
+ static stats() {
126
+ try {
127
+ const stats = {
128
+ os: this.evaluateOsStats(),
129
+ process: this.evaluateProcessStats(),
130
+ };
131
+ return stats;
132
+ }
133
+ catch (error) {
134
+ core_bentley_1.Logger.logError(loggerCategory, "Could not fetch stats at backend");
135
+ throw error;
136
+ }
137
+ }
138
+ /** Sets up a log level at the backend and returns the old log level */
139
+ static setLogLevel(inLoggerCategory, newLevel) {
140
+ const oldLevel = core_bentley_1.Logger.getLevel(inLoggerCategory);
141
+ core_bentley_1.Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));
142
+ core_bentley_1.Logger.setLevel(inLoggerCategory, newLevel);
143
+ IModelHost_1.IModelHost.platform.clearLogLevelCache();
144
+ return oldLevel;
145
+ }
146
+ /** Obtains the backend application and iTwin.js Core versions */
147
+ static versions() {
148
+ return {
149
+ application: IModelHost_1.IModelHost.applicationVersion,
150
+ iTwinJs: require("../../package.json").version, // eslint-disable-line @typescript-eslint/no-var-requires
151
+ };
152
+ }
153
+ }
154
+ exports.DevTools = DevTools;
155
155
  //# sourceMappingURL=DevTools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DevTools.js","sourceRoot":"","sources":["../../src/DevTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,mCAAmC;AACnC,sDAAuD;AACvD,mEAAgE;AAChE,6CAA0C;AAE1C,0BAA0B;AAE1B,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAwC9D;;GAEG;AACH,MAAa,sBAAsB;IAmBjC,0GAA0G;IACnG,MAAM,CAAC,eAAe,CAAC,KAAU;QACtC,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,sBAAsB,C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gB,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QACtH,qBAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAC5C,uBAAU,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QACzC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,iEAAiE;IAC1D,MAAM,CAAC,QAAQ;QACpB,OAAO;YACL,WAAW,EAAE,uBAAU,CAAC,kBAAkB;YAC1C,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,EAAE,yDAAyD;SAC1G,CAAC;IACJ,CAAC;CACF;AAxHD,4BAwHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as os from \"os\";\r\nimport * as process from \"process\";\r\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { IModelHost } from \"./IModelHost\";\r\n\r\n// cspell:ignore ppid elap\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.DevTools;\r\n\r\ninterface StringIndexedObject<T> {\r\n [index: string]: T;\r\n}\r\n\r\n/**\r\n * Performance and Memory statistics of backend\r\n * @internal\r\n */\r\nexport interface DevToolsStats {\r\n os: DevToolsOsStats;\r\n process: DevToolsProcessStats;\r\n}\r\n\r\n/**\r\n * OS stats of backend\r\n * @internal\r\n */\r\nexport interface DevToolsOsStats {\r\n platform: NodeJS.Platform;\r\n hostname: string;\r\n totalmem: number;\r\n freemem: number;\r\n uptime: number;\r\n cpus: os.CpuInfo[];\r\n cpuUsage: number;\r\n}\r\n\r\n/**\r\n * Process stats of backend\r\n * @internal\r\n */\r\nexport interface DevToolsProcessStats {\r\n uptime: number;\r\n pid: number;\r\n ppid: number;\r\n memoryUsage: NodeJS.MemoryUsage;\r\n}\r\n\r\n/** Utility to format the JSON created by DevTools.stats() to include the appropriate units\r\n * @internal\r\n */\r\nexport class DevToolsStatsFormatter {\r\n private static readonly _megaByteProps = [\"totalmem\", \"freemem\", \"rss\", \"heapTotal\", \"heapUsed\", \"external\"];\r\n private static readonly _percentProps = [\"user\", \"nice\", \"sys\", \"idle\", \"irq\", \"cpuUsage\"];\r\n private static readonly _mHzProps = [\"speed\"];\r\n private static readonly _secondsProps = [\"uptime\"];\r\n\r\n /** Replacer that includes units - can be used with JSON.stringify() */\r\n private static _replacer = (key: string, value: any) => {\r\n if (DevToolsStatsFormatter._megaByteProps.includes(key))\r\n return `${value.toFixed()} MB`;\r\n if (DevToolsStatsFormatter._percentProps.includes(key))\r\n return `${value.toFixed()}%`;\r\n if (DevToolsStatsFormatter._mHzProps.includes(key))\r\n return `${value.toString()} MHz`;\r\n if (DevToolsStatsFormatter._secondsProps.includes(key))\r\n return `${value.toFixed()} secs`;\r\n return value;\r\n };\r\n\r\n /** Converts the input stats to another JSON object with the appropriate units setup for various fields */\r\n public static toFormattedJson(stats: any) {\r\n // Serialize the stats to a string with a replacer that sets up units during the serialization\r\n const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);\r\n\r\n // Deserialize back to JSON\r\n return JSON.parse(statsStr);\r\n }\r\n}\r\n\r\n/**\r\n * Internal diagnostic utility\r\n * @internal\r\n */\r\nexport class DevTools {\r\n\r\n /** Receives a ping and returns true */\r\n public static ping(): boolean {\r\n Logger.logInfo(loggerCategory, \"Received ping at backend\");\r\n return true;\r\n }\r\n\r\n private static hrtimeToMS(hrtime: any) {\r\n return hrtime[0] * 1000 + hrtime[1] / 1000000;\r\n }\r\n\r\n private static bytesToMegaBytes(bytes: number): number {\r\n const megaBytes = bytes / Math.pow(1024, 2);\r\n return Math.round(megaBytes * 100) / 100;\r\n }\r\n\r\n private static evaluateCpuUsage(): number {\r\n const NUMBER_OF_CPUS = os.cpus().length;\r\n const startTime = process.hrtime();\r\n const startUsage = process.cpuUsage();\r\n\r\n // spin the CPU for 500 milliseconds\r\n const now = Date.now();\r\n while (Date.now() - now < 500);\r\n\r\n const elapTime = process.hrtime(startTime);\r\n const elapUsage = process.cpuUsage(startUsage);\r\n\r\n const elapTimeMS = this.hrtimeToMS(elapTime);\r\n\r\n const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds\r\n const elapSystMS = elapUsage.system / 1000;\r\n const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));\r\n\r\n return cpuPercent;\r\n }\r\n\r\n private static evaluateCpus(): os.CpuInfo[] {\r\n // Create a clone\r\n const srcCpus = os.cpus();\r\n const cpus = new Array<os.CpuInfo>(srcCpus.length);\r\n let ii = 0;\r\n for (const srcCpu of srcCpus)\r\n cpus[ii++] = { ...srcCpu };\r\n\r\n // Evaluate cpu usage as percentages\r\n for (const cpu of Object.values(cpus)) {\r\n const total = Object.values(cpu.times).reduce((_total: number, currValue) => _total += currValue, 0);\r\n const cpuTimes = cpu.times as StringIndexedObject<number>;\r\n for (const type of Object.keys(cpuTimes)) {\r\n const cpuPercent = Math.round(100 * cpuTimes[type] / total);\r\n cpuTimes[type] = cpuPercent;\r\n }\r\n }\r\n return cpus;\r\n }\r\n\r\n private static evaluateMemoryUsage() {\r\n // Create a clone\r\n const memUsage = { ...process.memoryUsage() } as NodeJS.MemoryUsage;\r\n const memUsageObj = (memUsage as any) as StringIndexedObject<number>;\r\n // Evaluate memory usage as mega bytes\r\n for (const type of Object.keys(memUsageObj)) {\r\n memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);\r\n }\r\n return memUsage;\r\n }\r\n\r\n private static evaluateProcessStats(): DevToolsProcessStats {\r\n return {\r\n uptime: process.uptime(),\r\n pid: process.pid,\r\n ppid: process.ppid,\r\n memoryUsage: this.evaluateMemoryUsage(),\r\n } as DevToolsProcessStats;\r\n }\r\n\r\n private static evaluateOsStats(): DevToolsOsStats {\r\n return {\r\n platform: os.platform(),\r\n hostname: os.hostname(),\r\n totalmem: this.bytesToMegaBytes(os.totalmem()),\r\n freemem: this.bytesToMegaBytes(os.freemem()),\r\n uptime: os.uptime(),\r\n cpus: this.evaluateCpus(),\r\n cpuUsage: this.evaluateCpuUsage(),\r\n } as DevToolsOsStats;\r\n }\r\n\r\n /** Returns JSON object with backend statistics */\r\n public static stats(): DevToolsStats {\r\n try {\r\n const stats = {\r\n os: this.evaluateOsStats(),\r\n process: this.evaluateProcessStats(),\r\n } as DevToolsStats;\r\n return stats;\r\n } catch (error) {\r\n Logger.logError(loggerCategory, \"Could not fetch stats at backend\");\r\n throw error;\r\n }\r\n }\r\n\r\n /** Sets up a log level at the backend and returns the old log level */\r\n public static setLogLevel(inLoggerCategory: string, newLevel: LogLevel): LogLevel | undefined {\r\n const oldLevel = Logger.getLevel(inLoggerCategory);\r\n Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));\r\n Logger.setLevel(inLoggerCategory, newLevel);\r\n IModelHost.platform.clearLogLevelCache();\r\n return oldLevel;\r\n }\r\n\r\n /** Obtains the backend application and iTwin.js Core versions */\r\n public static versions() {\r\n return {\r\n application: IModelHost.applicationVersion,\r\n iTwinJs: require(\"../../package.json\").version, // eslint-disable-line @typescript-eslint/no-var-requires\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"DevTools.js","sourceRoot":"","sources":["../../src/DevTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,mCAAmC;AACnC,sDAAuD;AACvD,mEAAgE;AAChE,6CAA0C;AAE1C,0BAA0B;AAE1B,MAAM,cAAc,GAAW,6CAAqB,CAAC,QAAQ,CAAC;AAwC9D;;GAEG;AACH,MAAa,sBAAsB;IAmBjC,0GAA0G;IACnG,MAAM,CAAC,eAAe,CAAC,KAAU;QACtC,8FAA8F;QAC9F,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAA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,EAAE,cAAc,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QACtH,qBAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QAC5C,uBAAU,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QACzC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,iEAAiE;IAC1D,MAAM,CAAC,QAAQ;QACpB,OAAO;YACL,WAAW,EAAE,uBAAU,CAAC,kBAAkB;YAC1C,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,EAAE,yDAAyD;SAC1G,CAAC;IACJ,CAAC;CACF;AAzHD,4BAyHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as os from \"os\";\nimport * as process from \"process\";\nimport { Logger, LogLevel } from \"@itwin/core-bentley\";\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\nimport { IModelHost } from \"./IModelHost\";\n\n// cspell:ignore ppid elap\n\nconst loggerCategory: string = BackendLoggerCategory.DevTools;\n\ninterface StringIndexedObject<T> {\n [index: string]: T;\n}\n\n/**\n * Performance and Memory statistics of backend\n * @internal\n */\nexport interface DevToolsStats {\n os: DevToolsOsStats;\n process: DevToolsProcessStats;\n}\n\n/**\n * OS stats of backend\n * @internal\n */\nexport interface DevToolsOsStats {\n platform: NodeJS.Platform;\n hostname: string;\n totalmem: number;\n freemem: number;\n uptime: number;\n cpus: os.CpuInfo[];\n cpuUsage: number;\n}\n\n/**\n * Process stats of backend\n * @internal\n */\nexport interface DevToolsProcessStats {\n uptime: number;\n pid: number;\n ppid: number;\n memoryUsage: NodeJS.MemoryUsage;\n}\n\n/** Utility to format the JSON created by DevTools.stats() to include the appropriate units\n * @internal\n */\nexport class DevToolsStatsFormatter {\n private static readonly _megaByteProps = [\"totalmem\", \"freemem\", \"rss\", \"heapTotal\", \"heapUsed\", \"external\"];\n private static readonly _percentProps = [\"user\", \"nice\", \"sys\", \"idle\", \"irq\", \"cpuUsage\"];\n private static readonly _mHzProps = [\"speed\"];\n private static readonly _secondsProps = [\"uptime\"];\n\n /** Replacer that includes units - can be used with JSON.stringify() */\n private static _replacer = (key: string, value: any) => {\n if (DevToolsStatsFormatter._megaByteProps.includes(key))\n return `${value.toFixed()} MB`;\n if (DevToolsStatsFormatter._percentProps.includes(key))\n return `${value.toFixed()}%`;\n if (DevToolsStatsFormatter._mHzProps.includes(key))\n return `${value.toString()} MHz`;\n if (DevToolsStatsFormatter._secondsProps.includes(key))\n return `${value.toFixed()} secs`;\n return value;\n };\n\n /** Converts the input stats to another JSON object with the appropriate units setup for various fields */\n public static toFormattedJson(stats: any) {\n // Serialize the stats to a string with a replacer that sets up units during the serialization\n const statsStr = JSON.stringify(stats, DevToolsStatsFormatter._replacer);\n\n // Deserialize back to JSON\n return JSON.parse(statsStr);\n }\n}\n\n/**\n * Internal diagnostic utility\n * @internal\n */\nexport class DevTools {\n\n /** Receives a ping and returns true */\n public static ping(): boolean {\n Logger.logInfo(loggerCategory, \"Received ping at backend\");\n return true;\n }\n\n private static hrtimeToMS(hrtime: any) {\n return hrtime[0] * 1000 + hrtime[1] / 1000000;\n }\n\n private static bytesToMegaBytes(bytes: number): number {\n const megaBytes = bytes / Math.pow(1024, 2);\n return Math.round(megaBytes * 100) / 100;\n }\n\n private static evaluateCpuUsage(): number {\n const NUMBER_OF_CPUS = os.cpus().length;\n const startTime = process.hrtime();\n const startUsage = process.cpuUsage();\n\n // spin the CPU for 500 milliseconds\n const now = Date.now();\n while (Date.now() - now < 500)\n ;\n\n const elapTime = process.hrtime(startTime);\n const elapUsage = process.cpuUsage(startUsage);\n\n const elapTimeMS = this.hrtimeToMS(elapTime);\n\n const elapUserMS = elapUsage.user / 1000; // microseconds to milliseconds\n const elapSystMS = elapUsage.system / 1000;\n const cpuPercent = Math.round((100 * (elapUserMS + elapSystMS) / elapTimeMS / NUMBER_OF_CPUS));\n\n return cpuPercent;\n }\n\n private static evaluateCpus(): os.CpuInfo[] {\n // Create a clone\n const srcCpus = os.cpus();\n const cpus = new Array<os.CpuInfo>(srcCpus.length);\n let ii = 0;\n for (const srcCpu of srcCpus)\n cpus[ii++] = { ...srcCpu };\n\n // Evaluate cpu usage as percentages\n for (const cpu of Object.values(cpus)) {\n const total = Object.values(cpu.times).reduce((_total: number, currValue) => _total += currValue, 0);\n const cpuTimes = cpu.times as StringIndexedObject<number>;\n for (const type of Object.keys(cpuTimes)) {\n const cpuPercent = Math.round(100 * cpuTimes[type] / total);\n cpuTimes[type] = cpuPercent;\n }\n }\n return cpus;\n }\n\n private static evaluateMemoryUsage() {\n // Create a clone\n const memUsage = { ...process.memoryUsage() } as NodeJS.MemoryUsage;\n const memUsageObj = (memUsage as any) as StringIndexedObject<number>;\n // Evaluate memory usage as mega bytes\n for (const type of Object.keys(memUsageObj)) {\n memUsageObj[type] = this.bytesToMegaBytes(memUsageObj[type]);\n }\n return memUsage;\n }\n\n private static evaluateProcessStats(): DevToolsProcessStats {\n return {\n uptime: process.uptime(),\n pid: process.pid,\n ppid: process.ppid,\n memoryUsage: this.evaluateMemoryUsage(),\n } as DevToolsProcessStats;\n }\n\n private static evaluateOsStats(): DevToolsOsStats {\n return {\n platform: os.platform(),\n hostname: os.hostname(),\n totalmem: this.bytesToMegaBytes(os.totalmem()),\n freemem: this.bytesToMegaBytes(os.freemem()),\n uptime: os.uptime(),\n cpus: this.evaluateCpus(),\n cpuUsage: this.evaluateCpuUsage(),\n } as DevToolsOsStats;\n }\n\n /** Returns JSON object with backend statistics */\n public static stats(): DevToolsStats {\n try {\n const stats = {\n os: this.evaluateOsStats(),\n process: this.evaluateProcessStats(),\n } as DevToolsStats;\n return stats;\n } catch (error) {\n Logger.logError(loggerCategory, \"Could not fetch stats at backend\");\n throw error;\n }\n }\n\n /** Sets up a log level at the backend and returns the old log level */\n public static setLogLevel(inLoggerCategory: string, newLevel: LogLevel): LogLevel | undefined {\n const oldLevel = Logger.getLevel(inLoggerCategory);\n Logger.logInfo(loggerCategory, `Setting log level`, () => ({ loggerCategory: inLoggerCategory, oldLevel, newLevel }));\n Logger.setLevel(inLoggerCategory, newLevel);\n IModelHost.platform.clearLogLevelCache();\n return oldLevel;\n }\n\n /** Obtains the backend application and iTwin.js Core versions */\n public static versions() {\n return {\n application: IModelHost.applicationVersion,\n iTwinJs: require(\"../../package.json\").version, // eslint-disable-line @typescript-eslint/no-var-requires\n };\n }\n}\n"]}
@@ -1,107 +1,107 @@
1
- /** @packageDocumentation
2
- * @module ViewDefinitions
3
- */
4
- import { Id64Set, Id64String } from "@itwin/core-bentley";
5
- import { Code, CodeScopeProps, ColorDef, DisplayStyle3dProps, DisplayStyle3dSettings, DisplayStyle3dSettingsProps, DisplayStyleProps, DisplayStyleSettings, RenderSchedule, ViewFlags } from "@itwin/core-common";
6
- import { DefinitionElement } from "./Element";
7
- import { IModelCloneContext } from "./IModelCloneContext";
8
- import { IModelDb } from "./IModelDb";
9
- /** A DisplayStyle defines the parameters for 'styling' the contents of a view.
10
- * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.
11
- * Many ViewDefinitions may share the same DisplayStyle.
12
- * @public
13
- */
14
- export declare abstract class DisplayStyle extends DefinitionElement {
15
- /** @internal */
16
- static get className(): string;
17
- abstract get settings(): DisplayStyleSettings;
18
- /** @internal */
19
- protected constructor(props: DisplayStyleProps, iModel: IModelDb);
20
- /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.
21
- * @param iModel The IModelDb
22
- * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.
23
- * @param codeValue The DisplayStyle name
24
- */
25
- static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code;
26
- /** @alpha */
27
- protected collectReferenceIds(referenceIds: Id64Set): void;
28
- /** @alpha */
29
- protected static onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyleProps, targetElementProps: DisplayStyleProps): void;
30
- loadScheduleScript(): RenderSchedule.ScriptReference | undefined;
31
- }
32
- /** A DisplayStyle for 2d views.
33
- * @public
34
- */
35
- export declare class DisplayStyle2d extends DisplayStyle {
36
- /** @internal */
37
- static get className(): string;
38
- private readonly _settings;
39
- get settings(): DisplayStyleSettings;
40
- /** @internal */
41
- constructor(props: DisplayStyleProps, iModel: IModelDb);
42
- /** Create a DisplayStyle2d for use by a ViewDefinition.
43
- * @param iModelDb The iModel
44
- * @param definitionModelId The [[DefinitionModel]]
45
- * @param name The name/CodeValue of the DisplayStyle2d
46
- * @returns The newly constructed DisplayStyle2d element.
47
- * @throws [[IModelError]] if unable to create the element.
48
- */
49
- static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DisplayStyle2d;
50
- /** Insert a DisplayStyle2d for use by a ViewDefinition.
51
- * @param iModelDb Insert into this iModel
52
- * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel
53
- * @param name The name of the DisplayStyle2d
54
- * @returns The Id of the newly inserted DisplayStyle2d element.
55
- * @throws [[IModelError]] if unable to insert the element.
56
- */
57
- static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string): Id64String;
58
- }
59
- /** Describes initial settings for a new [[DisplayStyle3d]].
60
- * Most properties are inherited from [DisplayStyle3dSettingsProps]($common), but for backwards compatibility reasons, this interface is slightly awkward:
61
- * - It adds a `viewFlags` member that differs only in case and type from [DisplayStyleSettingsProps.viewflags]($common); and
62
- * - It extends the type of [DisplayStyleSettingsProps.backgroundColor]($common) to include [ColorDef]($common).
63
- * These idiosyncrasies will be addressed in a future version of core-backend.
64
- * @see [[DisplayStyle3d.create]].
65
- * @public
66
- */
67
- export interface DisplayStyleCreationOptions extends Omit<DisplayStyle3dSettingsProps, "backgroundColor" | "scheduleScript"> {
68
- /** If supplied, the [ViewFlags]($common) applied by the display style.
69
- * If undefined, [DisplayStyle3dSettingsProps.viewflags]($common) will be used if present (note the difference in case); otherwise, default-constructed [ViewFlags]($common) will be used.
70
- */
71
- viewFlags?: ViewFlags;
72
- backgroundColor?: ColorDef | number;
73
- }
74
- /** A DisplayStyle for 3d views.
75
- * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).
76
- * @public
77
- */
78
- export declare class DisplayStyle3d extends DisplayStyle {
79
- /** @internal */
80
- static get className(): string;
81
- private readonly _settings;
82
- get settings(): DisplayStyle3dSettings;
83
- /** @internal */
84
- constructor(props: DisplayStyle3dProps, iModel: IModelDb);
85
- /** @alpha */
86
- protected collectReferenceIds(referenceIds: Id64Set): void;
87
- /** @alpha */
88
- protected static onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyle3dProps, targetElementProps: DisplayStyle3dProps): void;
89
- /** Create a DisplayStyle3d for use by a ViewDefinition.
90
- * @param iModelDb The iModel
91
- * @param definitionModelId The [[DefinitionModel]]
92
- * @param name The name/CodeValue of the DisplayStyle3d
93
- * @returns The newly constructed DisplayStyle3d element.
94
- * @throws [[IModelError]] if unable to create the element.
95
- */
96
- static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): DisplayStyle3d;
97
- /**
98
- * Insert a DisplayStyle3d for use by a ViewDefinition.
99
- * @param iModelDb Insert into this iModel
100
- * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]
101
- * @param name The name of the DisplayStyle3d
102
- * @returns The Id of the newly inserted DisplayStyle3d element.
103
- * @throws [[IModelError]] if unable to insert the element.
104
- */
105
- static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): Id64String;
106
- }
1
+ /** @packageDocumentation
2
+ * @module ViewDefinitions
3
+ */
4
+ import { Id64Set, Id64String } from "@itwin/core-bentley";
5
+ import { Code, CodeScopeProps, ColorDef, DisplayStyle3dProps, DisplayStyle3dSettings, DisplayStyle3dSettingsProps, DisplayStyleProps, DisplayStyleSettings, RenderSchedule, ViewFlags } from "@itwin/core-common";
6
+ import { DefinitionElement } from "./Element";
7
+ import { IModelCloneContext } from "./IModelCloneContext";
8
+ import { IModelDb } from "./IModelDb";
9
+ /** A DisplayStyle defines the parameters for 'styling' the contents of a view.
10
+ * Internally a DisplayStyle consists of a dictionary of several named 'styles' describing specific aspects of the display style as a whole.
11
+ * Many ViewDefinitions may share the same DisplayStyle.
12
+ * @public
13
+ */
14
+ export declare abstract class DisplayStyle extends DefinitionElement {
15
+ /** @internal */
16
+ static get className(): string;
17
+ abstract get settings(): DisplayStyleSettings;
18
+ /** @internal */
19
+ protected constructor(props: DisplayStyleProps, iModel: IModelDb);
20
+ /** Create a Code for a DisplayStyle given a name that is meant to be unique within the scope of the specified DefinitionModel.
21
+ * @param iModel The IModelDb
22
+ * @param scopeModelId The Id of the DefinitionModel that contains the DisplayStyle and provides the scope for its name.
23
+ * @param codeValue The DisplayStyle name
24
+ */
25
+ static createCode(iModel: IModelDb, scopeModelId: CodeScopeProps, codeValue: string): Code;
26
+ /** @alpha */
27
+ protected collectReferenceIds(referenceIds: Id64Set): void;
28
+ /** @alpha */
29
+ protected static onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyleProps, targetElementProps: DisplayStyleProps): void;
30
+ loadScheduleScript(): RenderSchedule.ScriptReference | undefined;
31
+ }
32
+ /** A DisplayStyle for 2d views.
33
+ * @public
34
+ */
35
+ export declare class DisplayStyle2d extends DisplayStyle {
36
+ /** @internal */
37
+ static get className(): string;
38
+ private readonly _settings;
39
+ get settings(): DisplayStyleSettings;
40
+ /** @internal */
41
+ constructor(props: DisplayStyleProps, iModel: IModelDb);
42
+ /** Create a DisplayStyle2d for use by a ViewDefinition.
43
+ * @param iModelDb The iModel
44
+ * @param definitionModelId The [[DefinitionModel]]
45
+ * @param name The name/CodeValue of the DisplayStyle2d
46
+ * @returns The newly constructed DisplayStyle2d element.
47
+ * @throws [[IModelError]] if unable to create the element.
48
+ */
49
+ static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string): DisplayStyle2d;
50
+ /** Insert a DisplayStyle2d for use by a ViewDefinition.
51
+ * @param iModelDb Insert into this iModel
52
+ * @param definitionModelId Insert the new DisplayStyle2d into this DefinitionModel
53
+ * @param name The name of the DisplayStyle2d
54
+ * @returns The Id of the newly inserted DisplayStyle2d element.
55
+ * @throws [[IModelError]] if unable to insert the element.
56
+ */
57
+ static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string): Id64String;
58
+ }
59
+ /** Describes initial settings for a new [[DisplayStyle3d]].
60
+ * Most properties are inherited from [DisplayStyle3dSettingsProps]($common), but for backwards compatibility reasons, this interface is slightly awkward:
61
+ * - It adds a `viewFlags` member that differs only in case and type from [DisplayStyleSettingsProps.viewflags]($common); and
62
+ * - It extends the type of [DisplayStyleSettingsProps.backgroundColor]($common) to include [ColorDef]($common).
63
+ * These idiosyncrasies will be addressed in a future version of core-backend.
64
+ * @see [[DisplayStyle3d.create]].
65
+ * @public
66
+ */
67
+ export interface DisplayStyleCreationOptions extends Omit<DisplayStyle3dSettingsProps, "backgroundColor" | "scheduleScript"> {
68
+ /** If supplied, the [ViewFlags]($common) applied by the display style.
69
+ * If undefined, [DisplayStyle3dSettingsProps.viewflags]($common) will be used if present (note the difference in case); otherwise, default-constructed [ViewFlags]($common) will be used.
70
+ */
71
+ viewFlags?: ViewFlags;
72
+ backgroundColor?: ColorDef | number;
73
+ }
74
+ /** A DisplayStyle for 3d views.
75
+ * See [how to create a DisplayStyle3d]$(docs/learning/backend/CreateElements.md#DisplayStyle3d).
76
+ * @public
77
+ */
78
+ export declare class DisplayStyle3d extends DisplayStyle {
79
+ /** @internal */
80
+ static get className(): string;
81
+ private readonly _settings;
82
+ get settings(): DisplayStyle3dSettings;
83
+ /** @internal */
84
+ constructor(props: DisplayStyle3dProps, iModel: IModelDb);
85
+ /** @alpha */
86
+ protected collectReferenceIds(referenceIds: Id64Set): void;
87
+ /** @alpha */
88
+ protected static onCloned(context: IModelCloneContext, sourceElementProps: DisplayStyle3dProps, targetElementProps: DisplayStyle3dProps): void;
89
+ /** Create a DisplayStyle3d for use by a ViewDefinition.
90
+ * @param iModelDb The iModel
91
+ * @param definitionModelId The [[DefinitionModel]]
92
+ * @param name The name/CodeValue of the DisplayStyle3d
93
+ * @returns The newly constructed DisplayStyle3d element.
94
+ * @throws [[IModelError]] if unable to create the element.
95
+ */
96
+ static create(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): DisplayStyle3d;
97
+ /**
98
+ * Insert a DisplayStyle3d for use by a ViewDefinition.
99
+ * @param iModelDb Insert into this iModel
100
+ * @param definitionModelId Insert the new DisplayStyle3d into this [[DefinitionModel]]
101
+ * @param name The name of the DisplayStyle3d
102
+ * @returns The Id of the newly inserted DisplayStyle3d element.
103
+ * @throws [[IModelError]] if unable to insert the element.
104
+ */
105
+ static insert(iModelDb: IModelDb, definitionModelId: Id64String, name: string, options?: DisplayStyleCreationOptions): Id64String;
106
+ }
107
107
  //# sourceMappingURL=DisplayStyle.d.ts.map