Skip to content

Commit

Permalink
step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-intel committed Oct 30, 2024
1 parent f17274f commit e4c1cb1
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
22 changes: 18 additions & 4 deletions src/plugins/intel_cpu/tools/commit_slider/commit_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
from distutils.dir_util import copy_tree
from distutils.errors import DistutilsFileError
from utils.cfg_manager import CfgManager
from utils.helpers import safeClearDir, getParams

args, cfgData, customCfgPath = getParams()
Expand Down Expand Up @@ -50,13 +51,24 @@
p.printResult()

else:
# prepare run
workPath = cfgData["workPath"]
if not os.path.exists(workPath):
os.mkdir(workPath)
else:
safeClearDir(workPath, cfgData)
curPath = os.getcwd()
copy_tree(curPath, workPath)
# handle user cache path
tempCachePath = CfgManager.singlestepStrFormat(cfgData["cachePath"], "workPath", workPath)
permCachePath = CfgManager.singlestepStrFormat(cfgData["cachePath"], "workPath", curPath)
# setup cache path if specified
if cfgData['userCachePath']:
permCachePath = cfgData['userCachePath']
else:
cfgData['userCachePath'] = permCachePath

# run CS
scriptName = os.path.basename(__file__)
argString = " ".join(sys.argv)
formattedCmd = "{py} {workPath}/{argString} -wd".format(
Expand All @@ -65,14 +77,16 @@
subprocess.call(formattedCmd.split())

# copy logs and cache back to general repo
tempLogPath = cfgData["logPath"].format(workPath=workPath)
permLogPath = cfgData["logPath"].format(workPath=curPath)
tempLogPath = CfgManager.singlestepStrFormat(cfgData["logPath"], "workPath", workPath)
permLogPath = CfgManager.singlestepStrFormat(cfgData["logPath"], "workPath", curPath)

if cfgData['userLogPath']:
permLogPath = cfgData['userLogPath']

safeClearDir(permLogPath, cfgData)
if not cfgData['clearLogsAposteriori']:
copy_tree(tempLogPath, permLogPath)

tempCachePath = cfgData["cachePath"].format(workPath=workPath)
permCachePath = cfgData["cachePath"].format(workPath=curPath)
safeClearDir(permCachePath, cfgData)
try:
copy_tree(tempCachePath, permCachePath)
Expand Down
29 changes: 21 additions & 8 deletions src/plugins/intel_cpu/tools/commit_slider/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import shutil
from os import path
from utils.cfg_manager import CfgManager
from test_data import TestData
from test_data import TestError
from utils.helpers import formatJSON
Expand Down Expand Up @@ -154,8 +155,15 @@ def getActualCommit(td: TestData):

# prepare config
cfg = formatJSON(td.testCfg, td.formatConfig)
cfg['logPath'] = td.logPath
cfg['clearLogsAposteriori'] = td.clearLogsAposteriori
td.userLogPath = CfgManager.singlestepStrFormat(
td.userLogPath, "testDir", os.getcwd())
td.userCachePath = CfgManager.singlestepStrFormat(
td.userCachePath, "testDir", os.getcwd())
for key in [
'userLogPath', 'clearLogsAposteriori',
'userCachePath', 'clearCache'
]:
cfg[key] = getattr(td, key)
testCfg = "test_cfg.json"

with open(testCfg, "w+") as customCfg:
Expand All @@ -173,7 +181,8 @@ def getActualCommit(td: TestData):
# clear temp data
[shutil.rmtree(dir) for dir in [
td.repoName,
td.cachePath
td.userCachePath,
td.userLogPath
]]
os.remove(testCfg)

Expand Down Expand Up @@ -222,11 +231,15 @@ def requireBinarySearchData(td: TestData, rsc: map):
'testCfg', 'patchedFile', 'repoName'
]]
)

