Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-13145

Redundant typecasts to double in src/zabbix_agent/vmstats.c

    XMLWordPrintable

    Details

    • Team:
      Team C
    • Sprint:
      Sprint 24
    • Story Points:
      0.5

      Description

      1. One typecast is enough (no matter which one) because integer operand is casted to double when another operand is double:
        /* --- kthr --- */
        vmstat->kthr_r = (double)(cpustats.runque - last_runque) / (double)(now - last_clock);
        vmstat->kthr_b = (double)(cpustats.swpque - last_swpque) / (double)(now - last_clock);
        /* --- page --- */
        vmstat->fi = (double)(memstats.pgins - last_pgins) / (double)(now - last_clock);
        vmstat->fo = (double)(memstats.pgouts - last_pgouts) / (double)(now - last_clock);
        vmstat->pi = (double)(memstats.pgspins - last_pgspins) / (double)(now - last_clock);
        vmstat->po = (double)(memstats.pgspouts - last_pgspouts) / (double)(now - last_clock);
        vmstat->fr = (double)(memstats.cycles - last_cycles) / (double)(now - last_clock);
        vmstat->sr = (double)(memstats.scans - last_scans) / (double)(now - last_clock);
        /* -- faults -- */
        vmstat->in = (double)(cpustats.devintrs - last_devintrs) / (double)(now - last_clock);
        vmstat->sy = (double)(cpustats.syscall - last_syscall) / (double)(now - last_clock);
        vmstat->cs = (double)(cpustats.pswitch - last_pswitch) / (double)(now - last_clock);
        
      2. Typecast is not needed, 100.0 is of type double:
        vmstat->ent = (double)lparstats.entitled_proc_capacity / 100.0;
        
      3. One typecast is enough:
        dpcpu_wa += unused_purr * ((double)dlcpu_wa / (double)(dlcpu_wa + dlcpu_id));
        dpcpu_id += unused_purr * ((double)dlcpu_id / (double)(dlcpu_wa + dlcpu_id));
        
      4. Typecasts not needed thanks to 100.0 and left-to-right associativity of multiplication and division:
        vmstat->cpu_us = (double)dpcpu_us * 100.0 / (double)pcputime;
        vmstat->cpu_sy = (double)dpcpu_sy * 100.0 / (double)pcputime;
        vmstat->cpu_id = (double)dpcpu_id * 100.0 / (double)pcputime;
        vmstat->cpu_wa = (double)dpcpu_wa * 100.0 / (double)pcputime;
        
      5. One is enough:
        vmstat->cpu_pc = (double)delta_purr / (double)dtimebase;
        
      6. Not needed, vmstat->cpu_pc is double:
        vmstat->cpu_ec = (double)(vmstat->cpu_pc / vmstat->ent) * 100.0;
        
      7. Not needed:
        vmstat->cpu_lbusy = (double)(dlcpu_us + dlcpu_sy) * 100.0 / (double)lcputime;
        
      8. One is enough:
        vmstat->cpu_app = (double)(lparstats.pool_idle_time - last_pool_idle_time) / (XINTFRAC * (double)dtimebase);
        
      9. Not needed:
        vmstat->cpu_us = (double)dlcpu_us * 100.0 / (double)lcputime;
        vmstat->cpu_sy = (double)dlcpu_sy * 100.0 / (double)lcputime;
        vmstat->cpu_id = (double)dlcpu_id * 100.0 / (double)lcputime;
        vmstat->cpu_wa = (double)dlcpu_wa * 100.0 / (double)lcputime;
        
      10. One is enough:
        vmstat->disk_tps = (double)(diskstats.xfers - last_xfers) / (double)(now - last_clock);
        

        Attachments

          Activity

            People

            Assignee:
            MVekslers Michael Veksler
            Reporter:
            glebs.ivanovskis Glebs Ivanovskis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: