mirror of
https://github.com/retorquere/zotero-better-bibtex.git
synced 2022-05-23 09:36:29 +03:00
memory trace
This commit is contained in:
12
.trace.json
12
.trace.json
@@ -2,8 +2,18 @@
|
||||
"gh-1896": {
|
||||
"plugin": [
|
||||
"content/better-bibtex.ts",
|
||||
"content/key-manager.ts",
|
||||
"content/serializer.ts",
|
||||
"content/db/*.ts"
|
||||
"content/db/*.ts",
|
||||
"content/auto-export.ts",
|
||||
"content/dateparser.ts",
|
||||
"content/escape.ts",
|
||||
"content/get-items-async.ts",
|
||||
"content/journal-abbrev.ts",
|
||||
"content/markupparser.ts",
|
||||
"content/scheduler.ts",
|
||||
"content/startup.ts",
|
||||
"content/translators.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +74,6 @@
|
||||
|
||||
<hbox>
|
||||
<button label="&better-bibtex.ErrorReport.save;" oncommand="bbt_errorreport.save()"/>
|
||||
<button label="Memory use" oncommand="Zotero.openInViewer('about:memory')"/>
|
||||
<button label="Garbage collect" oncommand="gc()"/>
|
||||
<hbox flex="1"/>
|
||||
</hbox>
|
||||
<description id="better-bibtex-error-memory-use" style="white-space: pre-wrap;"></description>
|
||||
|
||||
@@ -8,13 +8,13 @@ declare const AsyncShutdown: any
|
||||
|
||||
import { patch as $patch$ } from '../monkey-patch'
|
||||
|
||||
import AJV from 'ajv'
|
||||
import { log } from '../logger'
|
||||
// import { Preferences as Prefs } from '../prefs'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle,id-blacklist,id-match
|
||||
import Loki = require('lokijs')
|
||||
|
||||
import AJV from 'ajv'
|
||||
const validator = new AJV({ useDefaults: true, coerceTypes: true })
|
||||
require('ajv-keywords')(validator)
|
||||
|
||||
|
||||
@@ -14,24 +14,30 @@ import * as Extra from './extra'
|
||||
import { $and } from './db/loki'
|
||||
import { defaults } from '../gen/preferences/meta'
|
||||
import { Preference } from '../gen/preferences'
|
||||
import * as memory from './memory'
|
||||
// import * as memory from './memory'
|
||||
|
||||
const setatstart: string[] = ['workersMax', 'testing', 'caching'].filter(p => Preference[p] !== defaults[p])
|
||||
|
||||
export class TestSupport {
|
||||
// private residentMem: number
|
||||
|
||||
/*
|
||||
constructor() {
|
||||
// log memory use every second to try to pinpoint the memory leak
|
||||
let memuse = memory.resident()
|
||||
log.debug('memory use:', memuse)
|
||||
setInterval(() => {
|
||||
// (window as any).QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils).garbageCollect()
|
||||
const memcur = memory.resident()
|
||||
const memdiff = memcur - memuse
|
||||
log.debug(`memory use: ${memcur} (${memdiff < 0 ? '' : '+'}${memdiff})`)
|
||||
memuse = memcur
|
||||
}, 1000) // eslint-disable-line no-magic-numbers
|
||||
this.residentMem = memory.resident()
|
||||
log.debug('memory use:', this.residentMem)
|
||||
setInterval(() => { this.logMemoryUse() }, 500) // eslint-disable-line no-magic-numbers
|
||||
}
|
||||
|
||||
public logMemoryUse(msg = ''): void {
|
||||
// (window as any).QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils).garbageCollect()
|
||||
const memcur = memory.resident()
|
||||
const memdiff = memcur - this.residentMem
|
||||
log.debug(`${msg}memory use: ${memcur} (${memdiff < 0 ? '' : '+'}${memdiff})`)
|
||||
this.residentMem = memcur
|
||||
}
|
||||
*/
|
||||
|
||||
public removeAutoExports(): void {
|
||||
AutoExport.db.findAndRemove({ type: { $ne: '' } })
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ module.exports.__dirname = {
|
||||
setup(build) {
|
||||
build.onLoad({ filter: /\/node_modules\/.+\.js$/ }, async (args) => {
|
||||
let contents = await fs.promises.readFile(args.path, 'utf-8')
|
||||
const filename = 'resource://zotero-better-bibtex/' + args.path.replace(/.*\/node_modules\/(\.pnpm)?/, '')
|
||||
const filename = 'resource://zotero-better-bibtex/' + (args.path.includes('/node_modules/') ? args.path.replace(/.*\/node_modules\//, '') : path.resolve(__dirname, args.path))
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
contents = [
|
||||
@@ -169,16 +169,16 @@ module.exports.trace = function(section) {
|
||||
|
||||
try {
|
||||
const estrace = await import('estrace/plugin');
|
||||
const {code} = putout(source.code, {
|
||||
let {code} = putout(source.code, {
|
||||
fixCount: 1,
|
||||
rules: {
|
||||
'estrace/trace': ['on', { url: `file://${args.path}`, exclude: [ 'FunctionExpression', 'ArrowFunctionExpression' ] }],
|
||||
'estrace/trace': ['on', { url: localpath, exclude: [ 'FunctionExpression', 'ArrowFunctionExpression' ] }],
|
||||
},
|
||||
plugins: [ estrace ],
|
||||
})
|
||||
|
||||
return {
|
||||
contents: prefix + code,
|
||||
contents: `${prefix};${code}`,
|
||||
loader: 'js',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,54 @@
|
||||
;if (typeof Zotero !== 'undefined' && Zotero.Debug) Zotero.Debug.enabled = true
|
||||
|
||||
const __estrace = {
|
||||
depth: 0,
|
||||
hold: '',
|
||||
prefix: 'zotero(?)(+0000000): ',
|
||||
MB: 1024 * 1024,
|
||||
|
||||
ready() {
|
||||
if (!Zotero
|
||||
|| !Zotero.BetterBibTeX
|
||||
|| !Zotero.BetterBibTeX.ready
|
||||
|| Zotero.BetterBibTeX.ready.isPending()
|
||||
|| !Zotero.BetterBibTeX.TestSupport
|
||||
) return false
|
||||
|
||||
if (!Zotero.BetterBibTeX.TestSupport.memoryReporterManager) {
|
||||
Zotero.BetterBibTeX.TestSupport.memoryReporterManager = Components.classes['@mozilla.org/memory-reporter-manager;1'].getService(Components.interfaces.nsIMemoryReporterManager)
|
||||
Zotero.BetterBibTeX.TestSupport.memoryReporterManager.init()
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
mem() {
|
||||
if (!this.ready()) return ''
|
||||
let memInUse = Zotero.BetterBibTeX.TestSupport.memoryReporterManager.resident / this.MB
|
||||
if (!this.memInUse) this.memAtStart = this.memInUse = memInUse
|
||||
if (memInUse == this.memInUse) return ''
|
||||
const diff = {
|
||||
start: `${memInUse > this.memAtStart ? '+' : ''}${memInUse - this.memAtStart}`,
|
||||
recent: `${memInUse > this.memInUse ? '+' : ''}${memInUse - this.memInUse}`,
|
||||
}
|
||||
this.memInUse = memInUse
|
||||
return ` (memory in use: ${memInUse}) (${diff.recent} / ${diff.start})`
|
||||
},
|
||||
|
||||
enter(name, url, args) {
|
||||
const replacer = this.circularReplacer()
|
||||
Zotero.debug(`bbt.trace.enter ${url}.${name}`)
|
||||
if (name.startsWith('<anonymous')) return
|
||||
this.log(`bbt.trace.enter ${url} : ${name}`)
|
||||
// const replacer = this.circularReplacer()
|
||||
//this.report(`bbt trace.enter ${url}.${name}(${Array.from(args).map(arg => JSON.stringify(arg, replacer)).join(', ')})`)
|
||||
//this.state(1)
|
||||
},
|
||||
|
||||
exit(name, url, result) {
|
||||
Zotero.debug(`bbt.trace.exit ${url}.${name}`)
|
||||
// this.state(-1)
|
||||
if (name.startsWith('<anonymous')) return
|
||||
this.log(`bbt.trace.exit ${url} : ${name}${this.mem()}`)
|
||||
// this.report(`bbt trace.exit ${url}.${name} => ${JSON.stringify(result, this.circularReplacer())}`)
|
||||
},
|
||||
|
||||
state(inc) {
|
||||
const zotero = typeof Zotero !== 'undefined'
|
||||
const debug = zotero && Zotero.Debug
|
||||
const bbt = zotero && typeof Zotero.BetterBibTeX !== 'undefined'
|
||||
const ready = bbt && Zotero.BetterBibTeX.ready && !Zotero.BetterBibTeX.ready.isPending()
|
||||
const host = bbt ? Zotero.BetterBibTeX : this
|
||||
|
||||
host.trace$depth = host.trace$depth || 0
|
||||
if (inc) host.trace$depth += inc
|
||||
|
||||
return {
|
||||
depth: Math.max(host.trace$depth, 0),
|
||||
zotero: {
|
||||
loaded: zotero,
|
||||
ready: debug,
|
||||
},
|
||||
bbt: {
|
||||
loaded: bbt,
|
||||
ready: ready,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
report(msg) {
|
||||
const state = this.state()
|
||||
|
||||
msg = ' '.repeat(state.depth || 0) + msg
|
||||
if (!state.zotero.loaded) {
|
||||
msg = `Before Zotero load: ${msg}`
|
||||
}
|
||||
else if (!state.zotero.ready) {
|
||||
msg = `Zotero loaded, but not debug-ready: ${msg}`
|
||||
}
|
||||
else if (!state.bbt.loaded) {
|
||||
msg = `Zotero ready, BBT not loaded: ${msg}`
|
||||
}
|
||||
else if (!state.bbt.ready) {
|
||||
msg = `Zotero ready, BBT not ready: ${msg}`
|
||||
}
|
||||
|
||||
log(msg) {
|
||||
const now = Date.now()
|
||||
if (state.zotero.ready && (!this.last || (now - this.last) > 1000)) {
|
||||
if (this.ready() && (!this.last || (now - this.last) > 1000)) {
|
||||
Zotero.debug((this.hold ? this.hold.replace(this.prefix, '') + this.prefix : '') + msg)
|
||||
this.last = now
|
||||
this.hold = ''
|
||||
|
||||
@@ -563,6 +563,7 @@ class Zotero:
|
||||
if self.config.db: install_xpis(os.path.join(ROOT, 'test/db', self.config.db, 'xpis'), profile.firefox)
|
||||
if self.config.profile: install_xpis(os.path.join(ROOT, 'test/db', self.config.profile, 'xpis'), profile.firefox)
|
||||
|
||||
profile.firefox.set_preference('extensions.zotero.debug.memoryInfo', True)
|
||||
profile.firefox.set_preference('extensions.zotero.translators.better-bibtex.testing', self.testing)
|
||||
profile.firefox.set_preference('extensions.zotero.translators.better-bibtex.workersMax', self.workers)
|
||||
profile.firefox.set_preference('extensions.zotero.translators.better-bibtex.caching', self.workers)
|
||||
|
||||
Reference in New Issue
Block a user