itools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/itools +20 -0
- data/bin/setup +8 -0
- data/itools.gemspec +40 -0
- data/lib/itools.rb +2 -0
- data/lib/itools/link_map.rb +253 -0
- data/lib/itools/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f078c88b1cad707558e31ce1e18919b7375ae486517a1428f35b9fe969d10951
|
|
4
|
+
data.tar.gz: b5733bf7a054146ace61c91c276ede3857b2288535903c5a86103c6a7ccf80cf
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b504c3211b25a0c418439d9415f7277fdc2a1a3169842257c31e9ef957815b54fec241ee0eb06492a17daef2887a0e047bc9ffe33ca95bc5b49e743aa82d65c4
|
|
7
|
+
data.tar.gz: fb3ce2ebdcc5f2d474b8afffc1ce974201723f825773f1aa2e631e393ebbcc3c1985f36bb563bb99875f7c33c0b49647d9a8c36422321cae416dc1dcdf506fa7
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at zhanggui@maoyan.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 张贵
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Itools
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/itools`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'itools'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install itools
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/itools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
+
|
|
41
|
+
## Code of Conduct
|
|
42
|
+
|
|
43
|
+
Everyone interacting in the Itools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/itools/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "itools"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/itools
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require ‘gli’
|
|
4
|
+
require 'itools'
|
|
5
|
+
|
|
6
|
+
include GLI::App
|
|
7
|
+
|
|
8
|
+
program_desc 'a collection of tools for ios developer'
|
|
9
|
+
|
|
10
|
+
version Itools::VERSION
|
|
11
|
+
|
|
12
|
+
desc "Analyze the memory footprint of each part or component in Xcode project"
|
|
13
|
+
arg 'xxx.txt linkmap'
|
|
14
|
+
command :parse do |c|
|
|
15
|
+
c.action do |global_options, options, args|
|
|
16
|
+
Itools::LinkMap.parser(args[0])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
exit run(ARGV)
|
|
20
|
+
|
data/bin/setup
ADDED
data/itools.gemspec
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "itools/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "itools"
|
|
8
|
+
spec.version = Itools::VERSION
|
|
9
|
+
spec.authors = ["zhanggui"]
|
|
10
|
+
spec.email = ["scottzg@126.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{iOS tools}
|
|
13
|
+
spec.description = %q{iOS dev tools }
|
|
14
|
+
spec.homepage = "https://github.com/ScottZg/itools"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if spec.respond_to?(:metadata)
|
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
20
|
+
|
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
22
|
+
spec.metadata["source_code_uri"] = "https://github.com/ScottZg/itools"
|
|
23
|
+
spec.metadata["changelog_uri"] = "https://github.com/ScottZg/itools/blob/master/README.md"
|
|
24
|
+
else
|
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
26
|
+
"public gem pushes."
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
33
|
+
end
|
|
34
|
+
spec.bindir = "exe"
|
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
36
|
+
spec.require_paths = ["lib"]
|
|
37
|
+
|
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
40
|
+
end
|
data/lib/itools.rb
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
$: << "."
|
|
4
|
+
|
|
5
|
+
module Itools
|
|
6
|
+
# ---------------------------------ObjectFile class---------------------------------
|
|
7
|
+
class ObjectFile
|
|
8
|
+
attr_accessor :serial_number, :file_path, :file_name
|
|
9
|
+
def initialize()
|
|
10
|
+
@serial_number = []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
# ---------------------------------Sections class---------------------------------
|
|
15
|
+
class Sections
|
|
16
|
+
attr_accessor :address, :size, :segment, :section
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
# ---------------------------------Symbols class---------------------------------
|
|
20
|
+
class Symbols
|
|
21
|
+
attr_accessor :s_address, :s_size, :s_file_serial_number, :s_name
|
|
22
|
+
def initialize
|
|
23
|
+
@s_file_serial_number = -1 #防止为0
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# ---------------------------------DSSymbols class---------------------------------
|
|
28
|
+
class DSSymbols
|
|
29
|
+
attr_accessor :size, :file, :name
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# ---------------------------------LinkMap class---------------------------------
|
|
33
|
+
class LinkMap
|
|
34
|
+
# 包含的属性
|
|
35
|
+
attr_accessor :l_name, :l_path, :l_arch, :l_obj_files, :l_sections, :l_symbols, :l_dead_stripped_symbols, :l_sym_map
|
|
36
|
+
# 初始化方法
|
|
37
|
+
def initialize(fName)
|
|
38
|
+
@l_name = fName
|
|
39
|
+
@l_obj_files = []
|
|
40
|
+
@l_symbols = []
|
|
41
|
+
@l_sections = []
|
|
42
|
+
@l_dead_stripped_symbols = []
|
|
43
|
+
end
|
|
44
|
+
# 得到path
|
|
45
|
+
def get_path(str)
|
|
46
|
+
splitparam = str.split(" ")
|
|
47
|
+
@l_path = splitparam.last
|
|
48
|
+
end
|
|
49
|
+
# 处理object文件
|
|
50
|
+
def handle_ojbect_files(str)
|
|
51
|
+
tempSplit = str.split("]")
|
|
52
|
+
if tempSplit.size > 1
|
|
53
|
+
obj_file = ObjectFile.new
|
|
54
|
+
obj_file.serial_number = tempSplit[0].delete("[").strip.to_i #设置serial_number
|
|
55
|
+
obj_file.file_path = tempSplit[1].strip
|
|
56
|
+
obj_file.file_name = tempSplit[1].split("/").last.chomp
|
|
57
|
+
l_obj_files << obj_file
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
# 处理sections
|
|
61
|
+
def handle_sections(str)
|
|
62
|
+
sectionSplit = str.split(" ")
|
|
63
|
+
if sectionSplit.size == 4
|
|
64
|
+
section = Sections.new
|
|
65
|
+
section.address = sectionSplit[0]
|
|
66
|
+
section.size = sectionSplit[1]
|
|
67
|
+
section.segment = sectionSplit[2]
|
|
68
|
+
section.section = sectionSplit[3]
|
|
69
|
+
l_sections << section
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
# get arch
|
|
73
|
+
def get_arch(str)
|
|
74
|
+
splitparam = str.split(" ")
|
|
75
|
+
@l_arch = splitparam.last
|
|
76
|
+
end
|
|
77
|
+
# 处理Symbols
|
|
78
|
+
def handle_symbols(str)
|
|
79
|
+
# 字符编码产生的异常处理
|
|
80
|
+
begin
|
|
81
|
+
symbolsSplit = str.split("\t")
|
|
82
|
+
rescue => exception
|
|
83
|
+
return
|
|
84
|
+
end
|
|
85
|
+
if symbolsSplit.size > 2
|
|
86
|
+
symbol = Symbols.new
|
|
87
|
+
symbol.s_address = symbolsSplit[0]
|
|
88
|
+
symbol.s_size = symbolsSplit[1]
|
|
89
|
+
# 获取编号和名字
|
|
90
|
+
serial_name_str = symbolsSplit[2]
|
|
91
|
+
file_and_name_split = serial_name_str.split("]")
|
|
92
|
+
if file_and_name_split.size > 1
|
|
93
|
+
symbol.s_file_serial_number = file_and_name_split[0].delete("[").strip.to_i #设置文件编号
|
|
94
|
+
symbol.s_name = file_and_name_split[1]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
l_symbols << symbol
|
|
98
|
+
else
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
# 处理symbols的数组,把symbols转换成hashmap
|
|
102
|
+
def handle_l_sym_map
|
|
103
|
+
@l_sym_map = @l_symbols.group_by(&:s_file_serial_number)
|
|
104
|
+
if @l_sym_map.include?(-1)
|
|
105
|
+
puts "移除无用元素"
|
|
106
|
+
@l_sym_map.delete(-1)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
# 处理link map file
|
|
110
|
+
def handle_map
|
|
111
|
+
handle_method_name = ""
|
|
112
|
+
File.read(@l_name).each_line do |line|
|
|
113
|
+
if line[0] == "#"
|
|
114
|
+
if line.include?("Path:")
|
|
115
|
+
handle_method_name = "get_path"
|
|
116
|
+
puts "处理path..."
|
|
117
|
+
elsif line.include?("Arch:")
|
|
118
|
+
handle_method_name = "get_arch"
|
|
119
|
+
puts "处理Arch..."
|
|
120
|
+
elsif line.include?("Object files")
|
|
121
|
+
handle_method_name = "handle_ojbect_files"
|
|
122
|
+
puts "处理Object files..."
|
|
123
|
+
elsif line.include?("Sections")
|
|
124
|
+
handle_method_name = "handle_sections"
|
|
125
|
+
puts "处理Sections..."
|
|
126
|
+
elsif line.include?("Symbols:") #symbols:和Dead Stripped Symbols处理一样
|
|
127
|
+
puts "处理#{line.delete('#').strip}..."
|
|
128
|
+
handle_method_name = "handle_symbols"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
self.send(handle_method_name, line)
|
|
132
|
+
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
def self.parser(path_para)
|
|
136
|
+
start_time = Time.now.to_i #程序开始执行时间(以毫秒为单位)
|
|
137
|
+
# 获取link map file's name
|
|
138
|
+
link_map_file_name = path_para
|
|
139
|
+
puts "获取的文件路径为:#{link_map_file_name}"
|
|
140
|
+
if link_map_file_name.nil?
|
|
141
|
+
puts "请按照如下命令执行该脚本:"
|
|
142
|
+
puts "\033[31mruby linkMapParse.rb **.txt \033[0m"
|
|
143
|
+
puts "**指代Link Map File的名字,例如LinkMapApp-LinkMap-normal-x86_64.txt"
|
|
144
|
+
exit
|
|
145
|
+
end
|
|
146
|
+
if File.exist?(link_map_file_name)
|
|
147
|
+
puts "\033[32m获取LinkMap文件: #{link_map_file_name}成功,开始分析数据...\033[0m"
|
|
148
|
+
else
|
|
149
|
+
puts "\033[31m#{link_map_file_name}文件不存在,请重新输入文件 \033[0m"
|
|
150
|
+
exit
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
link_map = LinkMap.new(link_map_file_name)
|
|
154
|
+
link_map.handle_map #处理文件为对象,然后继续后续操作
|
|
155
|
+
link_map.handle_l_sym_map #处理symbols为hashmap
|
|
156
|
+
sizeResultArr = []
|
|
157
|
+
|
|
158
|
+
link_map.l_obj_files.each do |obj|
|
|
159
|
+
temp_file_name = obj.file_name.split("(")[0]
|
|
160
|
+
|
|
161
|
+
last_file = sizeResultArr.last
|
|
162
|
+
|
|
163
|
+
if last_file && temp_file_name.eql?(last_file.file_name)
|
|
164
|
+
last_file.file_serial_numers << obj.serial_number
|
|
165
|
+
else
|
|
166
|
+
sz_obj = SizeResult.new
|
|
167
|
+
sz_obj.file_name = temp_file_name
|
|
168
|
+
sz_obj.file_serial_numers << obj.serial_number
|
|
169
|
+
sizeResultArr << sz_obj
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
data_analyze_time = Time.now.to_i
|
|
173
|
+
puts "\033[32m数据分析完成,耗时#{data_analyze_time - start_time}秒。开始计算结果\033[0m"
|
|
174
|
+
|
|
175
|
+
# 计算赋值size,此处耗时较长
|
|
176
|
+
total_size = 0
|
|
177
|
+
sizeResultArr.each do |obj|
|
|
178
|
+
# 处理方法2
|
|
179
|
+
obj.file_serial_numers.each do |s_number|
|
|
180
|
+
begin
|
|
181
|
+
link_map.l_sym_map[s_number].each do |symb|
|
|
182
|
+
obj.size = obj.size + symb.s_size.hex
|
|
183
|
+
total_size = total_size +symb.s_size.hex #统计总大小
|
|
184
|
+
end
|
|
185
|
+
rescue => exception
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
# 处理方法1 太过耗时
|
|
189
|
+
# link_map.l_symbols.each do |symb|
|
|
190
|
+
# if obj.file_serial_numers.include?(symb.s_file_serial_number)
|
|
191
|
+
# obj.size = obj.size + symb.s_size.hex
|
|
192
|
+
# end
|
|
193
|
+
# end
|
|
194
|
+
# puts "正在计算#{obj.file_name}的大小..."
|
|
195
|
+
end
|
|
196
|
+
data_handle_time = Time.now.to_i #处理数据时间
|
|
197
|
+
puts "\033[32m数据处理完成,耗时#{data_handle_time - data_analyze_time}秒。开始对结果进行大小排序(从大到小)...\033[0m"
|
|
198
|
+
# 按照从大到小排序
|
|
199
|
+
sizeResultArr.sort_by!{|obj|[-obj.size]}
|
|
200
|
+
sort_handle_time = Time.now.to_i #排序耗时
|
|
201
|
+
puts "\033[32m数据排序完成,耗时#{sort_handle_time - data_handle_time}秒。开始输出结果:\033[0m"
|
|
202
|
+
puts "\033[32m--------------------------------\033[0m"
|
|
203
|
+
|
|
204
|
+
# 判断文件是否存在
|
|
205
|
+
save_file_path = SizeResult.getSaveFileName
|
|
206
|
+
if File.exist?(save_file_path)
|
|
207
|
+
File.delete(save_file_path)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# 创建要保存数据的文件
|
|
211
|
+
save_file = File.new(save_file_path,"w+")
|
|
212
|
+
# 打印结果
|
|
213
|
+
sizeResultArr.each do |obj|
|
|
214
|
+
puts "#{obj.file_name} " + SizeResult.handleSize(obj.size)
|
|
215
|
+
save_file.puts("#{obj.file_name} #{SizeResult.handleSize(obj.size)}")
|
|
216
|
+
end
|
|
217
|
+
save_file.puts("总大小为:#{SizeResult.handleSize(total_size)}")
|
|
218
|
+
save_file.close
|
|
219
|
+
puts "总大小为(仅供参考):#{SizeResult.handleSize(total_size)}"
|
|
220
|
+
puts "\033[32m--------------------------------\033[0m"
|
|
221
|
+
end_time = Time.now.to_i #程序执行结束时间
|
|
222
|
+
puts "分析结果已经保存为文件,位置为:\n\033[32m#{save_file_path}\033[0m"
|
|
223
|
+
puts " "
|
|
224
|
+
puts "\033[32m整个程序执行时间为:#{end_time - start_time}秒\033[0m"
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
end
|
|
228
|
+
# --------------------------------- Size utils class ---------------------------------
|
|
229
|
+
class SizeResult
|
|
230
|
+
attr_accessor :file_name, :file_serial_numers, :size
|
|
231
|
+
def initialize
|
|
232
|
+
@file_serial_numers = []
|
|
233
|
+
@size = 0
|
|
234
|
+
end
|
|
235
|
+
# size字符化
|
|
236
|
+
def self.handleSize(size)
|
|
237
|
+
if size > 1024 * 1024
|
|
238
|
+
return format("%.2f",(size.to_f/(1024*1024))) + "MB"
|
|
239
|
+
elsif size > 1024
|
|
240
|
+
return format("%.2f",(size.to_f/1024)) + "KB"
|
|
241
|
+
else
|
|
242
|
+
return size.to_s + "B"
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
# 获取结果文件保存到目录
|
|
246
|
+
def self.getSaveFileName(path_para)
|
|
247
|
+
path = Pathname.new(path_para)
|
|
248
|
+
# 要保存的地址
|
|
249
|
+
save_file_path = path.dirname.to_s + "/" + "parse_" + path.basename.to_s + "_result.txt"
|
|
250
|
+
return save_file_path
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: itools
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- zhanggui
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-11-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.17'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.17'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: 'iOS dev tools '
|
|
42
|
+
email:
|
|
43
|
+
- scottzg@126.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- CODE_OF_CONDUCT.md
|
|
50
|
+
- Gemfile
|
|
51
|
+
- Gemfile.lock
|
|
52
|
+
- LICENSE.txt
|
|
53
|
+
- README.md
|
|
54
|
+
- Rakefile
|
|
55
|
+
- bin/console
|
|
56
|
+
- bin/itools
|
|
57
|
+
- bin/setup
|
|
58
|
+
- itools.gemspec
|
|
59
|
+
- lib/itools.rb
|
|
60
|
+
- lib/itools/link_map.rb
|
|
61
|
+
- lib/itools/version.rb
|
|
62
|
+
homepage: https://github.com/ScottZg/itools
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
65
|
+
metadata:
|
|
66
|
+
allowed_push_host: https://rubygems.org
|
|
67
|
+
homepage_uri: https://github.com/ScottZg/itools
|
|
68
|
+
source_code_uri: https://github.com/ScottZg/itools
|
|
69
|
+
changelog_uri: https://github.com/ScottZg/itools/blob/master/README.md
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubyforge_project:
|
|
86
|
+
rubygems_version: 2.7.6
|
|
87
|
+
signing_key:
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: iOS tools
|
|
90
|
+
test_files: []
|