Skip to content

Instantly share code, notes, and snippets.

@kanru
Created April 13, 2017 15:04
Show Gist options
  • Save kanru/edeb6cde3cf607139bd9e126ebe2207d to your computer and use it in GitHub Desktop.
Save kanru/edeb6cde3cf607139bd9e126ebe2207d to your computer and use it in GitHub Desktop.
#!/bin/env python
import json
import sys
skipList = [
"BaseThreadInitThunk",
"CharPrevA",
"CsrAllocateMessagePointer",
"DispatchMessageW",
"DispatchMessageWorker",
"EtwEventEnabled",
"GetCurrentThread",
"GetTickCount",
"KiFastSystemCallRet",
"MessageLoop::Run",
"MessageLoop::RunHandler",
"MsgWaitForMultipleObjects",
"MsgWaitForMultipleObjectsEx",
"NS_ProcessNextEvent",
"NS_internal_main",
"NtUserValidateHandleSecure",
"NtWaitForAlertByThreadId",
"NtWaitForMultipleObjects",
"NtWaitForSingleObject",
"PR_Lock",
"PeekMessageW",
"RealMsgWaitForMultipleObjectsEx",
"RtlAnsiStringToUnicodeString",
"RtlDeNormalizeProcessParams",
"RtlEnterCriticalSection",
"RtlLeaveCriticalSection",
"RtlUserThreadStart",
"RtlpAllocateListLookup",
"RtlpDeCommitFreeBlock",
"RtlpEnterCriticalSectionContended",
"RtlpUnWaitCriticalSection",
"RtlpWaitOnAddress",
"RtlpWaitOnAddressWithTimeout",
"RtlpWaitOnCriticalSection",
"RtlpWakeByAddress",
"UserCallWinProcCheckWow"
"ValidateHwnd",
"WaitForMultipleObjectsEx",
"WaitForMultipleObjectsExImplementation",
"WaitForSingleObjectEx",
"XRE_InitChildProcess",
"XRE_RunAppShell",
"ZwWaitForMultipleObjects",
"ZwWaitForSingleObject",
"_RtlUserThreadStart",
"__RtlUserThreadStart",
"__scrt_common_main_seh",
"content_process_main",
"mozilla::BackgroundHangMonitor::NotifyActivity",
"mozilla::BackgroundHangThread::NotifyActivity",
"mozilla::BackgroundHangThread::NotifyWait",
"mozilla::BootstrapImpl::XRE_InitChildProcess",
"mozilla::HangMonitor::NotifyActivity",
"mozilla::HangMonitor::Suspend",
"mozilla::ValidatingDispatcher::Runnable::Run",
"mozilla::detail::MutexImpl::lock",
"mozilla::ipc::MessageChannel::MessageTask::Run",
"mozilla::ipc::MessagePump::Run",
"mozilla::ipc::MessagePumpForChildProcess::Run",
"mozilla::widget::WinUtils::PeekMessageW",
"mozilla::widget::WinUtils::WaitForMessage",
"nsAppShell::ProcessNextNativeEvent",
"nsAppShell::Run",
"nsBaseAppShell::DoProcessNextNativeEvent",
"nsBaseAppShell::OnProcessNextEvent",
"nsBaseAppShell::Run",
"nsThread::DoMainThreadSpecificProcessing",
"nsThread::ProcessNextEvent",
"wmain",
"UserCallWinProcCheckWow",
"ValidateHwnd",
"0x1bc3d",
"0x1905a",
"RtlSleepConditionVariableCS",
"SleepConditionVariableCS",
"NDXGI::CDevice::GetKernelDeviceExecutionState",
"NtGdiDdDDIGetDeviceState",
]
def shouldSkip(frame):
for item in skipList:
if frame.startswith(item):
return True
return False
def filterStacks(stacks):
newstacks = []
for frame in stacks:
if shouldSkip(frame):
continue
newstacks.append(frame)
return newstacks
if __name__ == "__main__":
input = sys.argv[1]
data = json.load(open(input))
ranks = {}
for record in data:
stacks = filterStacks(record['nativeStack']['symbolicatedStacks'][0])
key = ''.join(stacks)
if stacks:
if not ranks.has_key(key):
ranks[key] = []
ranks[key].append(stacks)
for r in sorted(ranks.itervalues(), key=lambda r: len(r), reverse=True):
print("{}".format(len(r)))
for frame in r[0]:
print(" {}".format(frame))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment