Skip to content

Commit

Permalink
Dumping of invocation stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnno1962 committed Oct 14, 2020
1 parent e27960d commit 4bd64cf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions InjectionBundle/InjectionClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef NS_ENUM(int, InjectionCommand) {
InjectionTraceFramework,
InjectionInclude,
InjectionExclude,
InjectionStats,

InjectionInvalid = 1000,

Expand Down
8 changes: 7 additions & 1 deletion InjectionBundle/InjectionClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 06/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/ResidentEval/InjectionBundle/InjectionClient.mm#113 $
// $Id: //depot/ResidentEval/InjectionBundle/InjectionClient.mm#115 $
//

#import "InjectionClient.h"
Expand Down Expand Up @@ -283,6 +283,12 @@ - (void)runInBackground {
[SwiftTrace setSwiftTraceFilterExclude:[self readString]];
[self filteringChanged];
break;
case InjectionStats:
if (!tracing)
printf("💉 ⚠️ You need to have traced something to gather stats.\n");
else
[SwiftInjection dumpStats];
break;
case InjectionInvalid:
printf("💉 ⚠️ Connection rejected. Are you running the correct version of InjectionIII.app from /Applications? ⚠️\n");
break;
Expand Down
14 changes: 13 additions & 1 deletion InjectionBundle/SwiftInjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 05/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/ResidentEval/InjectionBundle/SwiftInjection.swift#78 $
// $Id: //depot/ResidentEval/InjectionBundle/SwiftInjection.swift#84 $
//
// Cut-down version of code injection in Swift. Uses code
// from SwiftEval.swift to recompile and reload class.
Expand Down Expand Up @@ -339,6 +339,18 @@ public class SwiftInjection: NSObject {
free(methods)
}
}

@objc class func dumpStats() {
print("""
Sorted elapsed time/invocations by method
=========================================
""")
let invocationCounts = SwiftTrace.invocationCounts()
for (method, elapsed) in SwiftTrace.sortedElapsedTimes(onlyFirst: 1000) {
print("\(String(format: "%.1f", elapsed*1000.0))ms/\(invocationCounts[method] ?? -1)\t\(method)")
}
}
}

class SwiftSweeper {
Expand Down
7 changes: 6 additions & 1 deletion InjectionIII/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by John Holdsworth on 06/11/2017.
// Copyright © 2017 John Holdsworth. All rights reserved.
//
// $Id: //depot/ResidentEval/InjectionIII/AppDelegate.swift#70 $
// $Id: //depot/ResidentEval/InjectionIII/AppDelegate.swift#71 $
//

import Cocoa
Expand Down Expand Up @@ -300,6 +300,11 @@ class AppDelegate : NSObject, NSApplicationDelegate {
lastConnection?.sendCommand(.traceSwiftUI, with: nil)
}

@IBAction func traceStats(_ sender: NSMenuItem) {
toggleState(sender)
lastConnection?.sendCommand(.stats, with: nil)
}

@IBAction func showTraceFilters(_ sender: NSMenuItem?) {
NSApplication.shared.activate(ignoringOtherApps: true)
traceFilters.makeKeyAndOrderFront(sender)
Expand Down
8 changes: 8 additions & 0 deletions InjectionIII/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@
<action selector="traceSwiftUI:" target="Voe-Tx-rLC" id="0xk-LY-4Pv"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="1Zk-TV-Nfy"/>
<menuItem title="Dump Stats" toolTip="Dump elpased time stats per method." id="wMb-mC-poo">
<modifierMask key="keyEquivalentModifierMask"/>
<accessibility description="Trace App"/>
<connections>
<action selector="traceStats:" target="Voe-Tx-rLC" id="2DR-dQ-dhn"/>
</connections>
</menuItem>
<menuItem title="Set Filters" toolTip="Set filters to manage trace output." id="Y20-on-vxe">
<modifierMask key="keyEquivalentModifierMask"/>
<accessibility description="Trace App"/>
Expand Down
2 changes: 1 addition & 1 deletion InjectionIII/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>4391</string>
<string>4401</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 4bd64cf

Please sign in to comment.