[setattr(td, key, td.commonRsc[key]) for key in [
'repoStructure', 'cachePath', 'logPath',
'clearLogsAposteriori', 'mainFile', 'repoPath'
] if not hasattr(td, key)]
[setattr(td, key, td.commonRsc[key] \
if not key in td.testCfg \
else td.testCfg[key]) for key in [
'repoStructure',
'userCachePath',
'userLogPath',
'clearLogsAposteriori', 'clearCache',
'mainFile', 'repoPath'
]]
td.patternPrefix = td.commonRsc['patchGeneratorPrefix']
td.patternPostfix = td.commonRsc['patchGeneratorPostfix']
td.pattern = "{pre}(.+?){post}".format(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"binarySearchRes": {
"repoPath": "./",
"cachePath": "../slider_cache",
"logPath" : "{workPath}/log/",
"userCachePath": "{testDir}/test_cache/",
"userLogPath" : "{testDir}/test_log/",
"clearLogsAposteriori" : true,
"clearCache" : true,
"patchGeneratorPrefix": "const char \\*patchGenerator = R\"V0G0N\\(",
"patchGeneratorPostfix": "\\)V0G0N\";",
"mainFile": "main.cpp",
Expand Down Expand Up @@ -42,7 +43,8 @@
"appCmd" : "{appCmd}",
"appPath": "{appPath}",
"gitPath" : "{gitPath}",
"logPath" : "{workPath}/sub_log/",
"userLogPath" : "{testDir}/test_log/sub_log/",
"clearLogsAposteriori" : false,
"buildPath" : "{buildPath}",
"verboseOutput": false,
"runConfig" : {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/intel_cpu/tools/commit_slider/utils/cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
"appPath" : "../../../../../bin/intel64/Release/",
"buildPath" : "../../../../../build/",
"cachePath" : "{workPath}/slider_cache/",
"userCachePath" : "",
"logPath" : "{workPath}/log/",
"userLogPath" : "",
"clearLogsAposteriori" : false,
"workPath" : "will be defined in runtime",
"linWorkPath" : "/tmp/commit_slider_tool",
Expand Down
32 changes: 24 additions & 8 deletions src/plugins/intel_cpu/tools/commit_slider/utils/common_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, cfg) -> None:
self.commonLogger = util.setupLogger(
"commonLogger", logPath, "common_log.log"
)
self.checkOutPathPattern = "check_output_cache.json"

def isPerformanceBased(self):
return False
Expand All @@ -45,22 +46,37 @@ def createCash(self):
cp = util.getActualPath("cachePath", self.cfg)
if not os.path.exists(cp):
os.makedirs(cp)
self.cachePath = os.path.join(cp, "check_output_cache.json")
self.cachePath = os.path.join(cp, self.checkOutPathPattern)
initCacheMap = {}
self.commonLogger.info("Cache created")
self.commonLogger.info("Work cache:")
self.commonLogger.info(self.cachePath)
self.commonLogger.info("User cache:")
self.commonLogger.info(self.cfg["userCachePath"])
# check if old cache must be reused
userCachePath = os.path.join(
self.cfg["userCachePath"],
self.checkOutPathPattern)
try:
with open(self.cachePath, "r+") as cacheDump:
with open(userCachePath, "r+") as cacheDump:
if self.cfg["clearCache"]:
cacheDump.truncate(0)
json.dump(initCacheMap, cacheDump)
# we don't need old cache
pass
else:
try:
json.load(cacheDump)
# check if JSON is valid
initCacheMap = json.load(cacheDump)
except json.decoder.JSONDecodeError:
json.dump(initCacheMap, cacheDump)
cacheDump.close()
except FileNotFoundError:
with open(self.cachePath, "w") as cacheDump:
json.dump(initCacheMap, cacheDump)
cacheDump.close()
# no old cache, never mind
pass

# create work cache
with open(self.cachePath, "w") as workCacheDump:
json.dump(initCacheMap, workCacheDump)
workCacheDump.close()

def getCommitIfCashed(self, commit):
with open(self.cachePath, "r") as cacheDump:
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_cpu/tools/commit_slider/utils/modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ def setCommitCash(self, commit, valueToCache):
def createCash(self):
# we use separate files instead of json cache,
# so, we just set up path to cache folder
# todo: handle usercache for multimodel case
self.cachePath = getActualPath("cachePath", self.cfg)
pass

Expand Down

0 comments on commit e4c1cb1

Please sign in to comment.