0%

AndroidSystemTrace

  • systrace 33.0.0之后的版本都没有了,下载
    1
    wget https://dl.google.com/android/repository/platform-tools_r33.0.0-darwin.zip

下载好之后直接覆盖就可以了
image.png
https://developer.android.com/topic/performance/tracing/command-line

1
2
python systrace.py -o mynewtrace.html sched freq idle am wm gfx view \
binder_driver hal dalvik camera input res memory
  • perfetto

https://developer.android.com/studio/command-line/perfetto

1
2
3
adb shell perfetto [ --time TIMESPEC ] [ --buffer SIZE ] [ --size SIZE ]
[ ATRACE_CAT | FTRACE_GROUP/FTRACE_NAME | FTRACE_GROUP/* ]...
--out FILE
  • 开发者模式中打开

https://developer.android.com/topic/performance/tracing/on-device

  • **atrace **

发现system/bin目录下有一个atrace
源码:/frameworks/native/cmds/atrace/atrace.cpp

  • android_process_data_agent.py

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    USER           PID  PPID     VSZ    RSS WCHAN  PC S NAME                        COMM                       
    root 1 0 60400 3384 SyS_epoll_wait 0 S init init
    root 2 0 0 0 kthreadd 0 S [kthreadd] 2
    root 3 2 0 0 rescuer_thread 0 I [rcu_gp] 3
    root 5 2 0 0 worker_thread 0 I [kworker/0:0H] 5
    root 7 2 0 0 rescuer_thread 0 I [mm_percpu_wq] 7
    root 8 2 0 0 smpboot_thread_fn 0 S [ksoftirqd/0] 8
    root 9 2 0 0 rcu_gp_kthread 0 I [rcu_preempt] 9
    root 10 2 0 0 rcu_gp_kthread 0 I [rcu_sched] 1
    root 11 2 0 0 rcu_gp_kthread 0 I [rcu_bh] 1
    root 12 2 0 0 rcu_nocb_kthread 0 S [rcuop/0] 1
  • android_cgroup_agent.py 先读取adb pull /proc/cgroups ,再依次根据文件中的属性读取/dev/cpuset/下的文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    #subsys_name	hierarchy	num_cgroups	enabled
    cpuset 4 7 1
    cpu 2 1 1
    cpuacct 3 714 1
    schedtune 6 6 1
    blkio 1 2 1
    memory 5 3 1
    freezer 0 1 1
    # cgroup task attachment
    /background (root=4) : 634 2729 3483 3490 3495 3496 3497 3498 3499 3500 3501 3502 3503 3531 3548 3679 3696 3725 3788 3793 3794 3798 3806 3826 3834 3836 3837 3850 3852 3857 3858 3863 3864 3865 3866 3867 3868 3869 3870 3877 3879 3894 3970 3983 4122 4128 4133 4134 4135 4136 4137 4138 4139 4140 4141 4153 4155 4156 4157 4159 4160 4162 4164 4165 4167 4168 4171 4173 4174 4177 4178 4179 4181 4187 4188 4189 4190 4191 4192 4196 4197 4198 4209 4211 4212 4213 4224 4231 4232 4233 4234 4235 4236 4237 4249 4250 4266 4270 4272 4273 4342 4392 4421 4441 4447 4448 4450 4464 4494 4495 4502 4508 4513 4515 4538 4543 4608 4877 5134 5146 5151 5152 5153 5154 5155 5157 5160 5161 5162 5165 5167 5168 5170 5172 5173 5175 5177 5181 5183 5184 5186 5188 5191 5192 5193 5194 5201 5202 5205 5206 5207 5208 5209 5213 5214 5215 5216 5217 5218 5219 5220 5231 5232 5233 5351 5352 5353 6036 7285 7288 7296 7300 7301 7302 7303 7304 7305 7306 7309 7310 7323 7324 7325 7326 7329 7330 7331 7339 7595 7690 7806 7808 7814 8491 8506 8513 8514 8518 8520 8521 8523 8524 8528 8530 8612 8835 8844 8845 8846 8849 8853 8856 8863 8865 8873 8887 8889 8896 8898 8907 8908 8909 8912 8926 8928 8930 8931 8932 8934 8938 8939 8940 8941 8945 8946 8947 8949 8950 8951 8952 8953 8954 8955 8956 8957 8985 9018 9019 9020 9021 9023 9062 9064 9066 9067 9072 9076 9085 9093 9142 9177 9202 9217 9244 9268 9273 9274 9276 9277 9288 9290 9292 9293 9295 9306 9310 9650 10045 10717 10718 10725 14316 14335 14365 14383 14388 14389 14390 14391 14392 14393 14399 14400 14422 14425 14426 14427 14431 14432 14434 14435 14443 14444 14447 14448 14450 14451 14478 14479 14480 14488 14519 14525 14530 14531 14532 14533 14535 14536 14537 14538 14539 14540 14541 14542 14546 14551 14552 14553 14554 14555 14556 14557 14558 14559 14564 14565 14568 14570 14576 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14593 14599 14600 14601 14602 14603 14604 14605 14606 14607 14611 14614 14615 14617 14622 14627 14631 14632 14638 14639 14661 14662 14669 14672 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14694 14695 14696 14697 14698 14700 14702 14703 14704 14705 14706 14708 14710 14711 14712 14713 14714 14722 14728 14734 14776 14781 14788 15043 15047 15052 15055 15056 15057 15058 15059 15060 15061 15062 15063 15065 15069 15071 15242 15243 15244 15245 15246 15247 15253 15256 15257 15258 15259 15260 15261 15262 15263 15264 15265 15266 15267 15268 15269 15270 15271 15272 15274 15276 15277 15278 15279 15280 15281 15282 15284 15286 15287 15288 15289 15290 15297 15304 15311 15312 15313 15320 15590 15596 15601 15602 15603 15604 15605 15606 15607 15608 15609 15611 15612 15622 15636 15637 15638 15639 15640 15645 15646 15647 15648 15654 15656 18530 18766 18769 18770 18772 18773 18774 18775 18776 18777 18778 18779 18837 18847 18866 19327 20009 20010 20016 20017 20018 20019 20020 20021 20022 20023 20024 20025 20026 20027 20028 20031 20040 20041 20042 20044 20045 20046 20047 21401 21637 21642 22218 22302 23445 23450 23456 23457 23458 23459 23460 23461 23462 23463 23464 23546 23547 23548 23629 23630 23632 23633 23634 23636 23637 23640 23641 23643 23646 23647 23648 23651 23652 23654 23655 23662 23664 23666 23670 23675 23676 23689 23701 23702 23703 23704 23705 23707 23709 23710 23711 23714 23715 23716 23719 23723 23729 23732 23733 23736 23742 23744 23749 23756 23761 23762 23765 23883 23889 23894 23895 23896 23897 23898 23899 23900 23901 23902 23906 23918 23919 23920 23936 23938 23939 23940 23941 23942 23943 23944 23949 23950 23953 23954 23957 23960 23961 23962 23965 23968 23973 23975 23976 23978 23979 23981 23982 23986 23988 23990 23994 24000 24005 24006 24007 24008 24009 24010 24011 24012 24015 24016 24019 24022 24023 24025 24028 24029 24030 24031 24034 24040 24041 24042 24050 24056 24057 24061 24064 24065 24066 24067 24068 24069 24070 24071 24072 24073 24075 24076 24077 24081 24083 24087 24092 24093 24096 24097 24098 24102 24103 24104 24106 24119 24120 24121 24122 24128 24131 24132 24136 24137 24138 24139 24140 24141 24142 24147 24148 24150 24151 24152 24153 24154 24155 24156 24157 24158 24159 24161 24162 24163 24164 24165 24168 24170 24171 24172 24173 24174 24175 24176 24177 24181 24182 24183 24184 24191 24194 24195 24196 24197 24198 24201 24204 24206 24207 24209 24210 24211 24213 24215 24218 24220 24221 24230 24231 24236 24237 24255 24262 24287 24302 24310 24316 24317 24323 24342 24429 24470 24471 24472 24473 24605 24622 24623 24625 24627 24628 24629 24630 24631 24632 24633 24637 24638 24640 24641 24642 24646 24647 24648 24649 24651 24652 24653 24655 24657 24658 24659 24660 24661 24663 24664 24665 24666 24668 24672 24680 24681 24686 24687 24688 24689 24690 24691 24692 24704 24705 24706 24707 24708 24709 24710 24711 24716 24726 24729 24730 24731 24732 24733 24734 24735 24738 24743 24754 24755 24756 24759 24771 24776 24779 24781 24786 24787 24788 24790 24791 24792 24806 24810 24821 24823 24828 24829 24831 24833 24836 24841 24844 24869 24876 24882 24889 24891 24892 24893 24894 24899 24915 24920 24927 24929 24932 24940 24949 24950 24954 24955 24957 24959 24963 24966 24967 24968 24969 24970 24975 24976 24978 24979 24980 24983 24986 24989 24996 24998 24999 25000 25001 25002 25005 25011 25018 25032 25034 25036 25046 25048 25049 25053 25054 25067 25073 25084 25086 25090 25093 25096 25100 25101 25103 25104 25119 25120 25124 25132 25135 25138 25143 25146 25148 25149 25151 25152 25175 25177 25181 25184 25188 25194 25201 25202 25212 25218 25223 25224 25225 25226 25227 25228 25229 25231 25232 25233 25242 25243 25244 25245 25247 25248 25249 25250 25255 25257 25281 25286 25292 25298 25299 25300 25304 25308 25310 25311 25312 25313 25314 25315 25316 25319 25320 25323 25325 25340 25351 25353 25366 25407 25432 25434 25435 25440 25441 25442 25443 25444 25447 25448 25478 25479 25499 25500 25599 25942 25943 26153 26172 27633 27841 27879 27911 27937 28330 28337 28342 28343 28344 28345 28346 28347 28348 28350 28368 28445 29650 30012 30018 30024 30025 30026 30027 30028 30029 30030 30031 30032 30042 30069 30146 30164 30407 31433 32714
    /camera-daemon (root=4) : 799 934 1186 1189 1194 1210 1211 1226 1227 1228 1229 1355 1356 1357 1358 1359 1360 1526 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1795 1796 2127 3168 17448
    /foreground (root=4) : 581 600 601 602 658 738 739 758 794 803 807 808 809 827 829 831 832 833 848 849 851 853 863 864 876 936 941 942 943 946 948 952 958 966 989 990 1030 1164 1166 1173 1180 1181 1195 1196 1199 1204 1205 1207 1208 1209 1219 1220 1230 1266 1276 1277 1278 1363 1404 1412 1413 1426 1427 1431 1442 1443 1452 1453 1457 1458 1462 1463 1483 1580 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1680 1681 1683 1684 1685 1689 1692 1693 1694 1695 1696 1699 1700 1701 1702 1703 1704 1705 1706 1784 1785 1786 1787 1792 1793 1794 1797 1799 1800 1804 1805 1806 1807 1808 1809 1811 1812 1813 1815 1817 1821 1823 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1977 1979 2000 2001 2002 2003 2005 2007 2008 2009 2035 2049 2055 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2085 2091 2092 2093 2094 2100 2106 2107 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2139 2140 2141 2142 2148 2153 2154 2155 2156 2157 2158 2159 2161 2162 2167 2169 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2185 2186 2187 2213 2214 2216 2223 2224 2226 2229 2231 2247 2258 2276 2279 2287 2289 2308 2311 2312 2318 2335 2338 2341 2345 2351 2352 2354 2356 2366 2367 2368 2369 2389 2390 2391 2393 2394 2395 2396 2397 2398 2400 2401 2402 2403 2404 2405 2406 2504 2505 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2547 2554 2555 2556 2557 2559 2725 2727 2732 3058 3083 3092 3097 3103 3108 3109 3110 3111 3112 3113 3114 3117 3118 3127 3128 3129 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3149 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3176 3178 3207 3218 3231 3270 3282 3307 3351 3367 3375 3377 3407 3416 3417 3435 3436 3441 3466 3473 3474 3516 3525 3573 3574 3575 3576 3577 3669 3902 4355 4356 4357 4360 4365 4366 4367 4368 4372 4376 4377 4385 4386 4387 5135 5140 5143 5144 5145 5356 5358 5359 5361 5481 5482 5548 5552 5914 5993 6005 6013 6067 6440 7286 7287 7291 7292 7297 7361 7540 7542 7544 7565 7728 7729 8089 8201 8207 8212 8213 8214 8215 8216 8217 8218 8225 8231 8244 8272 8295 8301 8305 8307 8314 8315 8316 8317 8318 8319 8321 8334 8335 8336 8342 8347 8348 8349 8350 8352 8353 8354 8355 8361 8372 8378 8385 8388 8390 8393 8395 8400 8401 8407 8412 8414 8415 8416 8417 8418 8419 8421 8424 8427 8435 8443 8444 8445 8446 8447 8448 8451 8453 8457 8458 8459 8462 8463 8465 8473 8474 8475 8476 8477 8478 8483 8484 8485 8488 8489 8492 8494 8495 8496 8497 8498 8499 8500 8501 8510 8516 8517 8519 8525 8526 8527 8533 8534 8535 8536 8537 8539 8540 8542 8543 8544 8545 8546 8547 8550 8551 8552 8558 8563 8566 8572 8574 8576 8577 8578 8580 8582 8584 8602 8604 8605 8606 8608 8609 8611 8614 8615 8618 8620 8622 8626 8629 8634 8635 8638 8640 8642 8648 8654 8655 8685 8691 8698 8708 8709 8716 8733 8734 8735 8736 8738 8744 8745 8746 8756 8762 8763 8764 8766 8806 8807 8808 8816 8819 8821 8825 8826 8842 8850 8866 8867 8878 8879 8880 8886 8891 8892 8894 8899 8904 8906 8910 8911 8920 8971 8972 8986 8987 8988 8989 8991 8992 8993 8998 9001 9002 9003 9006 9007 9022 9024 9025 9026 9037 9040 9041 9047 9049 9073 9074 9081 9082 9088 9099 9100 9115 9116 9117 9118 9119 9120 9122 9123 9126 9127 9128 9130 9132 9133 9134 9135 9136 9138 9140 9144 9155 9159 9169 9171 9183 9184 9191 9192 9194 9267 9417 9457 9462 9468 9469 9470 9471 9472 9473 9474 9475 9476 9495 9506 9508 9509 9510 9517 9523 9530 9531 9532 9533 9534 9535 9536 9538 9539 9540 9547 9548 9550 9552 9553 9554 9555 9556 9557 9560 9565 9566 9567 9568 9569 9570 9571 9572 9576 9577 9597 9598 9600 9602 9603 9604 9606 9610 9611 9612 9613 9614 9615 9627 9628 9630 9658 9673 9746 9748 9749 9788 9822 9862 9863 9864 9873 9875 9876 10540 10663 10689 10690 10813 11016 11017 11376 11529 12321 12409 12573 12583 12584 12590 12591 12607 12772 13169 13170 13334 13774 14098 14100 14185 14186 14187 16514 18118 19069 19070 21117 21124 21288 21464 21477 21479 22313 22534 22937 22939 24962 25029 25230 25685 26500 27980 28220 28224 28323 29231 29232 29443 32073 32074
    /restricted (root=4) : 1980 1986 1991 1992 1993 1994 1995 1996 1997 1998 1999 2081 2227 2234 2241 2246 2249 2250 2251 2252 2253 2254 2255 2256 2259 2263 2271 2272 2280 2288 2291 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2310 2313 2317 2328 2330 2339 2340 2342 2343 2344 2346 2347 2349 2350 2353 2355 2358 2392 2414 2420 2434 2435 2445 2447 2448 2449 2450 2507 2513 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2755 3036 3048 3049 3166 3190 3232 3236 3248 3253 3255 3256 3257 3258 3259 3260 3261 3263 3288 3294 3296 3301 3309 3311 3312 3313 3314 3315 3316 3318 3346 3353 3360 3365 3366 3369 3370 3371 3372 3373 3374 3376 3379 3405 3442 3479 3480 3481 3871 3986 3989 4001 4002 4003 4005 4007 4008 4010 4022 4023 4036 4038 4039 4042 4043 4044 4068 4094 4095 4098 4120 4151 4152 4229 4241 4242 4243 4245 4248 4254 4295 4369 4370 4375 4380 4389 4396 4401 4402 4403 4404 4405 4406 4407 4412 4422 4425 4431 4432 4433 4434 4436 4438 4457 4528 4596 4611 4651 4721 4747 4748 4751 4761 4762 4764 4772 4803 4804 4809 4811 4825 4831 4847 4848 4850 4851 4855 4861 4863 4864 4872 4876 4887 4901 4910 4913 4914 4919 4922 4925 4931 4933 4935 4936 4937 4938 4939 4954 4959 4962 4975 4981 5003 5011 5014 5015 5048 5049 5068 5072 5073 5123 5124 5136 5137 5138 5139 5141 5142 5156 5158 5159 5169 5197 5224 5238 5256 5272 5273 5274 5275 5276 5277 5278 5279 5282 5307 5345 5381 5382 5503 5504 5505 5506 5565 5570 5573 5590 5604 5612 5617 5622 5637 5895 5995 5996 6003 6722 7295 7298 7518 8890 9102 9150 10708 10820 10845 10883 11611 11615 11618 11620 11621 11622 11623 11632 11636 11706 12542 13829 13852 13854 14088 14089 14091 14184 16553 16726 17340 20226 21082 22217 23076 23800 23879 24223 24479 25598 25608 25645 25646 25868 25869 29935 31497 31519 31527 31531 32015
    /system-background (root=4) : 565 566 567 568 575 576 577 578 590 591 610 657 659 660 661 662 663 664 665 666 667 668 826 839 868 869 870 873 879 904 905 907 909 912 913 949 950 954 963 964 965 979 1057 1083 1084 1087 1088 1089 1090 1161 1163 1184 1333 1334 1335 1336 1347 1691 1741 1790 1791 2716 2717 5354 15613 15614 15615 15616 15617 15619 15620 15621 15623 15625 15627 15628 15629 15630 15631 15632 15633 15634 15635 16007 18690 29050 31096
    /top-app (root=4) : 1686 1687 1688 2130

  • atrace_agent.py

    • 正则修复
    • 解压缩
    • 获取所有proc 下id号
  • 装入html模版 output_generator.py

最重要的就是atrace
systrace 就是调用的atrace
image.png
image.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
usage: atrace [options] [categories...]
options include:
-a appname enable app-level tracing for a comma separated list of cmdlines; * is a wildcard matching any process
-b N use a trace buffer size of N KB
-c trace into a circular buffer
-f filename use the categories written in a file as space-separated
values in a line
-k fname,... trace the listed kernel functions
-n ignore signals
-s N sleep for N seconds before tracing [default 0]
-t N trace for N seconds [default 5]
-z compress the trace dump
--async_start start circular trace and return immediately
--async_dump dump the current contents of circular trace buffer
--async_stop stop tracing and dump the current contents of circular
trace buffer
--stream stream trace to stdout as it enters the trace buffer
Note: this can take significant CPU time, and is best
used for measuring things that are not affected by
CPU performance, like pagecache usage.
--list_categories
list the available tracing categories
-o filename write the trace to the specified file instead
of stdout.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  	 gfx - Graphics
input - Input
view - View System
webview - WebView
wm - Window Manager
am - Activity Manager
sm - Sync Manager
audio - Audio
video - Video
camera - Camera
hal - Hardware Modules
res - Resource Loading
dalvik - Dalvik VM
rs - RenderScript
bionic - Bionic C Library
power - Power Management
pm - Package Manager
ss - System Server
database - Database
network - Network
adb - ADB
vibrator - Vibrator
aidl - AIDL calls
nnapi - NNAPI
rro - Runtime Resource Overlay
pdx - PDX services
sched - CPU Scheduling
irq - IRQ Events
i2c - I2C Events
freq - CPU Frequency
idle - CPU Idle
disk - Disk I/O
sync - Synchronization
workq - Kernel Workqueues
memreclaim - Kernel Memory Reclaim
regulators - Voltage and Current Regulators
binder_driver - Binder Kernel driver
binder_lock - Binder global lock trace
pagecache - Page cache
memory - Memory
freq - CPU Frequency and System Clock (HAL)
gfx - Graphics (HAL)
ion - ION Allocation (HAL)
sched - CPU Scheduling and Trustzone (HAL)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
按键操作       作用
w 放大,[+shift]速度更快
s 缩小,[+shift]速度更快
a 左移,[+shift]速度更快
d 右移,[+shift]速度更快

f 放大当前选定区域
m 标记当前选定区域
v 高亮VSync
g 切换是否显示60hz的网格线
0 恢复trace到初始态,这里是数字0而非字母o

h 切换是否显示详情
/ 搜索关键字
enter      显示搜索结果,可通过← →定位搜索结果
` 显示/隐藏脚本控制台
? 显示帮助功能