Skip to content

Commit

Permalink
DecodeUefiLog separate by size feature (#631)
Browse files Browse the repository at this point in the history
## Description

DecodeUefiLog separate by size feature

For details on how to complete these options and their meaning refer to
[CONTRIBUTING.md](https://github.com/microsoft/mu/blob/HEAD/CONTRIBUTING.md).

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [X] Includes documentation?
- [X] Backport to release branch?

## How This Was Tested

Test DecodeUefiLog with "-size" command and check output file size and
contents.
![螢幕擷取畫面 2025-02-18
145746](https://github.com/user-attachments/assets/aa74553b-7314-4d22-9108-241d27fb8998)
![螢幕擷取畫面 2025-02-18
145833](https://github.com/user-attachments/assets/a015ac8b-3817-46cd-82a6-4022326b3ecc)

## Integration Instructions

N/A

---------

Co-authored-by: kuqin12 <[email protected]>
  • Loading branch information
2 people authored and ProjectMuBot committed Feb 26, 2025
1 parent da8da86 commit 3505bce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
51 changes: 45 additions & 6 deletions AdvLoggerPkg/Application/DecodeUefiLog/DecodeUefiLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tempfile
import traceback
import copy
import os

from win32com.shell import shell
from edk2toollib.os.uefivariablesupport import UefiVariable
Expand Down Expand Up @@ -1036,6 +1037,8 @@ def main():
help="Path to binary Output LogFile")
parser.add_argument("-s", "--StartLine", dest="StartLine", default=0, type=int,
help="Print starting at StartLine")
parser.add_argument("-size", "--FileSize", dest="FileSize", default=0, type=int,
help="[-o option] Output Separate LogFile by KB Size")

options = parser.parse_args()

Expand All @@ -1053,11 +1056,44 @@ def main():
lines = advlog.ProcessMessages(InFile, options.StartLine)

if options.OutFilePath is not None:
OutFile = open(options.OutFilePath, "w", newline=None)
OutFile.writelines(lines)
OutFile.close()
CountOfLines = len(lines)
print(f"{CountOfLines} lines written to {options.OutFilePath}")
if options.FileSize == 0:
OutFile = open(options.OutFilePath, "w", newline=None)
OutFile.writelines(lines)
OutFile.close()
CountOfLines = len(lines)
print(f"{CountOfLines} lines written to {options.OutFilePath}")
else:
SeparatedFilePath:str = options.OutFilePath
FilePathPart = os.path.splitext(SeparatedFilePath)
MaxSize = options.FileSize * 1024

for LineIndex, LineStr in enumerate(lines):
if LineIndex == 0:
CurrentFileSize = 0
SeparateFileIndex = 1
CountOfLines = 0
SeparatedFilePath = FilePathPart[0] + '_' + str(SeparateFileIndex) + FilePathPart[1]
OutFile = open(SeparatedFilePath, "w", newline=None)

CurrentLineSize = len(LineStr.encode('utf-8')) + 1
if CurrentFileSize + CurrentLineSize > MaxSize:
OutFile.close()
print(f"{CountOfLines} lines written to {SeparatedFilePath}")
CountOfLines = 1
SeparateFileIndex += 1
SeparatedFilePath = FilePathPart[0] + '_' + str(SeparateFileIndex) + FilePathPart[1]
OutFile = open(SeparatedFilePath, "w", newline=None)
OutFile.writelines(LineStr)
CurrentFileSize = CurrentLineSize
else:
OutFile.writelines(LineStr)
CountOfLines += 1
CurrentFileSize += CurrentLineSize

OutFile.close()
print(f"{CountOfLines} lines written to {SeparatedFilePath}")
elif options.FileSize != 0:
print("Warning: No OutFilePath found. -size is OutFile option.")

except Exception:
print("Error processing log output.")
Expand All @@ -1077,7 +1113,10 @@ def main():

InFile.close()

print("Log complete")
if options.OutFilePath is None and options.RawFilePath is None:
print("No output FilePath found.")
else:
print("Log complete")


# --------------------------------------------------------------------------- #
Expand Down
6 changes: 6 additions & 0 deletions AdvLoggerPkg/Application/DecodeUefiLog/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ Decode a raw file into a text file:
DecodeUefiLog -l RawLog.bin -o NewLogFIle.txt
```

[-o Option] Decode lines and separate to multiple files by Kb size -size:

```.sh
DecodeUefiLog -size 30 -o NewLogFile.txt
```

---

## Copyright
Expand Down

0 comments on commit 3505bce

Please sign in to comment.