Skip to content

Commit

Permalink
Add memory usage to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kaishin committed Jan 2, 2024
1 parent e051504 commit f86fcd6
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 24 deletions.
45 changes: 29 additions & 16 deletions Demo/Demo-iOS/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22504"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Gifu-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController title="Gifu" id="vXZ-lx-hvc" customClass="ViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
<viewController title="Gifu" id="vXZ-lx-hvc" customClass="ViewController" customModule="Gifu_iOSDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
Expand All @@ -22,7 +20,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Tap the image to pause/resume. Swipe to change GIF." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wsv-cU-WO5">
<rect key="frame" x="95" y="125" width="185" height="29"/>
<rect key="frame" x="95.5" y="125" width="184.5" height="29"/>
<constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="200" id="73c-sg-Egr"/>
</constraints>
Expand All @@ -44,21 +42,28 @@
</connections>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" text="Gifu" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c8Y-41-BaC">
<rect key="frame" x="171" y="100" width="34" height="21"/>
<rect key="frame" x="170.5" y="100" width="34" height="21"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
<color key="textColor" red="0.99144423007965088" green="0.56549066305160522" blue="0.033751130104064941" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XcY-7q-76n">
<rect key="frame" x="0.5" y="514" width="375" height="18"/>
<rect key="frame" x="0.0" y="514" width="375" height="18"/>
<fontDescription key="fontDescription" type="italicSystem" pointSize="15"/>
<color key="textColor" white="0.66666666669999997" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="65H-lb-eYT">
<rect key="frame" x="0.0" y="540" width="375" height="18"/>
<fontDescription key="fontDescription" type="italicSystem" pointSize="15"/>
<color key="textColor" white="0.66666666669999997" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="backgroundColor" systemColor="darkTextColor"/>
<color key="tintColor" red="0.99144423007965088" green="0.56549066305160522" blue="0.033751130104064941" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="65H-lb-eYT" firstAttribute="trailing" secondItem="XcY-7q-76n" secondAttribute="trailing" id="2eI-IQ-TOA"/>
<constraint firstItem="XcY-7q-76n" firstAttribute="width" secondItem="FSz-xF-Xds" secondAttribute="width" id="306-mf-Sm0"/>
<constraint firstAttribute="trailing" secondItem="FSz-xF-Xds" secondAttribute="trailing" id="8kQ-x1-WJl"/>
<constraint firstItem="XcY-7q-76n" firstAttribute="top" secondItem="FSz-xF-Xds" secondAttribute="bottom" constant="10" id="BH2-vh-hUc"/>
Expand All @@ -67,7 +72,9 @@
<constraint firstAttribute="centerX" secondItem="c8Y-41-BaC" secondAttribute="centerX" id="Kc0-P5-KMZ"/>
<constraint firstItem="FSz-xF-Xds" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="O4L-QH-SvV"/>
<constraint firstItem="FSz-xF-Xds" firstAttribute="top" secondItem="wsv-cU-WO5" secondAttribute="bottom" constant="50" id="ODd-UW-Pca"/>
<constraint firstItem="65H-lb-eYT" firstAttribute="top" secondItem="XcY-7q-76n" secondAttribute="bottom" constant="8" symbolic="YES" id="Pcw-nx-sBs"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" relation="greaterThanOrEqual" secondItem="XcY-7q-76n" secondAttribute="bottom" constant="12" id="VEE-1g-0W4"/>
<constraint firstItem="65H-lb-eYT" firstAttribute="leading" secondItem="XcY-7q-76n" secondAttribute="leading" id="Vgl-ue-sFb"/>
<constraint firstItem="wsv-cU-WO5" firstAttribute="top" secondItem="c8Y-41-BaC" secondAttribute="bottom" constant="4" id="ZG4-fK-WvN"/>
<constraint firstAttribute="centerX" secondItem="FSz-xF-Xds" secondAttribute="centerX" id="oih-yH-vRh"/>
<constraint firstAttribute="centerX" secondItem="wsv-cU-WO5" secondAttribute="centerX" id="yLb-zR-gfU"/>
Expand All @@ -79,6 +86,7 @@
<connections>
<outlet property="imageDataLabel" destination="XcY-7q-76n" id="8b5-Hu-aDc"/>
<outlet property="imageView" destination="FSz-xF-Xds" id="gtV-MK-Fwd"/>
<outlet property="memoryUsageLabel" destination="65H-lb-eYT" id="MgE-W8-BQH"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -108,7 +116,7 @@
<!--Empty View Controller-->
<scene sceneID="mnS-cg-VMi">
<objects>
<viewController storyboardIdentifier="EmptyViewController" id="E4d-Zb-hdl" customClass="EmptyViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="EmptyViewController" id="E4d-Zb-hdl" customClass="EmptyViewController" customModule="Gifu_iOSDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="oOj-g1-HPj"/>
<viewControllerLayoutGuide type="bottom" id="dND-Gc-LIW"/>
Expand All @@ -126,17 +134,17 @@
<!--Gifu-->
<scene sceneID="nSL-py-yiM">
<objects>
<viewController title="Gifu" id="OGk-7x-6ul" customClass="ViewController" customModule="Demo" customModuleProvider="target" sceneMemberID="viewController">
<viewController title="Gifu" id="OGk-7x-6ul" customClass="ViewController" customModule="Gifu_iOSDemo" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="83f-xL-xEu"/>
<viewControllerLayoutGuide type="bottom" id="wIQ-rE-qNC"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="1bA-xd-73D">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="647"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView clipsSubviews="YES" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" placeholderIntrinsicWidth="600" placeholderIntrinsicHeight="300" translatesAutoresizingMaskIntoConstraints="NO" id="Us4-12-3Mt" customClass="GIFImageView" customModule="Gifu">
<rect key="frame" x="0.0" y="166" width="375" height="300"/>
<rect key="frame" x="0.0" y="146" width="375" height="300"/>
<gestureRecognizers/>
<constraints>
<constraint firstAttribute="width" secondItem="Us4-12-3Mt" secondAttribute="height" multiplier="5:4" id="VBo-I2-vrW"/>
Expand All @@ -149,7 +157,7 @@
</connections>
</imageView>
</subviews>
<color key="backgroundColor" cocoaTouchSystemColor="darkTextColor"/>
<color key="backgroundColor" systemColor="darkTextColor"/>
<color key="tintColor" red="0.99144423010000005" green="0.56549066309999996" blue="0.033751130099999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Us4-12-3Mt" firstAttribute="leading" secondItem="1bA-xd-73D" secondAttribute="leading" id="3P4-3G-m6R"/>
Expand Down Expand Up @@ -191,4 +199,9 @@
<point key="canvasLocation" x="1626" y="368"/>
</scene>
</scenes>
<resources>
<systemColor name="darkTextColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
37 changes: 36 additions & 1 deletion Demo/Demo-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import Gifu
class ViewController: UIViewController {
@IBOutlet weak var imageView: GIFImageView!
@IBOutlet weak var imageDataLabel: UILabel!
@IBOutlet weak var memoryUsageLabel: UILabel!
@IBAction func unwindToRootViewController(segue: UIStoryboardSegue) { }

var currentGIFName: String = "mugen" {
var currentGIFName: String = "earth" {
didSet {
self.animate()
}
Expand Down Expand Up @@ -36,6 +37,7 @@ class ViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {
self.animate()
self.memoryUsageLabel.text = "Loading..."
}

func animate() {
Expand All @@ -46,5 +48,38 @@ class ViewController: UIViewController {
}, loopBlock: {
print("Loop finished")
})

if #available(iOS 15.0, *) {
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
DispatchQueue.main.async {
self.memoryUsageLabel.text = "Memory usage: \(Memory.memoryFootprint()!.formatted(.byteCount(style: .memory)))"
}
}
}
}
}

class Memory: NSObject {
// https://forums.developer.apple.com/thread/105088#357415
class func memoryFootprint() -> Int? {
let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)
let TASK_VM_INFO_REV1_COUNT = mach_msg_type_number_t(MemoryLayout.offset(of: \task_vm_info_data_t.min_address)! / MemoryLayout<integer_t>.size)

var info = task_vm_info_data_t()
var count = TASK_VM_INFO_COUNT

let kr = withUnsafeMutablePointer(to: &info) { infoPtr in
infoPtr.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { intPtr in
task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), intPtr, &count)
}
}

guard
kr == KERN_SUCCESS,
count >= TASK_VM_INFO_REV1_COUNT
else { return nil }

let usedBytes = Float(info.phys_footprint)
return Int(usedBytes)
}
}
29 changes: 22 additions & 7 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
0007E16E23809E9C000FED9F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0007E16C23809E9C000FED9F /* Main.storyboard */; };
0007E17023809E9D000FED9F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0007E16F23809E9D000FED9F /* Assets.xcassets */; };
0007E17323809E9D000FED9F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0007E17123809E9D000FED9F /* LaunchScreen.storyboard */; };
0007E18F2380A6DE000FED9F /* Gifu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0007E18E2380A6DE000FED9F /* Gifu.framework */; };
0007E193238193E1000FED9F /* Gifu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0007E192238193E1000FED9F /* Gifu.framework */; };
0007E194238193E1000FED9F /* Gifu.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 0007E192238193E1000FED9F /* Gifu.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0007E1962381978A000FED9F /* mugen.gif in Resources */ = {isa = PBXBuildFile; fileRef = 0007E1952381978A000FED9F /* mugen.gif */; };
002A1BFC1D1624D0005ABBD0 /* mugen.gif in Resources */ = {isa = PBXBuildFile; fileRef = 002A1BFB1D1624D0005ABBD0 /* mugen.gif */; };
0032FE841FFA693500444203 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0032FE831FFA693500444203 /* LaunchScreen.storyboard */; };
006795B42B43B49400D8C798 /* Gifu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0007E18E2380A6DE000FED9F /* Gifu.framework */; };
006795B52B43B49400D8C798 /* Gifu.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 0007E18E2380A6DE000FED9F /* Gifu.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
00DD26EB1DA5968500A0F683 /* EmptyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00DD26EA1DA5968500A0F683 /* EmptyViewController.swift */; };
9D98823D19BC69CA00B790C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D98823C19BC69CA00B790C6 /* AppDelegate.swift */; };
9D98823F19BC69CA00B790C6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D98823E19BC69CA00B790C6 /* ViewController.swift */; };
Expand All @@ -39,6 +40,17 @@
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
006795B62B43B49400D8C798 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
006795B52B43B49400D8C798 /* Gifu.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -78,7 +90,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0007E18F2380A6DE000FED9F /* Gifu.framework in Frameworks */,
006795B42B43B49400D8C798 /* Gifu.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -188,6 +200,7 @@
9D98823319BC69CA00B790C6 /* Sources */,
9D98823419BC69CA00B790C6 /* Frameworks */,
9D98823519BC69CA00B790C6 /* Resources */,
006795B62B43B49400D8C798 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -215,7 +228,7 @@
};
9D98823619BC69CA00B790C6 = {
CreatedOnToolsVersion = 6.0;
DevelopmentTeam = 5G38N4D8G2;
DevelopmentTeam = HCTW65QDC4;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -474,12 +487,13 @@
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 5G38N4D8G2;
DEVELOPMENT_TEAM = HCTW65QDC4;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/Demo-iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.redalemeden.Gifu-iOSDemo";
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = net.4rays.Gifu.Demo;
PRODUCT_NAME = "Gifu-iOSDemo";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
Expand All @@ -492,12 +506,13 @@
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 5G38N4D8G2;
DEVELOPMENT_TEAM = HCTW65QDC4;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = "$(SRCROOT)/Demo-iOS/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.redalemeden.Gifu-iOSDemo";
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = net.4rays.Gifu.Demo;
PRODUCT_NAME = "Gifu-iOSDemo";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
Loading

0 comments on commit f86fcd6

Please sign in to comment.