1 /*
2  * Copyright (C) 2010 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  */
17 
18 #include <jni.h>
19 #include <iostream>
20 #include <tuple>
21 #include <algorithm>
22 #include <numeric>
23 #include <string>
24 #include <sstream>
25 #include <cstring>
26 #include <fstream>
27 
28 #include <android/log.h>
29 #define LOG(...) __android_log_write(ANDROID_LOG_INFO, "ALLOC-STRESS", __VA_ARGS__)
30 
31 using namespace std;
32 
33 size_t s = 4 * (1 << 20); // 4 MB
34 extern "C"
35 JNIEXPORT void JNICALL
Java_com_android_server_cts_device_statsd_StatsdCtsBackgroundService_cmain(JNIEnv *,jobject)36 Java_com_android_server_cts_device_statsd_StatsdCtsBackgroundService_cmain(JNIEnv* , jobject /* this */)
37 {
38     long long allocCount = 0;
39     while (1) {
40         char *ptr = (char *) malloc(s);
41         memset(ptr, (int) allocCount >> 10, s);
42         std::stringstream ss;
43         ss << "total alloc: " << (allocCount >> 20) << endl;
44         LOG(ss.str().c_str());
45         allocCount += s;
46     }
47 }
48