Commit Graph

46 Commits

Author SHA1 Message Date
junyulai
fd661f5db8 [SP24] Rename functions that add Entry unconditionally
Currently, in NetworkStats, there are many methods to manipulate
the records. However, some methods are similar and ambiguous,
such as addEntry, addValues, setValues, addIfaceValues,
combineValues and combineAllValues.

Thus, properly grouping and renaming methods are necessary.
In this change, for methods that add one record unconditionally,
name them insertEntry.
  setIfaceValues -> insertEntry
  addEntry -> insertEntry

Test: atest FrameworksNetTests ImsPhoneCallTrackerTest TetheringTests
Test: m doc-comment-check-docs
Bug: 148895143
Change-Id: I801ddc49e283a254b9586700c9b597c0adb0d459
2020-03-16 14:27:45 +08:00
junyulai
d27a1725e8 [SP01] Add NetworkStats to system API
In order to let external module report their network stats,
expose necessary APIs to construct NetworkStats object.

Test: atest FrameworksNetTests CtsUsageStatsTestCases
Test: m doc-comment-check-docs
Bug: 130855321
Change-Id: Id3ec8aaff3df67948c25eac2319a74cf33a27979
2020-01-09 03:11:22 +00:00
Neil Fuller
7bb9a1e67f Merge "Add a basic benchmark for android.text.format.Time" am: 9038c7231d
am: e25cc6b0e7

Change-Id: I26854156a2f0451622bd70d9dba93b9bee669298
2019-06-18 07:25:00 -07:00
Neil Fuller
8dcdc1dd43 Add a basic benchmark for android.text.format.Time
Add a benchmark to demonstrate performance tradeoffs between
alternatives for android.text.format.Time. This can be extended later
as needed for other Time usecases.

Executable with:
vogar --mode app_process --benchmark core/tests/benchmarks/src/android/text/format/AndroidTimeVsOthersBenchmark.java

