@@ -492,6 +492,8 @@ static int we_perflib_process_object_type(
492
492
perflib_object -> counter_count = perf_object -> NumCounters ;
493
493
perflib_object -> instance_count = perf_object -> NumInstances ;
494
494
495
+ perflib_object -> total_byte_length = perf_object -> TotalByteLength ;
496
+ perflib_object -> definition_length = perf_object -> DefinitionLength ;
495
497
496
498
perflib_object -> instances = flb_hash_table_create (
497
499
FLB_HASH_TABLE_EVICT_NONE ,
@@ -795,11 +797,57 @@ static int we_perflib_process_instances(struct we_perflib_context *context,
795
797
{
796
798
struct we_perflib_instance * perflib_instance ;
797
799
size_t instance_index ;
800
+ size_t total_instance_data_size ;
801
+ PERF_COUNTER_BLOCK * first_counter_block ;
798
802
int result ;
799
803
int offset ;
800
804
801
805
offset = 0 ;
802
806
807
+ /* Calculate the total size of all instance and counter data blocks */
808
+ total_instance_data_size = perflib_object -> total_byte_length -
809
+ perflib_object -> definition_length ;
810
+
811
+ /*
812
+ * If the total size of instance data is exactly equal to the
813
+ * size of the first counter block, we can infer this is a single-instance
814
+ * object that lacks a PERF_INSTANCE_DEFINITION block.
815
+ */
816
+ if (perflib_object -> instance_count == PERF_NO_INSTANCES ) {
817
+ first_counter_block = (PERF_COUNTER_BLOCK * )input_data_block ;
818
+
819
+ if (first_counter_block -> ByteLength == total_instance_data_size ) {
820
+ /* Path for special single-instance objects like "Cache" and "System" */
821
+ perflib_instance = we_perflib_create_instance (perflib_object -> counter_count );
822
+ if (perflib_instance == NULL ) {
823
+ return -1 ;
824
+ }
825
+
826
+ perflib_instance -> name = flb_strdup ("_Total" );
827
+ perflib_instance -> parent = perflib_object ;
828
+
829
+ result = we_perflib_process_counters (context , perflib_object ,
830
+ perflib_instance , input_data_block );
831
+
832
+ if (result < 0 ) {
833
+ we_perflib_destroy_instance (perflib_instance );
834
+ return -1 ;
835
+ }
836
+ offset += result ;
837
+
838
+ result = flb_hash_table_add (perflib_object -> instances ,
839
+ perflib_instance -> name , strlen (perflib_instance -> name ),
840
+ perflib_instance , 0 );
841
+
842
+ if (result < 0 ) {
843
+ we_perflib_destroy_instance (perflib_instance );
844
+ return -2 ;
845
+ }
846
+
847
+ return offset ;
848
+ }
849
+ }
850
+
803
851
for (instance_index = 0 ;
804
852
instance_index < perflib_object -> instance_count ;
805
853
instance_index ++ ) {
0 commit comments