-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/devicemetrics enhancedproxy (#197)
This PR adds a few missing classes to unarchiver and initial support for LZ4 decompression. With this change, dproxy is now able to fully dump instruments metrics sessions. Paves the way for adding the feature to go-ios finally.
- Loading branch information
1 parent
fa24aca
commit 173b973
Showing
15 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dtx | ||
|
||
import ( | ||
"encoding/binary" | ||
"github.com/pierrec/lz4" | ||
) | ||
|
||
const bv41 = 0x62763431 | ||
|
||
//https://discuss.appium.io/t/how-to-parse-trace-file-to-get-cpu-performance-usage-data-for-ios-apps/35334/2 | ||
func Decompress(data []byte) ([]byte, error) { | ||
//no idea what the first four bytes mean | ||
totalUncompressedSize := binary.LittleEndian.Uint32(data) | ||
data = data[4:] | ||
|
||
var magic uint32 | ||
magic = binary.BigEndian.Uint32(data) | ||
compressedAgg := make([]byte, 0) | ||
for magic == bv41 { | ||
//uncompressedSize := binary.LittleEndian.Uint32(data[4:]) | ||
compressedSize := binary.LittleEndian.Uint32(data[8:]) | ||
chunk := data[12 : 12+compressedSize] | ||
//log.Infof("chunk: %x", chunk) | ||
data = data[12+compressedSize:] | ||
|
||
compressedAgg = append(compressedAgg, chunk...) | ||
magic = binary.BigEndian.Uint32(data) | ||
} | ||
uncompressedData := make([]byte, totalUncompressedSize+100) | ||
n, err := lz4.UncompressBlock(compressedAgg, uncompressedData) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
//log.Infof("uncompressed lz4 data of %d bytes", len(uncompressedData[:n])) | ||
return uncompressedData[:n], nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package instruments | ||
|
||
import ( | ||
"github.com/danielpaulus/go-ios/ios" | ||
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type metricsDispatcher struct { | ||
messageChannel chan dtx.Message | ||
closeChannel chan struct{} | ||
} | ||
|
||
func (dispatcher metricsDispatcher) Dispatch(msg dtx.Message) { | ||
log.Infof("%+v", msg) | ||
} | ||
|
||
func GetMetrics(device ios.DeviceEntry) (func() (map[string]interface{}, error), func() error, error) { | ||
conn, err := connectInstruments(device) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
dispatcher := metricsDispatcher{messageChannel: make(chan dtx.Message), closeChannel: make(chan struct{})} | ||
conn.AddDefaultChannelReceiver(dispatcher) | ||
channel := conn.RequestChannelIdentifier(mobileNotificationsChannel, channelDispatcher{}) | ||
resp, err := channel.MethodCall("setApplicationStateNotificationsEnabled:", true) | ||
if err != nil { | ||
log.Errorf("resp:%+v, %+v", resp, resp.Payload[0]) | ||
return nil, nil, err | ||
} | ||
log.Debugf("appstatenotifications enabled successfully: %+v", resp) | ||
resp, err = channel.MethodCall("setMemoryNotificationsEnabled:", true) | ||
if err != nil { | ||
log.Errorf("resp:%+v, %+v", resp, resp.Payload[0]) | ||
return nil, nil, err | ||
} | ||
log.Debugf("memory notifications enabled: %+v", resp) | ||
|
||
return nil, nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters