1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <thread> 16 #include <unistd.h> 17 #include <vector> 18 19 #include "hiperf_client.h" 20 21 using namespace OHOS::Developtools::HiPerf; 22 using namespace HiperfMallocDemo; 23 main(const int argc,const char * argv[])24int main(const int argc, const char *argv[]) 25 { 26 static const int WART_TIME = 100; 27 static const int COUNT_TRY = 1000; 28 const int bufSize = 1048576; 29 30 printf("demo start\n"); 31 sleep(WART_TIME); 32 void *temp = nullptr; 33 // try for each thread times 34 for (int i = 0; i < COUNT_TRY; i++) { 35 temp = malloc(bufSize); 36 printf("malloc %d \n", i); 37 sleep(WART_TIME); 38 if (temp != nullptr) { 39 free(temp); 40 temp = nullptr; 41 } 42 } 43 printf("demo stop \n"); 44 if (temp != nullptr) { 45 free(temp); 46 temp = nullptr; 47 } 48 return 0; 49 }; 50