Skip to content

Commit 2748eee

Browse files
Hongyan JiangGitHub Enterprise
authored andcommitted
Low Memory beacon does not include used memory
1 parent b6d392f commit 2748eee

6 files changed

Lines changed: 13 additions & 44 deletions

File tree

Changelog.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Changelog
22

3-
## 1.9.0
4-
- add option to configure rate limit
3+
## 1.8.8
4+
- add option to configure rate limit, drop beacons and performance beacons
55
- send drop beacons and performance beacons (app launch time, low memory warning, application not responding)to Instana backend
6-
- allow caller enable/disable the new features through configuration
76

87
## 1.8.7
98
- queryTrackedDomainList configuration to capture http query parameters if url is in the white listed RegExp array

InstanaAgent.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "InstanaAgent"
19-
s.version = "1.9.0"
19+
s.version = "1.8.8"
2020
s.summary = "Instana iOS agent."
2121

2222
# This description is used to generate tags and improve search results.

Sources/InstanaAgent/Beacons/Beacons Types/PerformanceBeacons/PerfLowMemoryBeacon.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PerfLowMemoryBeacon: PerformanceBeacon {
99
let availableMemory: UInt64?
1010
let maximumMemory: UInt64?
1111

12-
init(usedMemory: UInt64?, availableMemory: UInt64?, maximumMemory: UInt64?) {
12+
init(usedMemory: UInt64? = nil, availableMemory: UInt64?, maximumMemory: UInt64?) {
1313
self.usedMemory = usedMemory
1414
self.availableMemory = availableMemory
1515
self.maximumMemory = maximumMemory
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
struct VersionConfig {
2-
static let agentVersion = "1.9.0"
2+
static let agentVersion = "1.8.8"
33
}

Sources/InstanaAgent/Monitors/Performance/LowMemoryMonitor.swift

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Foundation
66
#if os(tvOS) || os(watchOS) || os(iOS)
77
import UIKit
88
#endif
9-
import MachO
9+
import os
1010

1111
class LowMemoryMonitor {
1212
let reporter: Reporter
@@ -22,43 +22,13 @@ class LowMemoryMonitor {
2222

2323
@objc func onLowMemoryWarning(notification: Notification) {
2424
let unit = UInt64(1024 * 1024)
25-
let usedMemory = getUsedMemory()
26-
let freeMemory = getFreeMemory()
27-
let maxMemory: UInt64 = ProcessInfo.processInfo.physicalMemory
28-
// in mega bytes
29-
reporter.submit(PerfLowMemoryBeacon(usedMemory: usedMemory != nil ? usedMemory! / unit : nil,
30-
availableMemory: freeMemory != nil ? freeMemory! / unit : nil,
31-
maximumMemory: maxMemory / unit))
32-
}
33-
34-
func getUsedMemory() -> UInt64? {
35-
var taskVMInfo = task_vm_info_data_t()
36-
var vmSize = mach_msg_type_number_t(MemoryLayout<task_vm_info>.size) / 4
37-
let kernResult: kern_return_t = withUnsafeMutablePointer(to: &taskVMInfo) {
38-
$0.withMemoryRebound(to: integer_t.self, capacity: 1) {
39-
task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), $0, &vmSize)
40-
}
41-
}
42-
if kernResult == KERN_SUCCESS {
43-
return UInt64(taskVMInfo.phys_footprint)
44-
}
45-
return nil
46-
}
47-
48-
func getFreeMemory() -> UInt64? {
49-
var vmStats = vm_statistics64()
50-
var vmSize = mach_msg_type_number_t(MemoryLayout<vm_statistics64>.size) / 4
51-
52-
let machHost = mach_host_self()
53-
let ret = withUnsafeMutablePointer(to: &vmStats) {
54-
$0.withMemoryRebound(to: integer_t.self, capacity: Int(vmSize)) {
55-
host_statistics64(machHost, HOST_VM_INFO64, $0, &vmSize)
56-
}
25+
var freeMemory: UInt64?
26+
if #available(iOS 13.0, *) {
27+
freeMemory = UInt64(os_proc_available_memory()) / unit
5728
}
29+
let maxMemory: UInt64 = ProcessInfo.processInfo.physicalMemory / unit
5830

59-
if ret == KERN_SUCCESS {
60-
return UInt64(vmStats.free_count) * UInt64(vm_kernel_page_size)
61-
}
62-
return nil
31+
// in mega bytes
32+
reporter.submit(PerfLowMemoryBeacon(availableMemory: freeMemory, maximumMemory: maxMemory))
6333
}
6434
}

Tests/InstanaAgentTests/Configuration/InstanaSystemUtilsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class InstanaSystemUtilsTests: InstanaTestCase {
55

66
func test_AgentVersion() {
77
// Then
8-
AssertTrue(InstanaSystemUtils.agentVersion == "1.9.0")
8+
AssertTrue(InstanaSystemUtils.agentVersion == "1.8.8")
99
}
1010

1111
func test_systemVersion() {

0 commit comments

Comments
 (0)