Skip to content

Commit 73e3d43

Browse files
author
Zhen Li
committed
Adding missing profile statistics
1 parent 966e8c2 commit 73e3d43

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

src/result-summary.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,24 @@ class ProfiledPlan {
174174
this.operatorType = profile.operatorType
175175
this.identifiers = profile.identifiers
176176
this.arguments = profile.args
177-
this.dbHits = intValue(profile.args.DbHits)
178-
this.rows = intValue(profile.args.Rows)
177+
this.dbHits = valueOrDefault('dbHits', profile)
178+
this.rows = valueOrDefault('rows', profile)
179+
this.pageCacheMisses = valueOrDefault('pageCacheMisses', profile)
180+
this.pageCacheHits = valueOrDefault('pageCacheHits', profile)
181+
this.pageCacheHitRatio = valueOrDefault('pageCacheHitRatio', profile)
182+
this.time = valueOrDefault('time', profile)
179183
this.children = profile.children
180184
? profile.children.map(child => new ProfiledPlan(child))
181185
: []
182186
}
187+
188+
hasPageCacheStats () {
189+
return (
190+
this.pageCacheMisses > 0 ||
191+
this.pageCacheHits > 0 ||
192+
this.pageCacheHitRatio > 0
193+
)
194+
}
183195
}
184196

185197
/**
@@ -308,6 +320,15 @@ function intValue (value) {
308320
return isInt(value) ? value.toInt() : value
309321
}
310322

323+
function valueOrDefault (key, values, defaultValue = 0) {
324+
if (key in values) {
325+
const value = values[key]
326+
return isInt(value) ? value.toInt() : value
327+
} else {
328+
return defaultValue
329+
}
330+
}
331+
311332
const statementType = {
312333
READ_ONLY: 'r',
313334
READ_WRITE: 'rw',

test/session.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import SingleConnectionProvider from '../src/internal/connection-provider-single
2525
import FakeConnection from './internal/fake-connection'
2626
import sharedNeo4j from './internal/shared-neo4j'
2727
import _ from 'lodash'
28-
import { ServerVersion, VERSION_4_0_0 } from '../src/internal/server-version'
2928
import { isString } from '../src/internal/util'
3029
import testUtils from './internal/test-utils'
3130
import { newError, PROTOCOL_ERROR, SESSION_EXPIRED } from '../src/error'
@@ -299,7 +298,6 @@ describe('#integration session', () => {
299298
expect(sum.profile.identifiers[0]).toBe('n')
300299
expect(sum.profile.children[0].operatorType).toBeDefined()
301300
expect(sum.profile.rows).toBe(0)
302-
// expect(sum.profile.dbHits).toBeGreaterThan(0);
303301
done()
304302
})
305303
})

test/summary.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ describe('#integration result summary', () => {
153153

154154
expect(profile.dbHits).toBe(0)
155155
expect(profile.rows).toBe(1)
156+
expect(profile.time).toBe(0)
157+
expect(profile.hasPageCacheStats()).toBe(false)
156158

157159
done()
158160
})

test/types/result-summary.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ const profileIdentifiers: string[] = profile.identifiers
5656
const profileArguments: { [key: string]: string } = profile.arguments
5757
const profileDbHits: number = profile.dbHits
5858
const profileRows: number = profile.rows
59+
const hasPageCacheStats: boolean = profile.hasPageCacheStats()
60+
const profilePageCacheMisses: number = profile.pageCacheMisses
61+
const profilePageCacheHits: number = profile.pageCacheHits
62+
const profilePageCacheHitRatio: number = profile.pageCacheHitRatio
63+
const time: number = profile.time
5964
const profileChildren: ProfiledPlan[] = profile.children
6065

6166
const notifications: Notification[] = sum1.notifications

types/result-summary.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ declare interface ProfiledPlan {
4949
arguments: { [key: string]: string }
5050
dbHits: number
5151
rows: number
52+
pageCacheMisses: number
53+
pageCacheHits: number
54+
pageCacheHitRatio: number
55+
time: number
56+
57+
hasPageCacheStats(): boolean
58+
5259
children: ProfiledPlan[]
5360
}
5461

0 commit comments

Comments
 (0)