33
44#include " MLInference.h"
55#include " ContextualClassifier.h"
6+ #include " FeatureExtractor.h"
67#include < algorithm>
78#include < cmath>
89#include < fstream>
1617
1718#define CLASSIFIER_TAG " MLInference"
1819
20+ static std::string format_string (const char *fmt, ...) {
21+ char buffer[1024 ];
22+ va_list args;
23+ va_start (args, fmt);
24+ vsnprintf (buffer, sizeof (buffer), fmt, args);
25+ va_end (args);
26+ return std::string (buffer);
27+ }
28+
1929MLInference::MLInference (const std::string &ft_model_path)
2030 : Inference(ft_model_path) {
2131 text_cols_ = {" attr" , " cgroup" , " cmdline" , " comm" , " maps" ,
@@ -46,8 +56,8 @@ std::string MLInference::normalize_text(const std::string &text) {
4656}
4757
4858CC_TYPE MLInference::Classify (int process_pid) {
49- LOGD (CLASSIFIER_TAG,
50- format_string (" Starting classification for PID:%d" , process_pid));
59+ // LOGD(CLASSIFIER_TAG,
60+ // format_string("Starting classification for PID:%d", process_pid));
5161
5262 const std::string proc_path = " /proc/" + std::to_string (process_pid);
5363 CC_TYPE contextType = CC_APP;
@@ -56,24 +66,24 @@ CC_TYPE MLInference::Classify(int process_pid) {
5666
5767 auto start_collect = std::chrono::high_resolution_clock::now ();
5868 int collect_rc = FeatureExtractor::CollectAndStoreData (
59- process_pid, raw_data, mDebugMode );
69+ process_pid, raw_data, false );
6070 auto end_collect = std::chrono::high_resolution_clock::now ();
6171 std::chrono::duration<double , std::milli> elapsed_collect =
6272 end_collect - start_collect;
63- LOGD (CLASSIFIER_TAG,
64- format_string (" Data collection for PID:%d took %f ms (rc=%d)" ,
65- process_pid, elapsed_collect.count (), collect_rc));
73+ // LOGD(CLASSIFIER_TAG,
74+ // format_string("Data collection for PID:%d took %f ms (rc=%d)",
75+ // process_pid, elapsed_collect.count(), collect_rc));
6676
6777 if (collect_rc != 0 ) {
6878 // Process exited or collection failed; skip further work.
69- return 0 ;
79+ return contextType ;
7080 }
7181
72- LOGD (CLASSIFIER_TAG,
73- format_string (" Text features collected for PID:%d" , process_pid));
82+ // LOGD(CLASSIFIER_TAG,
83+ // format_string("Text features collected for PID:%d", process_pid));
7484
7585 if (!AuxRoutines::fileExists (proc_path)) {
76- return 0 ;
86+ return contextType ;
7787 }
7888
7989 bool has_sufficient_features = false ;
@@ -93,8 +103,8 @@ CC_TYPE MLInference::Classify(int process_pid) {
93103 format_string (" Invoking ML inference for PID:%d" , process_pid));
94104
95105 auto start_inference = std::chrono::high_resolution_clock::now ();
96- if (mInference ) {
97- uint32_t rc = mInference -> predict (process_pid, raw_data, predicted_label);
106+ // if (Inference ) {
107+ uint32_t rc = predict (process_pid, raw_data, predicted_label);
98108 auto end_inference = std::chrono::high_resolution_clock::now ();
99109 std::chrono::duration<double , std::milli> elapsed_inference =
100110 end_inference - start_inference;
@@ -105,11 +115,11 @@ CC_TYPE MLInference::Classify(int process_pid) {
105115 // Inference failed, keep contextType as UNKNOWN.
106116 predicted_label.clear ();
107117 }
108- } else {
118+ /* } else {
109119 LOGW(CLASSIFIER_TAG,
110120 format_string("No Inference object available for PID:%d",
111121 process_pid));
112- }
122+ }*/
113123
114124 // Map stripped label -> CC_APP enum.
115125 // MLInference::predict() returns after stripping "__label__".
0 commit comments