148f512ceSopenharmony_ci/* 248f512ceSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 348f512ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 448f512ceSopenharmony_ci * you may not use this file except in compliance with the License. 548f512ceSopenharmony_ci * You may obtain a copy of the License at 648f512ceSopenharmony_ci * 748f512ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 848f512ceSopenharmony_ci * 948f512ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1048f512ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1148f512ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1248f512ceSopenharmony_ci * See the License for the specific language governing permissions and 1348f512ceSopenharmony_ci * limitations under the License. 1448f512ceSopenharmony_ci */ 1548f512ceSopenharmony_ci#include <thread> 1648f512ceSopenharmony_ci#include <unistd.h> 1748f512ceSopenharmony_ci#include <vector> 1848f512ceSopenharmony_ci 1948f512ceSopenharmony_ci#include "hiperf_client.h" 2048f512ceSopenharmony_ci 2148f512ceSopenharmony_ciusing namespace OHOS::Developtools::HiPerf; 2248f512ceSopenharmony_ciusing namespace HiperfMallocDemo; 2348f512ceSopenharmony_ci 2448f512ceSopenharmony_ciint main(const int argc, const char *argv[]) 2548f512ceSopenharmony_ci{ 2648f512ceSopenharmony_ci static const int WART_TIME = 100; 2748f512ceSopenharmony_ci static const int COUNT_TRY = 1000; 2848f512ceSopenharmony_ci const int bufSize = 1048576; 2948f512ceSopenharmony_ci 3048f512ceSopenharmony_ci printf("demo start\n"); 3148f512ceSopenharmony_ci sleep(WART_TIME); 3248f512ceSopenharmony_ci void *temp = nullptr; 3348f512ceSopenharmony_ci // try for each thread times 3448f512ceSopenharmony_ci for (int i = 0; i < COUNT_TRY; i++) { 3548f512ceSopenharmony_ci temp = malloc(bufSize); 3648f512ceSopenharmony_ci printf("malloc %d \n", i); 3748f512ceSopenharmony_ci sleep(WART_TIME); 3848f512ceSopenharmony_ci if (temp != nullptr) { 3948f512ceSopenharmony_ci free(temp); 4048f512ceSopenharmony_ci temp = nullptr; 4148f512ceSopenharmony_ci } 4248f512ceSopenharmony_ci } 4348f512ceSopenharmony_ci printf("demo stop \n"); 4448f512ceSopenharmony_ci if (temp != nullptr) { 4548f512ceSopenharmony_ci free(temp); 4648f512ceSopenharmony_ci temp = nullptr; 4748f512ceSopenharmony_ci } 4848f512ceSopenharmony_ci return 0; 4948f512ceSopenharmony_ci}; 50