Skip to content

Commit

Permalink
Add generate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphofmann committed Oct 7, 2021
1 parent 48728b0 commit ecf222a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions develop-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This page contains internal documentation for development.

![Auto UI Performance Class Overview](./auto-ui-performance-tracking.svg)

## Generating classes

You can use the `generate-classes.sh` to generate ViewControllers and other classes to emulate a large project. This is useful, for example, to test the performance of swizzling in a large project without having to check in thousands of lines of code.

## Generating Diagrams

The diagrams are created with [PlantUml](http://plantuml.com). The advantage of PlantUml
Expand Down
84 changes: 84 additions & 0 deletions scripts/generate-classes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
set -euo pipefail

# Generates classes useful for testing of the performance of swizzling ViewControllers
# with plenty of code and view controllers.
# You can move the generated classes to a sample project and use the profiler to analyze
# how long the swizzling takes.

viewControllers="ViewControllers.swift"
dsnStorage="DSNStorage.swift"

if [ -f "$viewControllers" ] ; then
rm "$viewControllers"
fi

if [ -f "$dsnStorage" ] ; then
rm "$dsnStorage"
fi

for i in {1..1000}
do
echo "class ViewController$i: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
func$i() -> Bool {
return true
}
}" >> $viewControllers
done

for i in {1..2000}
do
echo "class DSNStorage$i {
static let shared = DSNStorage$i()
private let dsnFile: URL
private init() {
// swiftlint:disable force_unwrapping
let cachesDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
// swiftlint:enable force_unwrapping
dsnFile = cachesDirectory.appendingPathComponent(\"dsn\")
}
func saveDSN$i(dsn: String) {
do {
deleteDSN$i()
try dsn.write(to: dsnFile, atomically: true, encoding: .utf8)
} catch {
SentrySDK.capture(error: error)
}
}
func getDSN$i() -> String? {
let fileManager = FileManager.default
do {
if fileManager.fileExists(atPath: dsnFile.path) {
return try String(contentsOfFile: dsnFile.path)
}
} catch {
SentrySDK.capture(error: error)
}
return nil
}
func deleteDSN$i() {
let fileManager = FileManager.default
do {
if fileManager.fileExists(atPath: dsnFile.path) {
try fileManager.removeItem(at: dsnFile)
}
} catch {
SentrySDK.capture(error: error)
}
}
}" >> $dsnStorage
done


0 comments on commit ecf222a

Please sign in to comment.