itools 0.4.8 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc0a82baa018d343c2c905770612c5b27f33f720cbfb4cab71722556de54ad46
4
- data.tar.gz: 7f285a0f2b6c35101f169ec3e2298fad1520b9a183fee9de92156ef87115dd6e
3
+ metadata.gz: bf38167231314d38da1f2027c16c24df9cd7419205c154e6bf8591fe89d58133
4
+ data.tar.gz: ecbcb2405ee49c04d97de632f10d56ff4f2a17f26679fb7d0ed72bca3e0278c9
5
5
  SHA512:
6
- metadata.gz: 805fff92aa67254b0b157d566716145db209146b358151566a895ec8b03b3cd4a4433c5f999b6a838c036dcd7efe4fe31971b03876c648c6d9804329517915c1
7
- data.tar.gz: 6fa62c464796f2a82bf2af5b521244736779ccaa8326a71c79d1117a10461769a93ecb90e8aa8106ca5f8b1f920bd637bf9d7eb4f93ee1ec498367a65b18a89d
6
+ metadata.gz: 9d233beb82f1909ef00e6791789caae405cd852763fa2d5590cbe469a81f710b0e1358812da22b452359dd55f21f85ba8ee5b1290ecdecdbdd05ec15be7a9f25
7
+ data.tar.gz: 7684e2bafc4abc09757f3dbf96f316f44b6172b68cc532b5edb25a579db57ea3103d04ffd3b774dbbc822984e1cddd72304dde7e149c560f7874670803583061
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- itools (0.4.8)
4
+ itools (0.5.0)
5
5
  bundler (~> 1.17)
6
6
  git (~> 1.5)
7
7
  gli (~> 2.17)
data/README.md CHANGED
@@ -19,21 +19,22 @@ SYNOPSIS
19
19
  itools [global options] command [command options] [arguments...]
20
20
 
21
21
  VERSION
22
- 0.4.2
22
+ 0.4.9
23
23
 
24
24
  GLOBAL OPTIONS
25
25
  --help - Show this message
26
26
  --version - Display the program version
27
27
 
28
28
  COMMANDS
29
- count_code_line - count lines of code
30
- find - search unuse image
29
+ count_code_line - 统计代码行数
30
+ find - 查找无用图片
31
31
  help - Shows a list of commands or help for one command
