MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / saveReuseModel

Method saveReuseModel

native/agent/ModelReusableAgent.cpp:508–542  ·  view source on GitHub ↗

With the FlatBuffer library, serialize the ReuseModel according to ReuseModel.fbs, and save the data to modelFilePath. \param modelFilepath the path to save this serialized model.

Source from the content-addressed store, hash-verified

506 /// and save the data to modelFilePath.
507 /// \param modelFilepath the path to save this serialized model.
508 void ModelReusableAgent::saveReuseModel(const std::string &modelFilepath) {
509 flatbuffers::FlatBufferBuilder builder;
510 std::vector<flatbuffers::Offset<fastbotx::ReuseEntry>> actionActivityVector;
511 // loaded, but not visited
512 {
513 std::lock_guard<std::mutex> reuseGuard(this->_reuseModelLock);
514 for (const auto &actionIterator: this->_reuseModel) {
515 uint64_t actionHash = actionIterator.first;
516 ReuseEntryM activityCountEntryMap = actionIterator.second;
517 std::vector<flatbuffers::Offset<fastbotx::ActivityTimes>> activityCountEntryVector; // flat buffer needs vector rather than map
518 for (const auto &activityCountEntry: activityCountEntryMap) {
519 auto sentryActT = CreateActivityTimes(builder, builder.CreateString(
520 *(activityCountEntry.first)), activityCountEntry.second);
521 activityCountEntryVector.push_back(sentryActT);
522 }
523 auto savedActivityCountEntries = CreateReuseEntry(builder, actionHash,
524 builder.CreateVector(
525 activityCountEntryVector.data(),
526 activityCountEntryVector.size()));
527 actionActivityVector.push_back(savedActivityCountEntries);
528 }
529 }
530 auto savedActionActivityEntries = CreateReuseModel(builder, builder.CreateVector(
531 actionActivityVector.data(), actionActivityVector.size()));
532 builder.Finish(savedActionActivityEntries);
533
534 //save to local file
535 std::string outputFilePath = modelFilepath;
536 if (outputFilePath.empty()) // if the passed argument modelFilepath is "", use the tmpSavePath
537 outputFilePath = this->_defaultModelSavePath;
538 BLOG("save model to path: %s", outputFilePath.c_str());
539 std::ofstream outputFile(outputFilePath);
540 outputFile.write((char *) builder.GetBufferPointer(), static_cast<int>(builder.GetSize()));
541 outputFile.close();
542 }
543
544}
545

Callers 2

~ModelReusableAgentMethod · 0.95
threadModelStorageMethod · 0.80

Calls 10

CreateActivityTimesFunction · 0.85
CreateReuseEntryFunction · 0.85
CreateReuseModelFunction · 0.85
push_backMethod · 0.80
emptyMethod · 0.80
writeMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
FinishMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected