-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysisNodeProf.js
More file actions
99 lines (77 loc) · 2.65 KB
/
Copy pathAnalysisNodeProf.js
File metadata and controls
99 lines (77 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//DO NOT INSTRUMENT
// Libraries
const fs = require('fs')
const path = require('path')
const dotenv = require('dotenv')
// Errors
const ERROR_PARSING_JSON = require('../error/Constant.error.js').ERROR_PARSING_JSON
// Configurations
const AnalysisLoggerNodeProf = require('../helper/AnalysisLoggerNodeProf.helper')
// Imports
const {
getStaticAnalysisSummary,
extractInvocationLocation,
includesLocation,
findLocation
} = require('../helper/DynamicAnalyzerNodeProf.helper')
const { revive } = require('../model/Repository.model')
;(function (sandbox) {
const cliArgs = process.argv.slice(2)
const servicePath = cliArgs[2]
const serviceName = servicePath.split(path.sep).pop()
const staticAnalysisResultPath = cliArgs[cliArgs.length - 1]
const logger = AnalysisLoggerNodeProf.getLogger(serviceName)
function loadEnv() {
process.chdir(servicePath)
dotenv.config({ path: path.join(servicePath, '.env') })
}
function getJsonContent(staticAnalysisResultPath) {
try {
const fileData = fs.readFileSync(staticAnalysisResultPath, 'utf8')
return JSON.parse(fileData)
} catch (parseErr) {
logger.error(ERROR_PARSING_JSON, parseErr)
}
}
const staticAnalysisContent = getJsonContent(staticAnalysisResultPath)
const staticAnalysisRepositories = staticAnalysisContent.map((repositoryJson) =>
revive(repositoryJson)
)
const staticAnalysisSummary = getStaticAnalysisSummary(staticAnalysisRepositories, servicePath)
loadEnv()
function DynamicAnalysis() {
this.invokeFun = function (iid, f, base, args, result, isConstructor, isMethod, functionIid) {
let invocationData = undefined
try {
invocationData = extractInvocationLocation(J$.iidToLocation(iid))
} catch (e) {
logger.warning({
message: 'Unexpected location',
receivedValue: J$.iidToLocation(iid),
timestamp: Date.now()
})
}
const filePath = invocationData?.getFilePath()
if (!invocationData) {
return { f: f, base: base, args: args, skip: false }
}
const invokedFileLocations = staticAnalysisSummary[filePath]
if (
invokedFileLocations &&
includesLocation(invokedFileLocations, invocationData.getFileLocation())
) {
let codeFragmentLocation = findLocation(
invokedFileLocations,
invocationData.getFileLocation()
)
logger.trace({
location: codeFragmentLocation.getFilePath(),
timestamp: Date.now(),
argumentValues: args
})
}
return { f: f, base: base, args: args, skip: false }
}
}
sandbox.analysis = new DynamicAnalysis()
})(J$)