32
- parse - Analyze the memory footprint of each part or component in Xcode project
33
- search - search str(or strs) in some file(or folder's file)
34
- search_file - search File in folder
35
- search_unuse_class - search unuse class
36
- size_for - calculate the memory footprint of file or folder(contain file)
32
+ parse - 解析linkmap
33
+ pre_commit - 通过执行该命令,hook 本地commit,然后进行规范化
34
+ search - 在文件夹或文件中查找字符串(或者字符串组)
35
+ search_file - 查找文件
36
+ search_unuse_class - 查找无用类
37
+ size_for - 计算文件或者文件夹占用内存大小
37
38
  ```
38
39
 
39
40
  ### 功能1:解析LinkMap
data/bin/itools CHANGED
@@ -7,15 +7,20 @@ include GLI::App
7
7
  program_desc 'a collection of tools for ios developer'
8
8
  version Itools::VERSION
9
9
 
10
- desc "Analyze the memory footprint of each part or component in Xcode project"
10
+ desc "解析linkmap"
11
11
  arg 'xxx.txt'
12
12
  command :parse do |c|
13
13
  c.action do |global_options, options, args|
14
- Itools::LinkMap.parser(args[0])
14
+ if args.size == 1
15
+ Itools::LinkMap.parser(args[0])
16
+ else
17
+ Itools::LinkMap.parser_by_folder(args)
18
+ end
19
+
15
20
  end
16
21
  end
17
22
 
18
- desc "search str(or strs) in some file(or folder's file)"
23
+ desc "在文件夹或文件中查找字符串(或者字符串组)"
19
24
  arg 'xxx.txt'
20
25
  command :search do |c|
21
26
  c.action do |global_options, options, args|
@@ -23,7 +28,7 @@ command :search do |c|
23
28
  end
24
29
  end
25
30
  # 查找工程中没有用到的图片
26
- desc "search unuse image"
31
+ desc "查找无用图片"
27
32
  arg 'xxx.txt'
28
33
  command :find do |c|
29
34
  c.action do |global_options, options, args|
@@ -31,7 +36,7 @@ command :find do |c|
31
36
  end
32
37
  end
33
38
  # 查找Xcode工程中没有用到的类
34
- desc "search unuse class"
39
+ desc "查找无用类"
35
40
  arg 'xxx.txt'
36
41
  command :search_unuse_class do |c|
37
42
  c.action do |global_options, options, args|
@@ -40,7 +45,7 @@ command :search_unuse_class do |c|
40
45
  end
41
46
 
42
47
  # 计算占用内存大小
43
- desc "calculate the memory footprint of file or folder(contain file)"
48
+ desc "计算文件或者文件夹占用内存大小"
44
49
  arg 'xxx.txt'
45
50
  command :size_for do |c|
46
51
  c.action do |global_options, options, args|
@@ -49,7 +54,7 @@ command :size_for do |c|
49
54
  end
50
55
 
51
56
  # 查找文件
52
- desc "search File in folder"
57
+ desc "查找文件"
53
58
  arg 'file name'
54
59
  command :search_file do |c|
55
60
  c.action do |global_options, options, args|
@@ -58,7 +63,7 @@ command :search_file do |c|
58
63
  end
59
64
 
60
65
  # 统计代码行数
61
- desc "count lines of code"
66
+ desc "统计代码行数"
62
67
  arg 'file name or folder'
63
68
  command :count_code_line do |c|
64
69
  c.action do |global_options, options, args|
@@ -1,12 +1,17 @@
1
1
  require 'fileutils'
2
2
  require 'pathname'
3
-
3
+ require 'find'
4
4
  module Itools
5
5
  # ---------------------------------ObjectFile class---------------------------------
6
6
  class ObjectFile
7
- attr_accessor :serial_number, :file_path, :file_name
7
+ # file_size:单个文件的大小
8
+ # o_name:某个文件的名字
9
+ # o_size: 某个o文件的大小
10
+ attr_accessor :serial_number, :file_path, :file_name, :file_size, :o_name, :o_size
8
11
  def initialize()
9
12
  @serial_number = []
13
+ @file_size = 0
14
+ @o_size = 0
10
15
  end
11
16
 
12
17
  end
@@ -53,9 +58,19 @@ module Itools
53
58
  obj_file.serial_number = tempSplit[0].delete("[").strip.to_i #设置serial_number
54
59
  obj_file.file_path = tempSplit[1].strip
55
60
  obj_file.file_name = tempSplit[1].split("/").last.chomp
61
+ obj_file.o_name = get_o_name(tempSplit[1].split("/").last.chomp)
56
62
  l_obj_files << obj_file
57
63
  end
58
64
  end
65
+ # 得到o_ame 有待优化,可以使用正则表达式处理TODO
66
+ def get_o_name(str)
67
+ temp_arr = str.split("(")
68
+ if temp_arr.size > 1
69
+ temp_arr[1].split(".o)")[0]
70
+ else
71
+ return temp_arr[0].split(".o")[0]
72
+ end
73
+ end
59
74
  # 处理sections
60
75
  def handle_sections(str)
61
76
  sectionSplit = str.split(" ")
@@ -131,6 +146,7 @@ module Itools
131
146
 
132
147
  end
133
148
  end
149
+ # 对linkmap进行解析,然后输出结果
134
150
  def self.parser(path_para)
135
151
  start_time = Time.now.to_i #程序开始执行时间(以毫秒为单位)
136
152
  # 获取link map file's name
@@ -138,8 +154,8 @@ module Itools
138
154
  puts "获取的文件路径为:#{link_map_file_name}"
139
155
  if link_map_file_name.nil?
140
156
  puts "请按照如下命令执行该脚本:"
141
- puts "\033[31mruby linkMapParse.rb **.txt \033[0m"
142
- puts "**指代Link Map File的名字,例如LinkMapApp-LinkMap-normal-x86_64.txt"
157
+ puts "\033[31mitools parse **.txt \033[0m"
158
+ puts "**指代Link Map File的名字,例如LinkMapApp-LinkMap-normal-x86_64.txt,parse后面为绝对路径"
143
159
  return
144
160
  end
145
161
  if File.exist?(link_map_file_name)
@@ -223,10 +239,99 @@ module Itools
223
239
  puts "\033[32m整个程序执行时间为:#{end_time - start_time}秒\033[0m"
224
240
  end
225
241
 
242
+ # 根据linkmap && folder计算占用
243
+ # 第一个参数为linkmap路径,第二个参数为要分析的项目文件夹
244
+ def self.parser_by_folder(args)
245
+ link_map_file_name = args[0] #linkmap文件路径
246
+ project_folder = args[1] #项目文件夹
247
+ # 对参数进行校验
248
+ if File::directory?(project_folder)
249
+ puts "获取的项目目录路径为:#{project_folder}"
250
+ else
251
+ puts "\033[31m#{project_folder}文件夹不存在,请重新输入 \033[0m"
252
+ return
253
+ end
254
+ if File.exist?(link_map_file_name)
255
+ puts "获取的linkmap文件路径为:#{link_map_file_name}"
256
+ puts "\033[32m获取LinkMap文件: #{link_map_file_name}成功,开始分析数据...\033[0m"
257
+ else
258
+ puts "\033[31m#{link_map_file_name}文件不存在,请重新输入 \033[0m"
259
+ return
260
+ end
261
+ # 开始处理数据
262
+ link_map = LinkMap.new(link_map_file_name)
263
+ link_map.handle_map #处理文件为对象,然后继续后续操作
264
+ link_map.handle_l_sym_map #处理symbols为hashmap
265
+
266
+ # 所有的文件
267
+ link_map.l_obj_files
268
+ # 所有的symbols
269
+ link_map.l_symbols
270
+
271
+ # 处理得到每个obj_file的大小
272
+ link_map.l_obj_files.each do |obj|
273
+ if link_map.l_sym_map[obj.serial_number]
274
+ link_map.l_sym_map[obj.serial_number].each do |symb|
275
+ obj.o_size = obj.o_size + symb.s_size.hex
276
+ end
277
+ end
278
+ end
279
+ # key为文件名,value为ojbect
280
+ sort_by_obj_files_map = link_map.l_obj_files.group_by(&:o_name)
281
+ # save_file_path = SizeResult.getSaveFileName(project_folder)
282
+ # save_file = File.new(save_file_path,"w+")
283
+ # sort_by_obj_files_map.keys.each do |sss|
284
+
285
+ # save_file.puts("#{sort_by_obj_files_map[sss][0].o_name} #{sort_by_obj_files_map[sss][0].o_size}")
286
+ # end
287
+ # save_file.close
288
+ # exit
289
+
290
+
291
+
292
+ size_results = [] #盛放计算结果
293
+ size_files = []
294
+ space_index = 0
295
+ puts "计算开始"
296
+ traverse_dir(sort_by_obj_files_map,project_folder,size_results,size_files,space_index)
297
+ size_results.reverse!
298
+ # 存储为文件
299
+ save_file_path = SizeResult.getSaveFileName(project_folder)
300
+ if File.exist?(save_file_path)
301
+ File.delete(save_file_path)
302
+ end
303
+ save_file = File.new(save_file_path,"w+")
304
+ size_results.each do |o|
305
+ save_file.puts("#{' ' * o.space_count}|- #{o.folder_name.split('/').last} #{SizeResult.handleSize(o.size)}")
306
+ end
307
+ save_file.close
308
+ puts "分析结果已经保存为文件,位置为:\n\033[32m#{save_file_path}\033[0m"
309
+ end
310
+ def self.traverse_dir(sort_by_obj_files_map,file_path,results,size_files,space_index)
311
+ s_result = SizeResult.new
312
+ s_result.folder_name = file_path
313
+ space_index = space_index + 2
314
+ file_name_arr = [] #盛放计算过的类
315
+ Find.find(file_path) do |file|
316
+ if File.file?(file)
317
+ file_name = File.basename(file,".*")
318
+ if !file_name_arr.include?(file_name) && sort_by_obj_files_map[file_name] #没有已经计算过
319
+ s_result.size = s_result.size + sort_by_obj_files_map[file_name][0].o_size
320
+ file_name_arr << file_name
321
+ end
322
+ elsif File::directory?(file) && file != file_path
323
+ traverse_dir(sort_by_obj_files_map,file,results,size_files,space_index)
324
+ end
325
+ end
326
+ if s_result.size > 0 && !size_files.include?(s_result.folder_name)
327
+ s_result.space_count = space_index
328
+ results << s_result
329
+ size_files << s_result.folder_name
330
+ end
331
+ end
226
332
  end
227
- # --------------------------------- Size utils class ---------------------------------
228
333
  class SizeResult
229
- attr_accessor :file_name, :file_serial_numers, :size
334
+ attr_accessor :file_name, :file_serial_numers, :size,:folder_name, :space_count
230
335
  def initialize
231
336
  @file_serial_numers = []
232
337
  @size = 0
@@ -248,5 +353,7 @@ module Itools
248
353
  save_file_path = path.dirname.to_s + "/" + "parse_" + path.basename.to_s + "_result.txt"
249
354
  return save_file_path
250
355
  end
251
- end
356
+ end
252
357
  end
358
+
359
+ # --------------------------------- Size utils class ---------------------------------
@@ -1,3 +1,3 @@
1
1
  module Itools
2
- VERSION = "0.4.8"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhanggui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2019-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler