]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOHistogramReporter.cpp
xnu-4570.51.1.tar.gz
[apple/xnu.git] / iokit / Kernel / IOHistogramReporter.cpp
index f51a1c936c7a0c01282efb0b6e20ffe49c7e746a..4c288ccdb89095888d2d0751026c8294846003bf 100644 (file)
@@ -43,7 +43,7 @@ IOHistogramReporter::with(IOService *reportingService,
                           IOReportCategories categories,
                           uint64_t channelID,
                           const char *channelName,
-                          IOReportUnits unit,
+                          IOReportUnit unit,
                           int nSegments,
                           IOHistogramSegmentConfig *config)
 {
@@ -62,6 +62,8 @@ IOHistogramReporter::with(IOService *reportingService,
             return reporter;
         }
     }
+    OSSafeReleaseNULL(reporter);
+    OSSafeReleaseNULL(tmpChannelName);
     
     return 0;
 }
@@ -72,7 +74,7 @@ IOHistogramReporter::initWith(IOService *reportingService,
                               IOReportCategories categories,
                               uint64_t channelID,
                               const OSSymbol *channelName,
-                              IOReportUnits unit,
+                              IOReportUnit unit,
                               int nSegments,
                               IOHistogramSegmentConfig *config)
 {
@@ -208,7 +210,8 @@ IOHistogramReporter::initWith(IOService *reportingService,
             
             if (cnt3 >= _nElements) {
                 IORLOG("ERROR: _bucketBounds init");
-                return false;
+                result = false;
+                goto finish;
             }
             
             if (_histogramSegmentsConfig[cnt].scale_flag) {
@@ -245,21 +248,6 @@ IOHistogramReporter::initWith(IOService *reportingService,
     result = true;
     
 finish:
-    if (result != true) {
-        
-        if (_histogramSegmentsConfig)
-            IOFree(_histogramSegmentsConfig, configSize);
-        
-        if (_elements)
-            IOFree(_elements, elementsSize);
-        
-        if (_enableCounts)
-            IOFree(_enableCounts, eCountsSize);
-        
-        if (_bucketBounds)
-            IOFree(_bucketBounds, boundsSize);
-    }
-    
     return result;
 }
 
@@ -284,34 +272,62 @@ IOHistogramReporter::free(void)
 IOReportLegendEntry*
 IOHistogramReporter::handleCreateLegend(void)
 {
-    OSData                  *tmpConfigData;
-    OSDictionary            *tmpDict;
-    IOReportLegendEntry     *legendEntry = NULL;
+    IOReportLegendEntry     *rval = NULL, *legendEntry = NULL;
+    OSData                  *tmpConfigData = NULL;
+    OSDictionary            *tmpDict;       // no refcount
         
     legendEntry = super::handleCreateLegend();
+    if (!legendEntry)       goto finish;
     
-    if (legendEntry) {
-        
-        PREFL_MEMOP_PANIC(_segmentCount, IOHistogramSegmentConfig);
-        tmpConfigData = OSData::withBytes(_histogramSegmentsConfig,
-                                          (unsigned)_segmentCount *
-                                            (unsigned)sizeof(IOHistogramSegmentConfig));
-        if (!tmpConfigData) {
-            legendEntry->release();
-            goto finish;
-        }
-        
-        tmpDict = OSDynamicCast(OSDictionary, legendEntry->getObject(kIOReportLegendInfoKey));
-        if (!tmpDict) {
-            legendEntry->release();
-            goto finish;
-        }
-        
-        tmpDict->setObject(kIOReportLegendConfigKey, tmpConfigData);
+    PREFL_MEMOP_PANIC(_segmentCount, IOHistogramSegmentConfig);
+    tmpConfigData = OSData::withBytes(_histogramSegmentsConfig,
+                         (unsigned)_segmentCount *
+                             sizeof(IOHistogramSegmentConfig));
+    if (!tmpConfigData)         goto finish;
+
+    tmpDict = OSDynamicCast(OSDictionary,
+                    legendEntry->getObject(kIOReportLegendInfoKey));
+    if (!tmpDict)               goto finish;
+
+    tmpDict->setObject(kIOReportLegendConfigKey, tmpConfigData);
+
+    // success
+    rval = legendEntry;
+
+finish:
+    if (tmpConfigData)  tmpConfigData->release();
+    if (!rval && legendEntry) {
+        legendEntry->release();
     }
-    
+
+    return rval;
+}
+
+IOReturn
+IOHistogramReporter::overrideBucketValues(unsigned int index, 
+                                          uint64_t bucket_hits,
+                                          int64_t bucket_min,
+                                          int64_t bucket_max,
+                                          int64_t bucket_sum)
+{
+    IOReturn result;
+    IOHistogramReportValues bucket;
+    lockReporter();
+
+    if (index >= (unsigned int)_bucketCount) {
+        result = kIOReturnBadArgument;
+        goto finish;
+    }
+
+    bucket.bucket_hits = bucket_hits;
+    bucket.bucket_min = bucket_min;
+    bucket.bucket_max = bucket_max;
+    bucket.bucket_sum = bucket_sum;
+
+    result = setElementValues(index, (IOReportElementValues *)&bucket);
 finish:
-    return legendEntry;
+    unlockReporter();
+    return result;
 }
 
 int
@@ -349,7 +365,8 @@ IOHistogramReporter::tallyValue(int64_t value)
     hist_values.bucket_sum += value;
     hist_values.bucket_hits++;
     
-    if (setElementValues(element_index, (IOReportElementValues *)&hist_values) == kIOReturnSuccess) {
+    if (setElementValues(element_index, (IOReportElementValues *)&hist_values)
+                != kIOReturnSuccess) {
         goto finish;
     }