zoukankan      html  css  js  c++  java
  • [效率提升] 记一次使用工具编辑正则表达式快速输出匹配结果

           最近在使用python编写统计 android设备应用的帧率(FPS),通过adb shell dumpsys gfxinfo (packagename) 获取到数据后,如何对所有 Profile data in ms值进行提取,最先想到的肯定是要用正则表达式才能快速提取出想要的内容,具体要提取内容如下:

      1 Applications Graphics Acceleration Info:
      2 Uptime: 31994594 Realtime: 103860953
      3 
      4 ** Graphics info for pid 1499 [com.google.launcher] **
      5 
      6 Stats since: 16212900501273ns
      7 Total frames rendered: 37545
      8 Janky frames: 18745 (49.93%)
      9 50th percentile: 17ms
     10 90th percentile: 28ms
     11 95th percentile: 36ms
     12 99th percentile: 61ms
     13 Number Missed Vsync: 1209
     14 Number High input latency: 545
     15 Number Slow UI thread: 3348
     16 Number Slow bitmap uploads: 32
     17 Number Slow issue draw commands: 17592
     18 HISTOGRAM: 5ms=4 6ms=102 7ms=254 8ms=1477 9ms=5596 10ms=5048 11ms=2306 12ms=985 13ms=624 14ms=604 15ms=583 16ms=938 17ms=1427 18ms=3251 19ms=4266 20ms=1897 21ms=1385 22ms=867 23ms=536 24ms=428 25ms=404 26ms=337 27ms=355 28ms=360 29ms=340 30ms=307 31ms=269 32ms=356 34ms=268 36ms=230 38ms=197 40ms=143 42ms=106 44ms=61 46ms=69 48ms=151 53ms=343 57ms=295 61ms=95 65ms=61 69ms=64 73ms=65 77ms=19 81ms=12 85ms=8 89ms=10 93ms=4 97ms=11 101ms=1 105ms=2 109ms=2 113ms=1 117ms=2 121ms=2 125ms=1 129ms=2 133ms=0 150ms=6 200ms=2 250ms=1 300ms=2 350ms=1 400ms=0 450ms=0 500ms=0 550ms=0 600ms=1 650ms=0 700ms=0 750ms=0 800ms=1 850ms=0 900ms=0 950ms=0 1000ms=0 1050ms=0 1100ms=0 1150ms=0 1200ms=0 1250ms=0 1300ms=0 1350ms=0 1400ms=0 1450ms=0 1500ms=0 1550ms=0 1600ms=0 1650ms=0 1700ms=0 1750ms=0 1800ms=0 1850ms=0 1900ms=0 1950ms=0 2000ms=0 2050ms=0 2100ms=0 2150ms=0 2200ms=0 2250ms=0 2300ms=0 2350ms=0 2400ms=0 2450ms=0 2500ms=0 2550ms=0 2600ms=0 2650ms=0 2700ms=0 2750ms=0 2800ms=0 2850ms=0 2900ms=0 2950ms=0 3000ms=0 3050ms=0 3100ms=0 3150ms=0 3200ms=0 3250ms=0 3300ms=0 3350ms=0 3400ms=0 3450ms=0 3500ms=0 3550ms=0 3600ms=0 3650ms=0 3700ms=0 3750ms=0 3800ms=0 3850ms=0 3900ms=0 3950ms=0 4000ms=0 4050ms=0 4100ms=0 4150ms=0 4200ms=0 4250ms=0 4300ms=0 4350ms=0 4400ms=0 4450ms=0 4500ms=0 4550ms=0 4600ms=0 4650ms=0 4700ms=0 4750ms=0 4800ms=0 4850ms=0 4900ms=0 4950ms=0
     19 Caches:
     20 Current memory usage / total memory usage (bytes):
     21   TextureCache           896926 / 24576000
     22   Layers total          0 (numLayers = 0)
     23   RenderBufferCache           0 /  2048000
     24   GradientCache           32768 /  1048576
     25   PathCache                2696 /  4096000
     26   TessellationCache         816 /  1048576
     27   TextDropShadowCache     12224 /  2048000
     28   PatchCache                448 /   131072
     29   FontRenderer A8         10407 /   409600
     30     A8   texture 0        10407 /   409600
     31   FontRenderer RGBA           0 /        0
     32   FontRenderer total      10407 /   409600
     33 Other:
     34   FboCache                    0 /        0
     35 Total memory usage:
     36   1355478 bytes, 1.29 MB
     37 
     38 
     39 Pipeline=FrameBuilder
     40 Profile data in ms:
     41 
     42     com.android.launcher3/com.google.launcher.Launcher/android.view.V5ba3 (visibility=0)
     43     Draw    Prepare    Process    Execute
     44     1.96    0.41    5.82    2.01
     45     1.82    0.34    5.11    2.30
     46     3.35    0.34    4.76    2.06
     47     2.54    0.36    5.01    2.09
     48     2.00    0.36    5.73    2.06
     49     2.17    0.43    5.46    1.95
     50     1.92    0.35    5.19    2.38
     51     1.99    0.36    5.67    2.09
     52     2.03    0.41    5.37    2.08
     53     1.88    0.37    5.66    2.05
     54     2.16    0.36    5.14    2.09
     55     1.90    0.37    5.75    2.18
     56     1.99    0.42    5.56    2.04
     57     1.93    0.40    5.14    2.36
     58     1.97    0.36    5.47    2.13
     59     1.85    0.44    5.18    2.16
     60     1.99    0.35    5.29    2.12
     61     2.21    0.36    5.24    2.06
     62     1.91    0.36    5.42    2.16
     63     1.93    0.40    5.79    2.22
     64     1.96    0.36    5.38    2.59
     65     1.95    0.41    5.66    2.05
     66     2.01    0.36    5.23    2.05
     67     1.93    0.36    5.65    2.02
     68     2.09    0.38    5.38    2.04
     69     1.96    0.36    5.56    2.19
     70     2.08    0.39    5.36    2.13
     71     1.90    0.36    5.46    2.54
     72     1.98    0.35    5.63    2.11
     73     1.93    0.35    5.20    2.17
     74     1.91    0.36    5.74    2.06
     75     2.77    1.04    4.37    2.03
     76     1.95    0.36    5.39    2.31
     77     1.86    0.37    5.52    2.17
     78     1.95    0.37    5.23    2.34
     79     2.02    0.36    5.48    2.07
     80     1.95    0.36    5.39    2.07
     81     2.02    0.36    5.47    2.03
     82     3.77    0.34    4.66    2.04
     83     1.91    0.36    5.50    2.25
     84     2.02    0.46    5.55    2.06
     85     1.94    0.37    5.30    2.40
     86     2.01    0.36    5.57    2.11
     87     2.02    0.36    5.23    2.09
     88     2.03    0.35    5.40    2.04
     89     2.08    0.36    5.07    2.12
     90     1.91    0.35    5.19    2.36
     91     1.81    0.37    5.49    2.14
     92     2.00    0.36    5.02    2.42
     93     2.05    0.35    5.61    2.06
     94     1.97    0.36    5.29    2.12
     95     1.93    0.36    5.50    2.07
     96     2.07    0.37    5.42    2.11
     97     1.93    0.41    5.53    2.21
     98     3.68    0.36    4.67    1.93
     99     1.96    0.37    5.35    2.14
    100     2.00    0.36    5.68    2.01
    101     1.87    0.37    5.49    3.59
    102     1.95    0.36    5.68    2.11
    103     2.03    0.44    5.37    2.15
    104     2.01    0.36    5.25    2.56
    105     2.05    0.36    5.45    2.07
    106     2.03    0.35    5.22    2.35
    107     1.94    0.36    5.64    2.09
    108     1.92    0.36    5.12    2.04
    109     1.92    0.44    5.29    2.22
    110     2.13    0.37    5.38    2.12
    111     2.02    0.36    5.28    2.21
    112     2.10    0.37    5.94    1.96
    113     1.93    0.37    5.39    2.24
    114     1.99    0.35    5.64    2.09
    115     3.50    0.33    4.54    2.03
    116     1.97    0.37    5.57    2.17
    117     2.11    0.38    5.36    2.13
    118     1.95    0.36    5.11    2.29
    119     1.99    0.37    5.58    2.05
    120     3.52    0.33    4.73    2.52
    121     1.87    0.37    5.74    2.12
    122     1.93    0.41    5.20    2.19
    123     1.99    0.35    5.42    2.14
    124     2.43    0.97    4.51    2.09
    125     1.95    0.36    5.33    2.21
    126     2.14    0.37    5.70    2.14
    127     1.93    0.36    5.51    2.21
    128     1.97    0.46    5.51    2.05
    129     2.34    0.99    4.48    2.12
    130     1.99    0.36    5.38    2.12
    131     2.18    1.04    4.53    2.03
    132     1.96    0.36    5.33    2.37
    133     1.94    0.40    5.60    2.11
    134     1.93    0.36    5.27    2.30
    135     1.92    0.40    5.46    2.16
    136     2.03    0.36    5.17    2.31
    137     1.89    0.36    5.66    2.06
    138     2.18    0.39    5.31    2.03
    139     1.87    0.37    5.26    2.33
    140     1.92    0.36    5.95    2.04
    141     1.84    0.40    5.31    2.24
    142     2.04    0.36    5.50    2.14
    143     1.96    0.37    5.37    2.03
    144     2.02    0.36    5.73    2.02
    145     2.11    0.42    5.44    1.92
    146     1.89    0.35    5.11    2.39
    147     1.91    0.46    5.83    2.12
    148     1.99    0.36    4.95    2.17
    149     2.00    0.35    5.17    2.34
    150     2.17    0.41    5.42    2.02
    151     1.89    0.37    7.14    2.10
    152     1.97    0.41    6.70    2.05
    153     1.90    0.37    5.33    2.47
    154     1.86    0.42    5.90    2.07
    155     2.04    0.36    5.10    2.07
    156     1.96    0.37    6.45    2.35
    157     2.06    0.36    5.45    2.02
    158     2.03    0.36    5.48    2.15
    159     2.00    0.40    5.88    2.85
    160     1.95    0.46    5.59    2.52
    161     2.12    0.42    6.32    2.25
    162     1.96    0.35    5.28    2.42
    163     2.57    0.98    4.98    2.31
    164 
    165 View hierarchy:
    166 
    167   com.google.launcher3/com.google.launcher.Launcher/android.view.ViewRootImpl@a8f5ba3
    168   98 views, 122.13 kB of display lists
    169 
    170 
    171 Total ViewRootImpl: 1
    172 Total Views:        98
    173 Total DisplayList:  122.13 kB
    View Code

    把第44行至163行的 (Draw,Prepare,Process,Execute)值全部提取出来。

    下面讲解不使用工具和使用工具的操作步骤,大家一起评一评哪个效率更好些(当然了,如果是眯着眼睛都能知道正则表达式输出结果的非常牛逼的人可以忽略此):

    不使用工具:

    1 先是按照自己的思路大概将表达式写好,然后再执行一下代码查看结果是否是需要所要的;
    2 
    3 while 结果不对:
    4     继续调整正则表达式
    5     if 运行代码:
    6         结果是自己想要的同时返回结果
    7         break
    8     else:
    9         结果不对,从头执行

    对于掌握正则表达式一般般的人来说,反正就是反复调整表达式-->反复运行代码-->反复检查结果-->再又返回调整表达式,陷入了死循环了

    使用工具(RegexBuddy):

    先直接给出工具的界面,并在每一处需要手动处理的地方添加了备注,这个工具的好处就是在正则表达式区域输入匹配语句后,在右下 角区域能立即显示出匹配的效果,如果所要匹配的内容匹配上后,会按照颜色标注进行区分,所以这样就可以大胆的在编辑区域进行调整表达式,只要在右下角显示区域匹配成功后,即可将表达式拷出来放到 python 代码中运行。

  • 相关阅读:
    偶然闪退的排查
    ANTI-INFLAMMATORY FOODS
    健康餐
    PSORIASIS-7 THINGS TO AVOID
    eczema: improve or reverse your eczema
    VL10 or VL10A前台操作
    装修设计
    春运高速记录 1/15/2020
    rman 备份并异机恢复
    RMAN冷备份、一致性备份脚本
  • 原文地址:https://www.cnblogs.com/aziji/p/10031919.html
Copyright © 2011-2022 走看看