├── .gitignore ├── lib ├── cocoapods-TSPodfileTimeWatch.rb ├── cocoapods-TSPodfileTimeWatch │ ├── command.rb │ ├── gem_version.rb │ └── command │ │ └── TSPodfileTimeWatch.rb └── cocoapods_plugin.rb ├── Rakefile ├── Gemfile ├── spec ├── command │ └── TSPodfileTimeWatch_spec.rb └── spec_helper.rb ├── cocoapods-TSPodfileTimeWatch.gemspec ├── LICENSE.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | pkg 3 | .idea/ 4 | -------------------------------------------------------------------------------- /lib/cocoapods-TSPodfileTimeWatch.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-TSPodfileTimeWatch/gem_version' 2 | -------------------------------------------------------------------------------- /lib/cocoapods-TSPodfileTimeWatch/command.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-TSPodfileTimeWatch/command/TSPodfileTimeWatch' 2 | -------------------------------------------------------------------------------- /lib/cocoapods-TSPodfileTimeWatch/gem_version.rb: -------------------------------------------------------------------------------- 1 | module CocoapodsTspodfiletimewatch 2 | VERSION = "0.0.6" 3 | end 4 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | 3 | def specs(dir) 4 | FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ') 5 | end 6 | 7 | desc 'Runs all the specs' 8 | task :specs do 9 | sh "bundle exec bacon #{specs('**')}" 10 | end 11 | 12 | task :default => :specs 13 | 14 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in cocoapods-TSPodfileTimeWatch.gemspec 4 | gemspec 5 | 6 | group :development do 7 | gem 'cocoapods' 8 | 9 | gem 'mocha' 10 | gem 'bacon' 11 | gem 'mocha-on-bacon' 12 | gem 'prettybacon' 13 | end 14 | -------------------------------------------------------------------------------- /spec/command/TSPodfileTimeWatch_spec.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../../spec_helper', __FILE__) 2 | 3 | module Pod 4 | describe Command::Tspodfiletimewatch do 5 | describe 'CLAide' do 6 | it 'registers it self' do 7 | Command.parse(%w{ TSPodfileTimeWatch }).should.be.instance_of Command::Tspodfiletimewatch 8 | end 9 | end 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /cocoapods-TSPodfileTimeWatch.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'cocoapods-TSPodfileTimeWatch/gem_version.rb' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'cocoapods-TSPodfileTimeWatch' 8 | spec.version = CocoapodsTspodfiletimewatch::VERSION 9 | spec.authors = ['keai'] 10 | spec.email = ['604922471@qq.com'] 11 | spec.description = %q{cocoapods-TSPodfileTimeWatch} 12 | spec.summary = <<-DESC 13 | cocoapods-TSPodfileTimeWatch 14 | DESC 15 | spec.homepage = 'https://github.com/cxr0715/cocoapods-TSPodfileTimeWatch' 16 | spec.license = 'MIT' 17 | 18 | spec.files = `git ls-files`.split($/) 19 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 20 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 21 | spec.require_paths = ['lib'] 22 | 23 | spec.add_development_dependency 'bundler', '~> 1.3' 24 | spec.add_development_dependency 'rake' 25 | end 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 xueruicao 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'pathname' 2 | ROOT = Pathname.new(File.expand_path('../../', __FILE__)) 3 | $:.unshift((ROOT + 'lib').to_s) 4 | $:.unshift((ROOT + 'spec').to_s) 5 | 6 | require 'bundler/setup' 7 | require 'bacon' 8 | require 'mocha-on-bacon' 9 | require 'pretty_bacon' 10 | require 'pathname' 11 | require 'cocoapods' 12 | 13 | Mocha::Configuration.prevent(:stubbing_non_existent_method) 14 | 15 | require 'cocoapods_plugin' 16 | 17 | #-----------------------------------------------------------------------------# 18 | 19 | module Pod 20 | 21 | # Disable the wrapping so the output is deterministic in the tests. 22 | # 23 | UI.disable_wrap = true 24 | 25 | # Redirects the messages to an internal store. 26 | # 27 | module UI 28 | @output = '' 29 | @warnings = '' 30 | 31 | class << self 32 | attr_accessor :output 33 | attr_accessor :warnings 34 | 35 | def puts(message = '') 36 | @output << "#{message}\n" 37 | end 38 | 39 | def warn(message = '', actions = []) 40 | @warnings << "#{message}\n" 41 | end 42 | 43 | def print(message) 44 | @output << message 45 | end 46 | end 47 | end 48 | end 49 | 50 | #-----------------------------------------------------------------------------# 51 | -------------------------------------------------------------------------------- /lib/cocoapods-TSPodfileTimeWatch/command/TSPodfileTimeWatch.rb: -------------------------------------------------------------------------------- 1 | module Pod 2 | class Command 3 | # This is an example of a cocoapods plugin adding a top-level subcommand 4 | # to the 'pod' command. 5 | # 6 | # You can also create subcommands of existing or new commands. Say you 7 | # wanted to add a subcommand to `list` to show newly deprecated pods, 8 | # (e.g. `pod list deprecated`), there are a few things that would need 9 | # to change. 10 | # 11 | # - move this file to `lib/pod/command/list/deprecated.rb` and update 12 | # the class to exist in the the Pod::Command::List namespace 13 | # - change this class to extend from `List` instead of `Command`. This 14 | # tells the plugin system that it is a subcommand of `list`. 15 | # - edit `lib/cocoapods_plugins.rb` to require this file 16 | # 17 | # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org 18 | # in the `plugins.json` file, once your plugin is released. 19 | # 20 | class Tspodfiletimewatch < Command 21 | self.summary = 'Short description of cocoapods-TSPodfileTimeWatch.' 22 | 23 | self.description = <<-DESC 24 | Longer description of cocoapods-TSPodfileTimeWatch. 25 | DESC 26 | 27 | self.arguments = [] 28 | 29 | def initialize(argv) 30 | @name = argv.shift_argument 31 | super 32 | end 33 | 34 | def validate! 35 | super 36 | help! 'A Pod name is required.' unless @name 37 | end 38 | 39 | def run 40 | UI.puts "Add your implementation for the cocoapods-TSPodfileTimeWatch plugin in #{__FILE__}" 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cocoapods-TSPodfileTimeWatch 2 | 3 | 4 | 5 | ## 统计每个pod库下载耗时插件 6 | [![rnhmct.png](https://s3.ax1x.com/2020/12/14/rnhmct.png)](https://imgchr.com/i/rnhmct) 7 | 8 | ## 安装: 9 | 10 | 使用cocoapods plugin的方式实现 11 | 12 | ```bash 13 | $ gem install cocoapods-TSPodfileTimeWatch 14 | ``` 15 | 16 | 所有功能实现都在/CocoaPods/cocoapods-TSPodfileTimeWatch/lib/cocoapods_plugin.rb文件中 17 | 目前版本0.0.6(加入CDN耗时统计)--2020.12.14 18 | 19 | ## 使用方法 20 | 21 | 1. gem install cocoapods-TSPodfileTimeWatch(安装cocoapods-TSPodfileTimeWatch) 22 | 2. 删除pods文件夹(为了统计耗时,所以要先删除pods文件夹) 23 | 3. 删除podfile.lock文件(为了统计耗时,所以要先删除podfile.lock文件) 24 | 4. 删除pod缓存(pod cache clean --all,为了统计耗时,所以要先删除缓存) 25 | 5. 在podfile起始加入: 26 | 27 | ```ruby 28 | # 在这里判断是否启动插件,再加个异常保护 29 | begin 30 | if system "gem list | grep \"cocoapods-TSPodfileTimeWatch\"" 31 | # 判断是否有装cocoapods-TSPodfileTimeWatch插件 32 | plugin "cocoapods-TSPodfileTimeWatch" 33 | end 34 | # 其他plugin... 35 | end 36 | ``` 37 | 38 | 6. 执行pod update --verbose(或者是pod install --verbose,但是一定要加--verbose,只有加了--verbose才会输出csv以及详细下载耗时信息,并且会在每个库下载结束后输出对应信息) 39 | 40 | git方式: 41 | 42 | [![rn4bi4.png](https://s3.ax1x.com/2020/12/14/rn4bi4.png)](https://imgchr.com/i/rn4bi4) 43 | 44 | CDN方式: 45 | 46 | [![rn5pdO.png](https://s3.ax1x.com/2020/12/14/rn5pdO.png)](https://imgchr.com/i/rn5pdO) 47 | 48 | 7. pod结束后会在pods文件夹下生成AllPodsTimeAndSize.csv文件,用来记录所有pod下载耗时情况。(之前的pod install/update指令,无论加不加--verbose,都会在最后输出这次pod下载数据的信息) 49 | 50 | [![rn5tmV.png](https://s3.ax1x.com/2020/12/14/rn5tmV.png)](https://imgchr.com/i/rn5tmV) 51 | 52 | 8. 如果git clone文件大小和cache文件大的差值越大,说明下载的多余文件越多,则存在可优化空间。 53 | 54 | 9. 可以通过尝试把podfile中使用git commit集成的,修改为使用git tag集成的方式,减少git clone下载内容。也可以尝试把之前git方式下载的库,修改为CDN方式下载(需要自建CDN服务器),下载压缩包会使下载的资源小很多,速度进而加快很多。 55 | 56 | 10. 如果要卸载,gem uninstall cocoapods-TSPodfileTimeWatch 57 | -------------------------------------------------------------------------------- /lib/cocoapods_plugin.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-TSPodfileTimeWatch/command' 2 | require 'csv' 3 | class Dir 4 | def self.size(dir) 5 | sum = 0 6 | Dir.foreach(dir) do |entry| 7 | begin 8 | next if entry =~ /^\./ && entry != '.git' 9 | next if entry == "lfs" # 不统计在lfs文件夹下的资源,git clone下载的是lfs内的资源,之后copy到真正目录下,导致大小统计了两次,所以这里不统计lfs目录下的资源 10 | path = File.join(dir, entry) 11 | FileTest.directory?(path) ? sum += Dir.size(path) : sum += File.size(path) 12 | rescue => exception 13 | puts "\e[31mCocoapodsTSPodfileTimeWatch Dir.size error(已捕获): #{exception}\e[0m" 14 | next 15 | retry 16 | end 17 | end 18 | sum 19 | end 20 | end 21 | $pluginIsVerbose = false 22 | $pluginCurrentTarget = "" 23 | $pluginCurrentPodName = "" 24 | $pluginCurrentZipSize = 0 25 | $pluginCurrentZipAllSize = 0 26 | $gitSize = 0 27 | $gitAllSize = 0 28 | $cloneTime = 0 29 | $cloneAllTime = 0 30 | $downloadTime = 0 31 | $downloadAllTime = 0 32 | $cdnDownloadTime = 0 33 | $cdnDownloadAllTime = 0 34 | $cdnUnZipTime = 0 35 | $cdnUnZipAllTime = 0 36 | if ARGV.include?("--verbose") 37 | $pluginIsVerbose = true 38 | end 39 | 40 | module CocoapodsTSPodfileTimeWatch 41 | 42 | Pod::HooksManager.register("cocoapods-TSPodfileTimeWatch", :pre_install) do |context| 43 | begin 44 | if $pluginIsVerbose == true 45 | # home路径下是否存在.AllPodsTimeAndSize.csv的隐藏文件 46 | if File.exist?("#{Dir.home}/.AllPodsTimeAndSize.csv") 47 | # 如果存在则先删除,每次都生成新的csv文件 48 | File.delete("#{Dir.home}/.AllPodsTimeAndSize.csv") 49 | end 50 | # 统计到csv中 51 | CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "ab:utf-8") do |csv| 52 | csv << ["\xEF\xBB\xBF名称", "下载耗时(S)", "下载文件大小(M)", "cache文件大小(M)", "大小差值(Git专用)", "CDN/Git", "CDN下载耗时", "CDN解压耗时"] 53 | end 54 | end 55 | rescue => exception 56 | 57 | end 58 | end 59 | Pod::HooksManager.register("cocoapods-TSPodfileTimeWatch", :post_install) do |context| 60 | begin 61 | puts "\e[31mCocoapodsTSPodfileTimeWatch GitCloneAllSize: #{$gitAllSize} M\e[0m" 62 | puts "\e[31mCocoapodsTSPodfileTimeWatch GitCloneAllTime: #{$cloneAllTime} S\e[0m" 63 | puts "\e[31mCocoapodsTSPodfileTimeWatch CDNDownloadAllSize: #{$pluginCurrentZipAllSize} M\e[0m" 64 | puts "\e[31mCocoapodsTSPodfileTimeWatch CDNAllTime: #{$downloadAllTime} S\e[0m" 65 | puts "\e[31mCocoapodsTSPodfileTimeWatch CDNDownloadAllTime: #{$cdnDownloadAllTime} S\e[0m" 66 | puts "\e[31mCocoapodsTSPodfileTimeWatch CDNUnzipAllTime: #{$cdnUnZipAllTime} S\e[0m" 67 | # 如果是--verbose模式且$gitAllSize与$cloneAllTime(不为0表示有下载pod) 68 | if $pluginIsVerbose == true && $gitAllSize != 0 && $cloneAllTime != 0 && $pluginCurrentZipAllSize != 0 && $downloadAllTime != 0 69 | File.rename "#{Dir.home}/.AllPodsTimeAndSize.csv", "#{context.sandbox_root}/AllPodsTimeAndSize.csv" 70 | puts "\e[31m具体的统计数据请在#{context.sandbox_root}/AllPodsTimeAndSize.csv中查看\e[0m" 71 | end 72 | rescue => exception 73 | # 如果没有下载则#{Dir.home}/.AllPodsTimeAndSize.csv文件不会生成,产生异常 74 | puts "\e[31mCocoapodsTSPodfileTimeWatch post_install error(已捕获): #{exception}\e[0m" 75 | end 76 | end 77 | 78 | class Pod::Downloader::Cache 79 | # 使用方法别名hook copy_and_clean方法 80 | alias :origin_copy_and_clean :copy_and_clean 81 | def copy_and_clean(source, destination, spec) 82 | time1 = Time.new 83 | # 执行之前的拷贝到cache并且清除git clone临时目录的方法 84 | origin_copy_and_clean(source, destination, spec) 85 | time2 = Time.new 86 | # 获取时间差 87 | time = time2 - time1 88 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{spec.name} copy_and_clean time: #{time}"+" S\e[0m" 89 | # 如果是--verbose,则输出详细信息,生成csv 90 | if $pluginIsVerbose == true 91 | verboseCopy_and_clean(source, destination, spec) 92 | end 93 | end 94 | 95 | # --verbose输出详细信息,生成在home路径下.AllPodsTimeAndSize.csv的隐藏文件 96 | def verboseCopy_and_clean(source, destination, spec) 97 | begin 98 | # 计算拷贝到的目录下所有文件总大小,单位为M 99 | dirSum = Dir.size(destination.to_s)/1000.0/1000.0 100 | # 标红输出cache文件大小,单位为M 101 | puts "\e[31mCocoapodsTSPodfileTimeWatch cachesize #{spec.name}: "+"#{dirSum}"+" M\e[0m" 102 | # 如果相等则为CDN的下载方式 103 | if $gitSize == 0 104 | # CDN的下载方式 105 | CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "a+") do |csv| 106 | csv << [spec.name, $downloadTime, $pluginCurrentZipSize, dirSum, "CDN不统计此项", "CDN", $cdnDownloadTime, $cdnUnZipTime] 107 | end 108 | else 109 | # git的下载方式 110 | # 计算git clone大小和cache文件大小的差值,如果差值过大,则有优化空间 111 | diffSize = $gitSize - dirSum 112 | # 标红输出差值 113 | puts "\e[31mCocoapodsTSPodfileTimeWatch diffSize = #{diffSize}"+"M \e[0m" 114 | CSV.open("#{Dir.home}/.AllPodsTimeAndSize.csv", "a+") do |csv| 115 | csv << [spec.name, $cloneTime, $gitSize, dirSum, diffSize, "Git", "Git不统计此项", "Git不统计此项"] 116 | end 117 | end 118 | 119 | # 换行 120 | puts 121 | 122 | rescue => exception 123 | # 输出拷贝清除方法异常 124 | puts "\e[31mCocoapodsTSPodfileTimeWatch verboseCopy_and_clean error(已捕获): #{exception}\e[0m" 125 | end 126 | $gitSize = 0 127 | end 128 | end 129 | 130 | 131 | class Pod::Downloader::Cache 132 | 133 | alias :origin_download :download 134 | 135 | def download(request, target) 136 | # 获取downloader下载的文件路径 137 | source = target.to_s 138 | # 赋值当前正在下载的文件路径给全局变量,为了解压zip的时候做判断 139 | $pluginCurrentTarget = source 140 | # 赋值当前正在下载的pod名称给全局变量,为了解压zip的时候做输出 141 | $pluginCurrentPodName = request.name.to_s 142 | # 获取clone执行前时间点 143 | time1 = Time.new 144 | # 执行之前的download_source方法,接收该方法的返回值 145 | result, podspecs = origin_download(request, target) 146 | 147 | # 如果不是--verbose,只输出总耗时,总下载大小 148 | # 捕获一下异常,不会因为plugin的原因导致pod失败 149 | begin 150 | # 获取clone执行后时间点 151 | time2 = Time.new 152 | # 获取时间差 153 | time = time2 - time1 154 | if request.params["git".to_sym] 155 | # 说明是git方式 156 | # 赋值一个给全局变量,之后时间统计要用到 157 | $cloneTime = time 158 | # 赋值一个给全局变量,之后时间统计要用到 159 | $cloneAllTime = $cloneAllTime + time 160 | # 计算downloader下载的文件大小,单位为M 161 | dirSum = Dir.size(source)/1000.0/1000.0 162 | # 赋值给一个全局变量,之后输出会用到 163 | $gitAllSize = $gitAllSize + dirSum 164 | else 165 | # 说明是CDN方式 166 | # 赋值一个给全局变量,之后时间统计要用到 167 | $downloadTime = time 168 | # 赋值一个给全局变量,之后时间统计要用到 169 | $downloadAllTime = $downloadAllTime + time 170 | # 赋值给一个全局变量,之后输出会用到 171 | $cdnDownloadAllTime = $cdnDownloadAllTime + $cdnDownloadTime 172 | # 赋值给一个全局变量,之后输出会用到 173 | $cdnUnZipAllTime = $cdnUnZipAllTime + $cdnUnZipTime 174 | # 赋值给一个全局变量,之后输出会用到 175 | $pluginCurrentZipAllSize = $pluginCurrentZipAllSize + $pluginCurrentZipSize 176 | end 177 | 178 | # 如果是--verbose,则输出详细信息,生成csv 179 | if $pluginIsVerbose == true 180 | verboseDownload(request, time, dirSum) 181 | end 182 | # 返回值 183 | [result, podspecs] 184 | rescue => exception 185 | # 标红输出git clone hook异常 186 | puts "\e[31mCocoapodsTSPodfileTimeWatch download error(已捕获): #{exception}\e[0m" 187 | end 188 | end 189 | 190 | def verboseDownload(request, time, dirSum) 191 | if request.params["git".to_sym] 192 | # 说明是git方式 193 | # 标红输出git clone耗时 194 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} clone time: #{time}"+" S\e[0m" 195 | # 赋值给一个全局变量,之后输出会用到 196 | $gitSize = dirSum 197 | # 标红输出git clone下载文件大小 198 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} clone allsize: "+"#{dirSum}"+" M\e[0m" 199 | else 200 | # 说明是CDN方式 201 | # 标红输出CDN 下载耗时 202 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN download time: #{$cdnDownloadTime}"+" S\e[0m" 203 | # 标红输出CDN 解压耗时 204 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN unzip time: #{$cdnUnZipTime}"+" S\e[0m" 205 | # 标红输出CDN 总耗时 206 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN All time: #{$downloadTime}"+" S\e[0m" 207 | # 标红输出CDN clone下载文件大小 208 | puts "\e[31mCocoapodsTSPodfileTimeWatch #{request.name.to_s} CDN zipSize: "+"#{$pluginCurrentZipSize}"+" M\e[0m" 209 | end 210 | 211 | end 212 | 213 | end 214 | 215 | class Pod::Downloader::Http 216 | # 使用方法别名hook解压方法,获取解压之前的文件大小 217 | alias :origin_download_file :download_file 218 | alias :origin_extract_with_type :extract_with_type 219 | 220 | def download_file(_full_filename) 221 | # 捕获一下异常,不会因为plugin的原因导致pod失败 222 | begin 223 | if _full_filename.to_s.include?($pluginCurrentTarget) 224 | # 说明是之前被赋值的开始下载了 225 | 226 | # 获取CDN下载执行前时间点 227 | time1 = Time.new 228 | # 执行原来的CDN下载方法 229 | origin_download_file(_full_filename) 230 | # 获取CDN下载执行后时间点 231 | time2 = Time.new 232 | # 赋值CDN下载耗时给全局变量,用于之后输出以及写在csv中 233 | $cdnDownloadTime = time2 - time1 234 | else 235 | # 说明不是之前被赋值的开始下载了,输出一下,然后清空 236 | puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentTarget} target error\e[0m" 237 | puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentPodName} name error\e[0m" 238 | $pluginCurrentTarget = "" 239 | $pluginCurrentPodName = "" 240 | end 241 | rescue => exception 242 | # 输出CDM下载方法异常 243 | puts "\e[31mCocoapodsTSPodfileTimeWatch download_file error(已捕获): #{exception}\e[0m" 244 | end 245 | 246 | end 247 | 248 | def extract_with_type(full_filename, type = :zip) 249 | # 捕获一下异常,不会因为plugin的原因导致pod失败 250 | begin 251 | if full_filename.to_s.include?($pluginCurrentTarget) 252 | # 说明是之前被赋值的下载完成了,开始进行解压了 253 | 254 | # 计算拷贝到的目录下所有文件总大小,单位为M 255 | dirSum = File.size(full_filename.to_s)/1000.0/1000.0 256 | # 赋值给当前正在解压的zip大小,之后输出到csv要用 257 | $pluginCurrentZipSize = dirSum 258 | else 259 | # 说明不是之前被赋值的下载完成了,输出一下,然后清空 260 | puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentTarget} target error\e[0m" 261 | puts "\e[31mCocoapodsTSPodfileTimeWatch unzip warning: #{$pluginCurrentPodName} name error\e[0m" 262 | $pluginCurrentTarget = "" 263 | $pluginCurrentPodName = "" 264 | end 265 | rescue => exception 266 | # 输出CDN解压方法异常 267 | puts "\e[31mCocoapodsTSPodfileTimeWatch extract_with_type error(已捕获): #{exception}\e[0m" 268 | end 269 | # 获取CDN解压前时间点 270 | time1 = Time.new 271 | # 执行之前的解压方法 272 | origin_extract_with_type(full_filename, type) 273 | # 获取CDN解压后时间点 274 | time2 = Time.new 275 | # 赋值CDN解压耗时给全局变量,用于之后输出以及写在csv中 276 | $cdnUnZipTime = time2 - time1 277 | end 278 | end 279 | 280 | # class Pod::Downloader::Git 281 | # # 使用方法别名hook clone方法 282 | # alias :origin_clone :clone 283 | # def clone(force_head = false, shallow_clone = true) 284 | # # 获取clone执行前时间点 285 | # time1 = Time.new 286 | # # 执行之前的clone方法 287 | # origin_clone(force_head, shallow_clone) 288 | 289 | # # 如果不是--verbose,只输出总耗时,总下载大小 290 | # # 捕获一下异常,不会因为plugin的原因导致pod失败 291 | # begin 292 | # # 获取clone执行后时间点 293 | # time2 = Time.new 294 | # # 获取时间差 295 | # time = time2 - time1 296 | # # 赋值一个给全局变量,之后时间统计要用到 297 | # $cloneTime = time 298 | # # 赋值一个给全局变量,之后时间统计要用到 299 | # $cloneAllTime = $cloneAllTime + time 300 | # # 获取git clone下载的文件路径 301 | # source = target_path.to_s 302 | # # 计算git clone下载的文件大小,单位为M 303 | # dirSum = Dir.size(source)/1000.0/1000.0 304 | # # 赋值给一个全局变量,之后输出会用到 305 | # $gitAllSize = $gitAllSize + dirSum 306 | # # 如果是--verbose,则输出详细信息,生成csv 307 | # if $pluginIsVerbose == true 308 | # verboseClone(force_head, shallow_clone, time, dirSum) 309 | # end 310 | # rescue => exception 311 | # # 标红输出git clone hook异常 312 | # puts "\e[31mCocoapodsTSPodfileTimeWatch clone error(已捕获): #{exception}\e[0m" 313 | # end 314 | 315 | # end 316 | 317 | # # --verbose输出每个库的下载耗时 318 | # def verboseClone(force_head, shallow_clone, time, dirSum) 319 | # # 这里只能根据url获取到pod名称的开始index 320 | # start = url.rindex("/") + 1 321 | # # 获取pod名称 322 | # podName = url[start, url.length] 323 | # # 标红输出git clone耗时 324 | # puts "\e[31mCocoapodsTSPodfileTimeWatch #{podName} clone time: #{time}\e[0m" 325 | # # 赋值给一个全局变量,之后输出会用到 326 | # $gitSize = dirSum 327 | # # 标红输出git clone下载文件大小 328 | # puts "\e[31mCocoapodsTSPodfileTimeWatch #{podName} clone allsize: "+"#{dirSum}"+"M\e[0m" 329 | # end 330 | # end 331 | end --------------------------------------------------------------------------------