Skip to content

Commit

Permalink
btrace: Support JSON-format output (#270)
Browse files Browse the repository at this point in the history
Signed-off-by: Peace Lee <[email protected]>
  • Loading branch information
iipeace committed Oct 1, 2021
1 parent d46f401 commit d2eec17
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "210930"
__revision__ = "211001"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -4855,8 +4855,9 @@ def convCpuColor(value, string=None, size=1, align='right'):
def convColor(string, color='LIGHT', size=1, align='right'):
if not SysMgr.colorEnable or not color or \
SysMgr.outPath or SysMgr.outputFile or \
(not SysMgr.isLinux and not SysMgr.isDarwin) or \
SysMgr.remoteRun:
SysMgr.jsonEnable or SysMgr.remoteRun or \
(not SysMgr.isLinux and not SysMgr.isDarwin):
SysMgr.colorEnable = False
return string

if align == 'right':
Expand Down Expand Up @@ -24912,6 +24913,7 @@ def printHelp(force=False):
-m <ROWS:COLS:SYSTEM> set terminal size
-E <DIR> set cache dir path
-q <NAME{:VALUE}> set environment variables
-J print in JSON format
-v verbose
'''

Expand Down Expand Up @@ -59184,6 +59186,7 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):
hasRetFilter = False
elapsed = ''
callString = ''
jsonData = {}
etime = None
cmds = None
skip = False
Expand Down Expand Up @@ -59226,9 +59229,22 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):
else:
elapsed = convColor(elapsed, 'CYAN')

# build context string #
callString = '\n%s %s%s%s%s%s%s' % \
(diffstr, tinfo, indent, sym, retstr, elapsed, addStr)
# build output #
if SysMgr.jsonEnable:
jsonData = {
'time': diffstr,

This comment has been minimized.

Copy link
@elfring

elfring Oct 1, 2021

I wonder why such a value would be needed to be treated as a string at the moment.

'task': tinfo if tinfo \
else '%s(%s)' % (self.comm, self.pid),
'symbol': sym,
'return': retstr.lstrip('='),
'elapsed': elapsed.lstrip('/'),

This comment has been minimized.

Copy link
@elfring

elfring Oct 1, 2021

Will an integral (or floating-point) data type become nicer for such values (instead of string usage)?

This comment has been minimized.

Copy link
@iipeace

iipeace Oct 2, 2021

Author Owner

This output can be printed to file or stdout or socket as a string type.
I think type of values is not important because all of them will be in a string finally.

This comment has been minimized.

Copy link
@elfring

elfring Oct 2, 2021

I think type of values is not important

I disagree to this view.

because all of them will be in a string finally.

I would like to improve affected data processing details.

'caller': addStr.lstrip('-> ')
}
else:
# build context string #
callString = '\n%s %s%s%s%s%s%s' % \
(diffstr, tinfo, indent, sym, retstr,
elapsed, addStr)
except SystemExit:
sys.exit(0)
except:
Expand All @@ -59240,13 +59256,31 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):
if origSym in self.retCmdList:
cmds = self.retCmdList[origSym]
else:
# build current symbol string #
callString = '\n%s %s%s%s%s/%s%s [%s]' % \
(diffstr, tinfo, indent, convColor(sym, symColor),
elapsed, hex(addr).rstrip('L'), argstr,
convColor(fname, 'YELLOW'))
if SysMgr.jsonEnable:
jsonData = {
'time': diffstr,
'task': tinfo if tinfo \
else '%s(%s)' % (self.comm, self.pid),
'symbol': sym,
'args': argstr,
'file': fname
}
else:
# build current symbol string #
callString = '\n%s %s%s%s%s/%s%s [%s]' % \
(diffstr, tinfo, indent, convColor(sym, symColor),
elapsed, hex(addr).rstrip('L'), argstr,
convColor(fname, 'YELLOW'))

# print output #
if jsonData:
if btstr:
jsonData['backtrace'] = btstr.lstrip()

SysMgr.printPipe(
UtilMgr.convDict2Str(jsonData, pretty=False), flush=True)

if callString:
elif callString:
# emphasize string #
if hasRetFilter and not skip:
callString = convColor(callString, 'CYAN')
Expand Down Expand Up @@ -59274,6 +59308,7 @@ def printBpContext(self, sym, addr, fname, checkArg, origPC):
else:
SysMgr.printPipe(callString, newline=False, flush=True)

if jsonData or callString:
# handle repeat command #
if isRetBp and origPC != self.pc:
self.handleBp(True, checkArg)
Expand Down

3 comments on commit d2eec17

@elfring
Copy link

@elfring elfring commented on d2eec17 Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will a better JSON schema become relevant for efficient data processing?

@iipeace
Copy link
Owner Author

@iipeace iipeace commented on d2eec17 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elfring, do you wanna output for structured data consist of various types?

@elfring
Copy link

@elfring elfring commented on d2eec17 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yes.

I would like to achieve a distinction for numerical data types in comparison to others for the discussed software analyses.

Please sign in to comment.