• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
16 #include "ecmascript/pgo_profiler/pgo_profiler.h"
17 
18 #include "ecmascript/js_function.h"
19 #include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
20 
21 namespace panda::ecmascript {
Sample(JSTaggedType value,SampleMode mode)22 void PGOProfiler::Sample(JSTaggedType value, SampleMode mode)
23 {
24     if (!isEnable_) {
25         return;
26     }
27     DISALLOW_GARBAGE_COLLECTION;
28     JSTaggedValue jsValue(value);
29     if (jsValue.IsJSFunction() && JSFunction::Cast(jsValue)->GetMethod().IsMethod()) {
30         auto jsMethod = Method::Cast(JSFunction::Cast(jsValue)->GetMethod());
31         JSTaggedValue recordNameValue = JSFunction::Cast(jsValue)->GetRecordName();
32         if (recordNameValue.IsHole()) {
33             return;
34         }
35         CString recordName = ConvertToString(recordNameValue);
36         if (recordInfos_->AddMethod(recordName, jsMethod->GetMethodId(), jsMethod->GetMethodName(), mode)) {
37             methodCount_++;
38         }
39         // Merged every 10 methods
40         if (methodCount_ >= MERGED_EVERY_COUNT) {
41             LOG_ECMA(DEBUG) << "Sample: post task to save profiler";
42             PGOProfilerManager::GetInstance()->Merge(this);
43             PGOProfilerManager::GetInstance()->AsynSave();
44             methodCount_ = 0;
45         }
46     }
47 }
48 } // namespace panda::ecmascript
49