blob: c1c0ff9f5f0eb61e559331acfd233da22f6e0f79 [file] [log] [blame]
Mathieu Chartiera80e2af2016-06-08 16:29:48 -07001/*
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 Chartierf7d2f9f2016-06-14 10:41:06 -070017#include "base/time_utils.h"
Mathieu Chartiera80e2af2016-06-08 16:29:48 -070018#include "jni.h"
19#include "runtime.h"
20#include "thread_list.h"
21
22namespace art {
23
24extern "C" JNIEXPORT void JNICALL Java_Main_suspendAndResume(JNIEnv*, jclass) {
Mathieu Chartiere99f5322016-06-10 17:04:20 -070025 static constexpr size_t kInitialSleepUS = 100 * 1000; // 100ms.
Mathieu Chartiere99f5322016-06-10 17:04:20 -070026 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 Chartierf7d2f9f2016-06-14 10:41:06 -070034 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 Chartiere99f5322016-06-10 17:04:20 -070039 case kOPSuspendAll: {
40 ScopedSuspendAll ssa(__FUNCTION__);
41 usleep(500);
42 break;
43 }
44 case kOPDumpStack: {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070045 Runtime::Current()->GetThreadList()->Dump(LOG_STREAM(INFO));
Mathieu Chartiere99f5322016-06-10 17:04:20 -070046 usleep(500);
47 break;
48 }
49 case kOPSuspendAllDumpStack: {
50 // Not yet supported.
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070051 if ((false)) {
52 ScopedSuspendAll ssa(__FUNCTION__);
53 Runtime::Current()->GetThreadList()->Dump(LOG_STREAM(INFO));
54 }
Mathieu Chartiere99f5322016-06-10 17:04:20 -070055 break;
56 }
57 case kOPNumber:
58 break;
59 }
Mathieu Chartierf7d2f9f2016-06-14 10:41:06 -070060 ++iterations;
Mathieu Chartiera80e2af2016-06-08 16:29:48 -070061 }
Mathieu Chartierf7d2f9f2016-06-14 10:41:06 -070062 LOG(INFO) << "Did " << iterations << " iterations";
Mathieu Chartiera80e2af2016-06-08 16:29:48 -070063}
64
65} // namespace art