Mathieu Chartier | a80e2af | 2016-06-08 16:29:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mathieu Chartier | f7d2f9f | 2016-06-14 10:41:06 -0700 | [diff] [blame] | 17 | #include "base/time_utils.h" |
Mathieu Chartier | a80e2af | 2016-06-08 16:29:48 -0700 | [diff] [blame] | 18 | #include "jni.h" |
| 19 | #include "runtime.h" |
| 20 | #include "thread_list.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | extern "C" JNIEXPORT void JNICALL Java_Main_suspendAndResume(JNIEnv*, jclass) { |
Mathieu Chartier | e99f532 | 2016-06-10 17:04:20 -0700 | [diff] [blame] | 25 | static constexpr size_t kInitialSleepUS = 100 * 1000; // 100ms. |
Mathieu Chartier | e99f532 | 2016-06-10 17:04:20 -0700 | [diff] [blame] | 26 | usleep(kInitialSleepUS); // Leave some time for threads to get in here before we start suspending. |
| 27 | enum Operation { |
| 28 | kOPSuspendAll, |
| 29 | kOPDumpStack, |
| 30 | kOPSuspendAllDumpStack, |
| 31 | // Total number of operations. |
| 32 | kOPNumber, |
| 33 | }; |
Mathieu Chartier | f7d2f9f | 2016-06-14 10:41:06 -0700 | [diff] [blame] | 34 | const uint64_t start_time = NanoTime(); |
| 35 | size_t iterations = 0; |
| 36 | // Run for a fixed period of 10 seconds. |
| 37 | while (NanoTime() - start_time < MsToNs(10 * 1000)) { |
| 38 | switch (static_cast<Operation>(iterations % kOPNumber)) { |
Mathieu Chartier | e99f532 | 2016-06-10 17:04:20 -0700 | [diff] [blame] | 39 | case kOPSuspendAll: { |
| 40 | ScopedSuspendAll ssa(__FUNCTION__); |
| 41 | usleep(500); |
| 42 | break; |
| 43 | } |
| 44 | case kOPDumpStack: { |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 45 | Runtime::Current()->GetThreadList()->Dump(LOG_STREAM(INFO)); |
Mathieu Chartier | e99f532 | 2016-06-10 17:04:20 -0700 | [diff] [blame] | 46 | usleep(500); |
| 47 | break; |
| 48 | } |
| 49 | case kOPSuspendAllDumpStack: { |
| 50 | // Not yet supported. |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 51 | if ((false)) { |
| 52 | ScopedSuspendAll ssa(__FUNCTION__); |
| 53 | Runtime::Current()->GetThreadList()->Dump(LOG_STREAM(INFO)); |
| 54 | } |
Mathieu Chartier | e99f532 | 2016-06-10 17:04:20 -0700 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | case kOPNumber: |
| 58 | break; |
| 59 | } |
Mathieu Chartier | f7d2f9f | 2016-06-14 10:41:06 -0700 | [diff] [blame] | 60 | ++iterations; |
Mathieu Chartier | a80e2af | 2016-06-08 16:29:48 -0700 | [diff] [blame] | 61 | } |
Mathieu Chartier | f7d2f9f | 2016-06-14 10:41:06 -0700 | [diff] [blame] | 62 | LOG(INFO) << "Did " << iterations << " iterations"; |
Mathieu Chartier | a80e2af | 2016-06-08 16:29:48 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | } // namespace art |