Results from an aosp/master taimen:

    Experiment selection:
      Benchmark Methods:   [toMillis_androidIucUtil, toMillis_androidTime, toMillis_javaTime, toMillis_javaUtil]
      Instruments:   [runtime]
      User parameters:   {}
      Virtual machines:  [app_process]
      Selection type:    Full cartesian product
    This selection yields 4 experiments.
    Trial Report (1 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_androidIucUtil, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=6341.29, 1st qu.=6341.29, median=6341.29, mean=6341.29, 3rd qu.=6341.29, max=6341.29
    Trial Report (2 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_androidTime, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=12310.21, 1st qu.=12310.21, median=12310.21, mean=12310.21, 3rd qu.=12310.21, max=12310.21
    Trial Report (3 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_javaTime, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=1029.36, 1st qu.=1029.36, median=1029.36, mean=1029.36, 3rd qu.=1029.36, max=1029.36
    Trial Report (4 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_javaUtil, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=10142.66, 1st qu.=10142.66, median=10142.66, mean=10142.66, 3rd qu.=10142.66, max=10142.66
    Collected 4 measurements from:
      1 instrument(s)
      1 virtual machine(s)
      4 benchmark(s)

Note: When not cycling the time zone ID the results are different, but
java.time still comes out ahead.

    Trial Report (1 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_androidIucUtil, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=6583.57, 1st qu.=6583.57, median=6583.57, mean=6583.57, 3rd qu.=6583.57, max=6583.57
    Trial Report (2 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_androidTime, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=4653.01, 1st qu.=4653.01, median=4653.01, mean=4653.01, 3rd qu.=4653.01, max=4653.01
    Trial Report (3 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_javaTime, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=1095.20, 1st qu.=1095.20, median=1095.20, mean=1095.20, 3rd qu.=1095.20, max=1095.20
    Trial Report (4 of 4):
      Experiment {instrument=runtime, benchmarkMethod=toMillis_javaUtil, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=2825.56, 1st qu.=2825.56, median=2825.56, mean=2825.56, 3rd qu.=2825.56, max=2825.56

Bug: 16550209
Test: see above
Change-Id: I8f1dffb083db00c2ea4cef40fd5cc2f4acab7a89
2019-06-17 19:04:37 +01:00
Varun Anand
2471441b2d Merge changes Ieb8645ac,I6466ec14,I87deb82b,I995b108e,Ib6521459 am: f4c10e8bc2
am: 48f59a0fdf

Change-Id: I960e94b03b29282ae2b03f78a19ed2692bd88e05
2019-06-17 10:33:53 -07:00
Benedict Wong
a84d9fa572 Revert "Revert "Take all VPN underlying networks into account when migrating traffic for""
This reverts commit d8220c2050.

Reason for revert: Fix available for deadlocks.

Bug: 134244752
Change-Id: Ib65214598837289bd39dbf040b56ab7835f893ba
2019-06-13 15:36:27 -07:00
Varun Anand
d8220c2050 Revert "Take all VPN underlying networks into account when migrating traffic for"
This reverts commit 95aa6d446f.

Reason for revert: This change has been implicated in 4-way deadlocks as seen in b/134244752.

Bug: 134244752
Change-Id: I2f1839d7776a613ca571af8a542755ddc5fc8760
Merged-In: Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9
2019-06-10 16:00:48 -07:00
Benedict Wong
f0904ebfc0 Revert "Take all VPN underlying networks into account when migrating traffic for"
am: ac06c1022d

Change-Id: Ie9e830962e702c5e66faa7239e6c5037ed3d791d
2019-06-07 02:33:33 -07:00
Benedict Wong
ac06c1022d Revert "Take all VPN underlying networks into account when migrating traffic for"
This reverts commit 917327b193.

Reason for revert: This change has been implicated in 4-way deadlocks as seen in b/134244752.

Bug: 134244752
Change-Id: Ibdaad3a4cbf0d8ef1ed53cfab1e454b9b878bae9
2019-06-07 09:18:01 +00:00
Varun Anand
ebf59f07b1 Merge changes from topic "vpn_data_accounting" into qt-dev
am: b33d2ca2e3

Change-Id: I234eb2b20f47bde94b4aba89867e9d1c7e9ee7d5
2019-05-29 09:44:04 -07:00
Varun Anand
917327b193 Take all VPN underlying networks into account when migrating traffic for
VPN uid.

(cherry picked from commit 95aa6d446f)

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests
Test: Manually verified on device that stats from VPN UID are moved
      appropriately based on its declared underlying network set.
Test: vogar --mode app_process --benchmark NetworkStatsBenchmark.java

Change-Id: I7f368c5970b2dcb969fe0daf5ef44edb1f51d09d
2019-05-29 18:15:17 +09:00
Treehugger Robot
48294e098f Merge "Move NetworkStatsFactory into service directory" 2019-04-05 19:27:22 +00:00
Sasha Smundak
7d6c615c82 Merge "Convert core/tests/**/Android.mk file to Android.bp" am: d0fc8c9d5b
am: 37c0949bf5

Change-Id: Ia4e91ee9eb77fbd5d9063ce28506fe60b86aec36
2019-04-05 03:06:44 -07:00
Treehugger Robot
d0fc8c9d5b Merge "Convert core/tests/**/Android.mk file to Android.bp" 2019-04-04 19:27:20 +00:00
Chenbo Feng
061cec7755 Move NetworkStatsFactory into service directory
In order to notify netd to swap eBPF maps before pulling the
networkStats from eBPF maps, NetworkStatsFactory need to use the
NetdServices to issue binder calls. So it need to be moved from
framework/base/core to framework/base/service since object in
framework/base/core cannot get any system services. This change is also
necessary for setting up a lock inside NetworkStatsFactory to prevent
racing between two netstats caller since the lock need to be hold before
netd trigger the map swap.

Also fix the compile problem caused by moving the NetworkStatsFactory
and the related tests. Rename the packages and the jni functions to a
more proper name.

Bug: 124764595
Bug: 128900919
Test: NetworkStatsFactoryTest
      android.app.usage.cts.NetworkUsageStatsTest
      android.net.cts.TrafficStatsTest

Change-Id: Ifcfe4df81caf8ede2e4e66a76552cb3200378fa8
2019-04-03 14:28:41 -07:00
Chenbo Feng
f2f1f27098 Move NetworkStatsFactory into service directory
In order to notify netd to swap eBPF maps before pulling the
networkStats from eBPF maps, NetworkStatsFactory need to use the
NetdServices to issue binder calls. So it need to be moved from
framework/base/core to framework/base/service since object in
framework/base/core cannot get any system services. This change is also
necessary for setting up a lock inside NetworkStatsFactory to prevent
racing between two netstats caller since the lock need to be hold before
netd trigger the map swap.

Also fix the compile problem caused by moving the NetworkStatsFactory
and the related tests. Rename the packages and the jni functions to a
more proper name.

Bug: 124764595
Bug: 128900919
Test: NetworkStatsFactoryTest
      android.app.usage.cts.NetworkUsageStatsTest
      android.net.cts.TrafficStatsTest

Merged-In: Ifcfe4df81caf8ede2e4e66a76552cb3200378fa8
Change-Id: Ifcfe4df81caf8ede2e4e66a76552cb3200378fa8
2019-04-03 11:33:40 -07:00
Varun Anand
95aa6d446f Take all VPN underlying networks into account when migrating traffic for
VPN uid.

Bug: 113122541
Bug: 120145746
Test: atest FrameworksNetTests
Test: Manually verified on device that stats from VPN UID are moved
      appropriately based on its declared underlying network set.
Test: vogar --mode app_process --benchmark NetworkStatsBenchmark.java

Change-Id: I9d8d0cc58d18002c1c96f8ddff780ef8dc452d21
2019-03-28 10:31:49 -07:00
Sasha Smundak
599404d2ed Convert core/tests/**/Android.mk file to Android.bp
See build/soong/README.md for more information.

Bug: 122332340
Test: treehugger
Change-Id: I368327d0f3b4bd3068e10c8750ece45e227531cf
2019-03-27 20:11:41 -07:00
Aurimas Liutikas
3f26befd10 Add a basic ResourcePerfTest.
Moving ResourcesBenchmark.java to the proper android.perftests infrastructure.

Test: ran the benchmark locally.
Change-Id: Ia981274e1e3c167a2a8900498fc40b7a03508a74
2018-08-03 14:37:27 -07:00
Jeff Sharkey
5aae0c9df7 Utility methods useful for working with files.
Part of getting DocumentsUI ready for building against public API.

Test: builds
Bug: 110959821
Change-Id: I7cc0acd5ac3bcc89790cb49f34291ae523e44019
2018-07-11 14:41:24 -06:00
Jeff Sharkey
3fc37deca8 Benchmarks for streams.
We've been advocating as little usage of streams as possible inside
the system_server, and this is a benchmark showing the costs of using
streams compared to rolling manual logic.

Results on a taimen show that direct route is 2.2x faster (!).

    Trial Report (1 of 2):
      Experiment {instrument=runtime, benchmarkMethod=timeDirect, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=47234.28, 1st qu.=47234.28, median=47234.28, mean=47234.28, 3rd qu.=47234.28, max=47234.28
    Trial Report (2 of 2):
      Experiment {instrument=runtime, benchmarkMethod=timeStreams, vm=app_process, parameters={}}
      Results:
        runtime(ns): min=105660.39, 1st qu.=105660.39, median=105660.39, mean=105660.39, 3rd qu.=105660.39, max=105660.39

Bug: 77808546
Test: vogar --mode app_process --benchmark frameworks/base/core/tests/benchmarks/src/android/util/StreamsBenchmark.java
Change-Id: Iac43a75970eee2c91593316a1b5a45d2c96c476b
2018-04-12 10:43:22 -06:00
Jeff Sharkey
45c97df89d Move more folks to FileUtils.copy().
Also extend API to accept a "count" argument of exactly how many
bytes to copy, and return the actual number of copied bytes.

Improve docs.

Test: bit FrameworksCoreTests:android.os.FileUtilsTest
Test: vogar --mode app_process --benchmark frameworks/base/core/tests/benchmarks/src/android/os/FileUtilsBenchmark.java
Bug: 71932978
Change-Id: I8d255e4f97462838c02a8ecb6d2d221188c4eff0
2018-02-01 16:01:55 -07:00
Jeff Sharkey
b18f899241 Use sendfile() and splice() to speed up copying.
There are several places across the OS where Java code is simply
copying data between two points, which requires bringing that data
out into userspace before going back into the kernel.  (That's pretty
lame.)  The patches for the recent Meltdown/Spectre security issues
have made this overhead even worse, so it's finally time to move this
copying directly into the kernel.

This change adds a couple new FileUtils.copy() methods which inspect
the given streams/FDs, and attempt to do as much optimization as
possible before falling back to a slower userspace-based copy.

Benchmarks are showing typical improvements of 44% for 32KB files,
50% for 32MB files, and 35% for 32MB pipes.

Plenty of tests are included, and there's a simple kill-switch that
can be used to enable/disable the feature if it starts causing any
trouble.  (A future CL will enable the optimizations.)

Test: bit FrameworksCoreTests:android.os.FileUtilsTest
Test: vogar --mode app_process --benchmark frameworks/base/core/tests/benchmarks/src/android/os/FileUtilsBenchmark.java
Bug: 71932978
Change-Id: I52518d529da5d961610998b9f61399064d8025cd
2018-01-31 21:47:22 -07:00
Chenbo Feng
828f1b45fb Add bpf support for NetworkStatsFactory
Add the native method used to read the detail information of network
stats from bpf maps. The native method of NetworkStatsFactory should
choose the correct implementation to get the stats detail depending on
the kernel version. Currently the bpf result is printed as a reference
and the actual behavior of NetworkStatsFactory should not change.

Test: NetworkStatsFactory related cts test should not fail.
Bug: 30950746
Change-Id: I4715a23559b5b2306bd556cea0431f0ed172a993
2018-01-23 00:34:53 -08:00
Igor Murashkin
12ffdd86e4 Merge "app_process: Forward -cp/-classpath to ART." am: 4a4a8f1555 am: d0d99d8a3d am: 4aa38633fe
am: 7ab062fd66

Change-Id: I6d093ad8aa1b04d75e6968ebcb9c0fb7376f0811
2016-10-28 18:05:46 +00:00
Igor Murashkin
4f66cb3f53 app_process: Forward -cp/-classpath to ART.
* No new functionality was added, this was already possible via
  -Djava.class.path=classpath
* However, this makes it a bit more compatible with other tools
  that use -cp to invoke the main class.
* Also update the benchmarks README for correct up-to-date vogar
  instructions.

Test: vogar --mode app_process --benchmark frameworks/base/core/tests/benchmarks/src/android/os/ParcelBenchmark.java
Bug: 31807538
Change-Id: Idb04600fed3dd955437ccac832617dcfd1b52b63
2016-10-03 11:08:42 -07:00
John Reck
71207b5a11 Switch Parcel to FastNative
Also fixes ParcelBenchmark to have bounded
memory usage to avoid OOM'ing during runs

Test: refactor, no behavior change

ParcelBenchmark results from bullhead
Before:
      timeReadByte 74.43ns
      timeReadInt 74.49ns
      timeReadLong 74.13ns
      timeWriteByte 81.81ns
      timeWriteInt 82.09ns
      timeWriteLong 81.84ns

After:
      timeReadByte 47.08ns
      timeReadInt 48.38ns
      timeReadLong 48.16ns
      timeWriteByte 55.90ns
      timeWriteInt 55.85ns
      timeWriteLong 56.58ns

Change-Id: I61b823d1d2beb86e00c196abd4dce65efa8fa7f0
2016-09-30 11:19:10 -07:00
Narayan Kamath
a09b4d2a61 Remove unnecessary allocation+unboxing of objects.
Transforming String->int can be done with 0 allocations
using Integer.parseInt.

bug: 28078871
Change-Id: I8d9f322d7154728849dde61ef282046032858d60
2016-04-18 09:55:59 +01:00
Siyamed Sinir
545c3cf95f Benchmarks for Linkify
Add benchmarks for Linkify and URL regular expressions.

Bug: 27921706
Change-Id: I61dcd090bdf877f2df77e898c8a0f441de1dc45a
2016-03-30 17:02:02 -07:00
Siyamed Sinir
fa05ba0b0d Sort the result of SpannableStringBuilder.getSpans
SpannableStringBuilder used to return the result of getSpans in the
order of start indices because of the interval tree it uses. However,
style spans has to be applied in the order of insertion to get
predictable results. Sorted the results of getSpans ordered first by
priority flag and then by insertion time. Moreover improved the
performance of SpannableStringInternal copy constructor.

Bug: 26240132
Change-Id: I0b0fa7bb30a3bd9ca37dedca66d8993718586027
2016-01-20 16:27:39 -08:00
Paul Duffin
cde2287208 Merge "Remove framework from LOCAL_JAVA_LIBRARIES" am: e252149ab9 am: ec9081a004
am: e94e7dd181

* commit 'e94e7dd181fb1857bf7aa3b807b64d9bb231edc6':
  Remove framework from LOCAL_JAVA_LIBRARIES
2015-12-08 14:22:55 +00:00
Paul Duffin
b12a3fca7e Remove framework from LOCAL_JAVA_LIBRARIES
After previous change removed LOCAL_NO_STANDARD_LIBRARIES:=true
it is no longer necessary to explicitly add framework to
LOCAL_JAVA_LIBRARIES as it is added automatically by the build.

Change-Id: I68bf700375e34a10302f76d7463110755b815f85
2015-12-08 13:59:36 +00:00
Andreas Gampe
32f4043ac3 Follow-up to Switch to the latest version of Caliper
Remove LOCAL_NO_STANDARD_LIBRARIES.

(cherry pick from commit c9d6a91cd5)

Bug: 24848946
Change-Id: I19feea042c9b4823d4979f4d951476792600edbc
2015-12-08 13:58:08 +00:00
Andreas Gampe
c373adb84d Merge "Follow-up to Switch to the latest version of Caliper" 2015-12-08 02:30:21 +00:00
Andreas Gampe
0fe2de958a Follow-up to Switch to the latest version of Caliper
Translate ResourcesBenchmark to work with the new version of Caliper.

Bug: 24848946
Change-Id: If4a4e5da5cd14da83d093a418147ad6d12c170cc
2015-12-07 18:25:10 -08:00
Andreas Gampe
c9d6a91cd5 Follow-up to Switch to the latest version of Caliper
Remove LOCAL_NO_STANDARD_LIBRARIES.

Bug: 24848946
Change-Id: I19feea042c9b4823d4979f4d951476792600edbc
2015-12-07 18:24:08 -08:00
Paul Duffin
6a75685258 Merge "Switch to the latest version of Caliper" am: ae119af517 am: 5e2d958157
am: 2a56ed70b1

* commit '2a56ed70b1e40039a532e4060074d62062713fcd':
  Switch to the latest version of Caliper
2015-12-07 23:58:26 +00:00
Paul Duffin
76a6cec97f Switch to the latest version of Caliper
Added an Android.mk file to core/tests/benchmarks to build the
benchmarks against caliper-api-target to ensure that they build
correctly. Changed the implementations to work with the new
version of Caliper.

Bug: 24848946
Change-Id: Ib28026816dbc5c1d54f65974f4a1abfee299c43f
2015-12-07 12:29:45 +00:00
Jeff Sharkey
46cfd93aa2 Let's sprinkle some FastJNI into Resources.
Before:

               benchmark   us linear runtime
                GetColor 14.9 ===========
              GetInteger 19.9 ===============
    GetLayoutAndTraverse 38.4 =============================
               GetString 38.5 ==============================

After:

               benchmark   us linear runtime
                GetColor 13.9 ==========
              GetInteger 18.8 ==============
    GetLayoutAndTraverse 38.1 =============================
               GetString 38.2 ==============================

Change-Id: I8c20e14182d2645bc62a0e7fc6345e298b11933c
2015-11-02 19:49:11 -08:00
Wenchao Tong
7ae35a0242 Create a Benchmark test for NetworkStats.
Bug: 19536273
Change-Id: I438ed3affa799612566b04e324e43bc5ea74079f
2015-03-23 16:34:03 -07:00
Nick Kralevich
7b3db39aa4 Replacing FloatMath native implementation with calls to Math
On modern versions of Android running in AOT mode
FloatMath is slower than Math. Calls to Math.sqrt(),
etc. are replaced by intrinsics which can be as small
as a single CPU opcode.

When running in interpreted mode the new
implementation is unfortunately slower, but I'm
judging this acceptable and likely to be improved
over time. This change saves a small amount of native
code.

Example timings:

Mako AOSP AOT:

Method: Original / New / Direct call to Math
ceil: 596ns / 146.ns / 111ns
sqrt: 694ns / 56ns / 25ns

Mako AOSP interpreted:

Method: Original / New / Direct call to Math
ceil: 1900ns / 2307ns / 1485ns
sqrt: 1998ns / 2603ns / 1788ns

Other calls Mako AOT:

Method: Original / New
cos: 635ns / 270ns
exp: 566ns / 324ns
floor: 604ns / 150ns
hypot: 631ns / 232ns
pow: 936ns / 643ns
sin: 641ns / 299ns

The advice to use Math directly, in preference to
FloatMath, is still good. FloatMath will be deprecated
separately.

Bug: https://code.google.com/p/android/issues/detail?id=36199
Change-Id: If07fcbd78543d13bc6d75f9743f999860e8d58d7
2014-10-20 09:24:11 +01:00
Jeff Sharkey
a2934d5ff0 Cache AndroidBlockGuardPolicy to avoid allocation.
Every incoming Binder call ends up triggering a BlockGuardPolicy
update, which would thrash between new AndroidBlockGuardPolicy
instances and BlockGuard.LAX_POLICY, causing GC churn.

This change avoids the extra allocations by recycling a single
AndroidBlockGuardPolicy in a ThreadLocal.  Worst-case thrashing case
is now 10% faster; from 7.46us to 6.65us.

Bug: 9424568
Change-Id: I9c3b1c097a2aecc9b1f109a824cf3ea319fb3393
2013-06-14 16:15:31 -07:00
Jeff Sharkey
8fa9bb5210 Benchmarks for IndentingPrintWriter.
Current timings on a mako listed below, which show minimal overhead
compared to writing directly. The increased code readability and
automatic indenting is worth the overhead.

Also worth noting is that writing concatenated strings is
substantially faster than printing components separately.

           benchmark      us linear runtime
       ComplexDirect 10712.7 =========================
    ComplexIndenting 12623.7 ==============================
       PairIndenting    45.8 =
             PairRaw    82.1 =
        SimpleDirect   282.2 =
     SimpleIndenting   294.4 =

Change-Id: I7c38690c14b017fa46248ebb0be69f6beff03371
2013-03-26 20:16:44 -07:00
Jeff Sharkey
9a2c2a6da9 Parse network stats using native code.
Switch to parsing detailed network stats with native code, which
is 71% faster than ProcFileReader.

Change-Id: I2525aaee74d227ce187ba3a74dd08a2b06514deb
2013-02-13 17:40:49 -08:00
Jeff Sharkey
92be93a94e Improve TrafficStats UID APIs.
Deprecate transport layer statistics, leaving only the summarized
network layer statistics.

Improve documentation to be clear about layers where measurements
occur, and their behavior since boot.  Under the hood, move to using
xt_qtaguid UID statistics.

Bug: 6818637, 7013662
Change-Id: I9f26992e5fcdebd88c671e5765bd91229e7b0016
2013-02-07 13:59:26 -08:00
Jeff Sharkey
a197e37f7f Caliper benchmarks for Parcel.
Bug: 6111276
Change-Id: I4b89e4c14d2dc20e71bbaed78f285e6d539a1f0f
2012-03-06 17:21:01 -08:00