blob: dfd944a2673f7c1410f92c6d2909dc20e12d5723 [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: {
45 Runtime::Current()->GetThreadList()->Dump(LOG(INFO));
46 usleep(500);
47 break;
48 }
49 case kOPSuspendAllDumpStack: {
50 // Not yet supported.
51 // ScopedSuspendAll ssa(__FUNCTION__);
52 // Runtime::Current()->GetThreadList()->Dump(LOG(INFO));
53 break;
54 }
55 case kOPNumber:
56 break;
57 }
Mathieu Chartierf7d2f9f2016-06-14 10:41:06 -070058 ++iterations;
Mathieu Chartiera80e2af2016-06-08 16:29:48 -070059 }
Mathieu Chartierf7d2f9f2016-06-14 10:41:06 -070060 LOG(INFO) << "Did " << iterations << " iterations";
Mathieu Chartiera80e2af2016-06-08 16:29:48 -070061}
62
63} // namespace art