fast-stats 1.7 → 1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/Makefile +1 -0
 - data/ext/stats/stats-ruby.c +209 -5
 - data/fast-stats.gemspec +3 -0
 - data/lib/stats/version.rb +1 -1
 - data/test/test_stats.rb +18 -0
 - metadata +20 -18
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: d927911272d5a002dc8c65081daf6ef427a45eeb
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ea6b385bb0459ea4c0e298d873b06f6dc106e241
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2072ef0aede7cb79bc0bb90b82954782bf7cd44ec572aa29cc4526e11c4767924b09082a8571052a0b81f632d608c2f47c80c0bca853cbf2e2e6464501fa66af
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 24bde670ea0a91aae2df662800bdf154a60856fc15eb0adaef234582683feded041669a8ac9427ef06b397781e0c4a4c6adb81bde3056e21de53f75541949e74
         
     | 
    
        data/Makefile
    CHANGED
    
    
    
        data/ext/stats/stats-ruby.c
    CHANGED
    
    | 
         @@ -10,6 +10,7 @@ 
     | 
|
| 
       10 
10 
     | 
    
         
             
            static VALUE stats_class = Qnil;
         
     | 
| 
       11 
11 
     | 
    
         
             
            static VALUE ctr_class = Qnil;
         
     | 
| 
       12 
12 
     | 
    
         
             
            static VALUE tmr_class = Qnil;
         
     | 
| 
      
 13 
     | 
    
         
            +
            static VALUE sample_class = Qnil;
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
15 
     | 
    
         
             
            #define STATS_MAGIC  'stat'
         
     | 
| 
       15 
16 
     | 
    
         
             
            #define CTR_MAGIC    'ctr '
         
     | 
| 
         @@ -37,6 +38,9 @@ static void rbctr_free(void *p); 
     | 
|
| 
       37 
38 
     | 
    
         
             
            static VALUE rbtmr_alloc(struct stats_counter *counter);
         
     | 
| 
       38 
39 
     | 
    
         
             
            static void rbtmr_free(void *p);
         
     | 
| 
       39 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
            static VALUE rbsample_alloc(struct stats_counter_list *cl, struct stats_sample *sample);
         
     | 
| 
      
 42 
     | 
    
         
            +
            static void rbsample_free(void *p);
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       40 
44 
     | 
    
         | 
| 
       41 
45 
     | 
    
         
             
            static int hash_probe(struct rbstats *stats, const char *key, long len)
         
     | 
| 
       42 
46 
     | 
    
         
             
            {
         
     | 
| 
         @@ -395,6 +399,52 @@ static VALUE rbstats_clr(VALUE self, VALUE rbkey) 
     | 
|
| 
       395 
399 
     | 
    
         
             
            }
         
     | 
| 
       396 
400 
     | 
    
         | 
| 
       397 
401 
     | 
    
         | 
| 
      
 402 
     | 
    
         
            +
            static VALUE rbstats_sample(VALUE self)
         
     | 
| 
      
 403 
     | 
    
         
            +
            {
         
     | 
| 
      
 404 
     | 
    
         
            +
                struct rbstats *stats;
         
     | 
| 
      
 405 
     | 
    
         
            +
                struct stats_counter_list *cl = NULL;
         
     | 
| 
      
 406 
     | 
    
         
            +
                struct stats_sample *sample = NULL;
         
     | 
| 
      
 407 
     | 
    
         
            +
                VALUE ret = Qnil;
         
     | 
| 
      
 408 
     | 
    
         
            +
             
     | 
| 
      
 409 
     | 
    
         
            +
                stats = rbstats_get_wrapped_stats(self);
         
     | 
| 
      
 410 
     | 
    
         
            +
                if (!stats)
         
     | 
| 
      
 411 
     | 
    
         
            +
                    goto exit;
         
     | 
| 
      
 412 
     | 
    
         
            +
             
     | 
| 
      
 413 
     | 
    
         
            +
                if (stats_cl_create(&cl) != S_OK)
         
     | 
| 
      
 414 
     | 
    
         
            +
                    goto exit;
         
     | 
| 
      
 415 
     | 
    
         
            +
             
     | 
| 
      
 416 
     | 
    
         
            +
                if (stats_get_counter_list(stats->stats, cl) != S_OK)
         
     | 
| 
      
 417 
     | 
    
         
            +
                    goto exit;
         
     | 
| 
      
 418 
     | 
    
         
            +
             
     | 
| 
      
 419 
     | 
    
         
            +
                if (stats_sample_create(&sample) != S_OK)
         
     | 
| 
      
 420 
     | 
    
         
            +
                    goto exit;
         
     | 
| 
      
 421 
     | 
    
         
            +
             
     | 
| 
      
 422 
     | 
    
         
            +
                if (stats_get_sample(stats->stats, cl, sample) != S_OK)
         
     | 
| 
      
 423 
     | 
    
         
            +
                    goto exit;
         
     | 
| 
      
 424 
     | 
    
         
            +
             
     | 
| 
      
 425 
     | 
    
         
            +
                ret = rbsample_alloc(cl, sample);
         
     | 
| 
      
 426 
     | 
    
         
            +
                if (ret != Qnil)
         
     | 
| 
      
 427 
     | 
    
         
            +
                {
         
     | 
| 
      
 428 
     | 
    
         
            +
                    cl = NULL;
         
     | 
| 
      
 429 
     | 
    
         
            +
                    sample = NULL;
         
     | 
| 
      
 430 
     | 
    
         
            +
                }
         
     | 
| 
      
 431 
     | 
    
         
            +
             
     | 
| 
      
 432 
     | 
    
         
            +
            exit:
         
     | 
| 
      
 433 
     | 
    
         
            +
                if (cl != NULL)
         
     | 
| 
      
 434 
     | 
    
         
            +
                {
         
     | 
| 
      
 435 
     | 
    
         
            +
                    stats_cl_free(cl);
         
     | 
| 
      
 436 
     | 
    
         
            +
                }
         
     | 
| 
      
 437 
     | 
    
         
            +
             
     | 
| 
      
 438 
     | 
    
         
            +
                if (sample != NULL)
         
     | 
| 
      
 439 
     | 
    
         
            +
                {
         
     | 
| 
      
 440 
     | 
    
         
            +
                    stats_sample_free(sample);
         
     | 
| 
      
 441 
     | 
    
         
            +
                }
         
     | 
| 
      
 442 
     | 
    
         
            +
             
     | 
| 
      
 443 
     | 
    
         
            +
                return ret;
         
     | 
| 
      
 444 
     | 
    
         
            +
            }
         
     | 
| 
      
 445 
     | 
    
         
            +
             
     | 
| 
      
 446 
     | 
    
         
            +
             
     | 
| 
      
 447 
     | 
    
         
            +
             
     | 
| 
       398 
448 
     | 
    
         
             
            /******************************************************************
         
     | 
| 
       399 
449 
     | 
    
         
             
             *
         
     | 
| 
       400 
450 
     | 
    
         
             
             *  Ruby Counter
         
     | 
| 
         @@ -439,6 +489,16 @@ VALUE rbctr_clr(VALUE self) 
     | 
|
| 
       439 
489 
     | 
    
         
             
                return self;
         
     | 
| 
       440 
490 
     | 
    
         
             
            }
         
     | 
| 
       441 
491 
     | 
    
         | 
| 
      
 492 
     | 
    
         
            +
            VALUE rbctr_get(VALUE self)
         
     | 
| 
      
 493 
     | 
    
         
            +
            {
         
     | 
| 
      
 494 
     | 
    
         
            +
                struct stats_counter *counter = NULL;
         
     | 
| 
      
 495 
     | 
    
         
            +
                long long val;
         
     | 
| 
      
 496 
     | 
    
         
            +
             
     | 
| 
      
 497 
     | 
    
         
            +
                Data_Get_Struct(self, struct stats_counter, counter);
         
     | 
| 
      
 498 
     | 
    
         
            +
                val = counter_get_value(counter);
         
     | 
| 
      
 499 
     | 
    
         
            +
                return LONG2FIX(val);
         
     | 
| 
      
 500 
     | 
    
         
            +
            }
         
     | 
| 
      
 501 
     | 
    
         
            +
             
     | 
| 
       442 
502 
     | 
    
         
             
            VALUE rbctr_set(VALUE self, VALUE amt)
         
     | 
| 
       443 
503 
     | 
    
         
             
            {
         
     | 
| 
       444 
504 
     | 
    
         
             
                struct stats_counter *counter = NULL;
         
     | 
| 
         @@ -472,15 +532,18 @@ struct timer_data 
     | 
|
| 
       472 
532 
     | 
    
         | 
| 
       473 
533 
     | 
    
         
             
            static VALUE rbtmr_alloc(struct stats_counter *counter)
         
     | 
| 
       474 
534 
     | 
    
         
             
            {
         
     | 
| 
       475 
     | 
    
         
            -
                VALUE tdata;
         
     | 
| 
      
 535 
     | 
    
         
            +
                VALUE tdata = Qnil;
         
     | 
| 
       476 
536 
     | 
    
         
             
                struct timer_data *td;
         
     | 
| 
       477 
537 
     | 
    
         | 
| 
       478 
538 
     | 
    
         
             
                td = (struct timer_data *)malloc(sizeof(struct timer_data));
         
     | 
| 
       479 
     | 
    
         
            -
                td 
     | 
| 
       480 
     | 
    
         
            -
                 
     | 
| 
       481 
     | 
    
         
            -
             
     | 
| 
      
 539 
     | 
    
         
            +
                if (td)
         
     | 
| 
      
 540 
     | 
    
         
            +
                {
         
     | 
| 
      
 541 
     | 
    
         
            +
                    td->counter = counter;
         
     | 
| 
      
 542 
     | 
    
         
            +
                    td->start_time = 0;
         
     | 
| 
      
 543 
     | 
    
         
            +
                    td->depth = 0;
         
     | 
| 
       482 
544 
     | 
    
         | 
| 
       483 
     | 
    
         
            -
             
     | 
| 
      
 545 
     | 
    
         
            +
                    tdata = Data_Wrap_Struct(tmr_class, 0, rbtmr_free, td);
         
     | 
| 
      
 546 
     | 
    
         
            +
                }
         
     | 
| 
       484 
547 
     | 
    
         | 
| 
       485 
548 
     | 
    
         
             
                return tdata;
         
     | 
| 
       486 
549 
     | 
    
         
             
            }
         
     | 
| 
         @@ -531,11 +594,144 @@ static void rbtmr_free(void *p) 
     | 
|
| 
       531 
594 
     | 
    
         
             
                free(p);
         
     | 
| 
       532 
595 
     | 
    
         
             
            }
         
     | 
| 
       533 
596 
     | 
    
         | 
| 
      
 597 
     | 
    
         
            +
             
     | 
| 
      
 598 
     | 
    
         
            +
            /******************************************************************
         
     | 
| 
      
 599 
     | 
    
         
            +
             *
         
     | 
| 
      
 600 
     | 
    
         
            +
             *  Ruby Sample
         
     | 
| 
      
 601 
     | 
    
         
            +
             *
         
     | 
| 
      
 602 
     | 
    
         
            +
             */
         
     | 
| 
      
 603 
     | 
    
         
            +
             
     | 
| 
      
 604 
     | 
    
         
            +
            struct rb_sample_data
         
     | 
| 
      
 605 
     | 
    
         
            +
            {
         
     | 
| 
      
 606 
     | 
    
         
            +
                struct stats_counter_list *cl;
         
     | 
| 
      
 607 
     | 
    
         
            +
                struct stats_sample *sample;
         
     | 
| 
      
 608 
     | 
    
         
            +
            };
         
     | 
| 
      
 609 
     | 
    
         
            +
             
     | 
| 
      
 610 
     | 
    
         
            +
             
     | 
| 
      
 611 
     | 
    
         
            +
            static VALUE rbsample_alloc(struct stats_counter_list *cl, struct stats_sample *sample)
         
     | 
| 
      
 612 
     | 
    
         
            +
            {
         
     | 
| 
      
 613 
     | 
    
         
            +
                VALUE tdata = Qnil;
         
     | 
| 
      
 614 
     | 
    
         
            +
                struct rb_sample_data *sd;
         
     | 
| 
      
 615 
     | 
    
         
            +
             
     | 
| 
      
 616 
     | 
    
         
            +
                sd = (struct rb_sample_data *) malloc(sizeof(struct rb_sample_data));
         
     | 
| 
      
 617 
     | 
    
         
            +
                if (sd)
         
     | 
| 
      
 618 
     | 
    
         
            +
                {
         
     | 
| 
      
 619 
     | 
    
         
            +
                    sd->cl = cl;
         
     | 
| 
      
 620 
     | 
    
         
            +
                    sd->sample = sample;
         
     | 
| 
      
 621 
     | 
    
         
            +
                    tdata = Data_Wrap_Struct(sample_class, 0, rbsample_free, sd);
         
     | 
| 
      
 622 
     | 
    
         
            +
                }
         
     | 
| 
      
 623 
     | 
    
         
            +
             
     | 
| 
      
 624 
     | 
    
         
            +
                return tdata;
         
     | 
| 
      
 625 
     | 
    
         
            +
            }
         
     | 
| 
      
 626 
     | 
    
         
            +
             
     | 
| 
      
 627 
     | 
    
         
            +
            static void rbsample_free(void *p)
         
     | 
| 
      
 628 
     | 
    
         
            +
            {
         
     | 
| 
      
 629 
     | 
    
         
            +
                struct rb_sample_data *d = (struct rb_sample_data *)p;
         
     | 
| 
      
 630 
     | 
    
         
            +
                stats_cl_free(d->cl);
         
     | 
| 
      
 631 
     | 
    
         
            +
                stats_sample_free(d->sample);
         
     | 
| 
      
 632 
     | 
    
         
            +
                free(d);
         
     | 
| 
      
 633 
     | 
    
         
            +
            }
         
     | 
| 
      
 634 
     | 
    
         
            +
             
     | 
| 
      
 635 
     | 
    
         
            +
            static VALUE rbsample_keys(VALUE self)
         
     | 
| 
      
 636 
     | 
    
         
            +
            {
         
     | 
| 
      
 637 
     | 
    
         
            +
                struct rb_sample_data *sd = NULL;
         
     | 
| 
      
 638 
     | 
    
         
            +
                VALUE keys;
         
     | 
| 
      
 639 
     | 
    
         
            +
                int i;
         
     | 
| 
      
 640 
     | 
    
         
            +
                char counter_name[MAX_COUNTER_KEY_LENGTH+1];
         
     | 
| 
      
 641 
     | 
    
         
            +
             
     | 
| 
      
 642 
     | 
    
         
            +
                Data_Get_Struct(self, struct rb_sample_data, sd);
         
     | 
| 
      
 643 
     | 
    
         
            +
             
     | 
| 
      
 644 
     | 
    
         
            +
                keys = rb_ary_new();
         
     | 
| 
      
 645 
     | 
    
         
            +
                if (keys != Qnil)
         
     | 
| 
      
 646 
     | 
    
         
            +
                {
         
     | 
| 
      
 647 
     | 
    
         
            +
                    for (i = 0; i < sd->cl->cl_count; i++)
         
     | 
| 
      
 648 
     | 
    
         
            +
                    {
         
     | 
| 
      
 649 
     | 
    
         
            +
                        counter_get_key(sd->cl->cl_ctr[i],counter_name,MAX_COUNTER_KEY_LENGTH+1);
         
     | 
| 
      
 650 
     | 
    
         
            +
                        rb_ary_push(keys, rb_str_new_cstr(counter_name));
         
     | 
| 
      
 651 
     | 
    
         
            +
                    }
         
     | 
| 
      
 652 
     | 
    
         
            +
                }
         
     | 
| 
      
 653 
     | 
    
         
            +
             
     | 
| 
      
 654 
     | 
    
         
            +
                return keys;
         
     | 
| 
      
 655 
     | 
    
         
            +
            }
         
     | 
| 
      
 656 
     | 
    
         
            +
             
     | 
| 
      
 657 
     | 
    
         
            +
            static VALUE rbsample_time(VALUE self)
         
     | 
| 
      
 658 
     | 
    
         
            +
            {
         
     | 
| 
      
 659 
     | 
    
         
            +
                struct rb_sample_data *sd = NULL;
         
     | 
| 
      
 660 
     | 
    
         
            +
             
     | 
| 
      
 661 
     | 
    
         
            +
                Data_Get_Struct(self, struct rb_sample_data, sd);
         
     | 
| 
      
 662 
     | 
    
         
            +
             
     | 
| 
      
 663 
     | 
    
         
            +
                return LONG2FIX(sd->sample->sample_time);
         
     | 
| 
      
 664 
     | 
    
         
            +
            }
         
     | 
| 
      
 665 
     | 
    
         
            +
             
     | 
| 
      
 666 
     | 
    
         
            +
            static VALUE rbsample_count(VALUE self)
         
     | 
| 
      
 667 
     | 
    
         
            +
            {
         
     | 
| 
      
 668 
     | 
    
         
            +
                struct rb_sample_data *sd = NULL;
         
     | 
| 
      
 669 
     | 
    
         
            +
             
     | 
| 
      
 670 
     | 
    
         
            +
                Data_Get_Struct(self, struct rb_sample_data, sd);
         
     | 
| 
      
 671 
     | 
    
         
            +
             
     | 
| 
      
 672 
     | 
    
         
            +
                return LONG2FIX(sd->cl->cl_count);
         
     | 
| 
      
 673 
     | 
    
         
            +
            }
         
     | 
| 
      
 674 
     | 
    
         
            +
             
     | 
| 
      
 675 
     | 
    
         
            +
            static VALUE rbsample_get(VALUE self, VALUE key_arg)
         
     | 
| 
      
 676 
     | 
    
         
            +
            {
         
     | 
| 
      
 677 
     | 
    
         
            +
                struct rb_sample_data *sd = NULL;
         
     | 
| 
      
 678 
     | 
    
         
            +
                int i;
         
     | 
| 
      
 679 
     | 
    
         
            +
                char counter_name[MAX_COUNTER_KEY_LENGTH+1], *key;
         
     | 
| 
      
 680 
     | 
    
         
            +
                long long val;
         
     | 
| 
      
 681 
     | 
    
         
            +
             
     | 
| 
      
 682 
     | 
    
         
            +
                Check_Type(key_arg,T_STRING);
         
     | 
| 
      
 683 
     | 
    
         
            +
             
     | 
| 
      
 684 
     | 
    
         
            +
                Data_Get_Struct(self, struct rb_sample_data, sd);
         
     | 
| 
      
 685 
     | 
    
         
            +
                key = StringValueCStr(key_arg);
         
     | 
| 
      
 686 
     | 
    
         
            +
             
     | 
| 
      
 687 
     | 
    
         
            +
                for (i = 0; i < sd->cl->cl_count; i++)
         
     | 
| 
      
 688 
     | 
    
         
            +
                {
         
     | 
| 
      
 689 
     | 
    
         
            +
                    counter_get_key(sd->cl->cl_ctr[i],counter_name,MAX_COUNTER_KEY_LENGTH+1);
         
     | 
| 
      
 690 
     | 
    
         
            +
                    if (strcmp(key, counter_name) == 0)
         
     | 
| 
      
 691 
     | 
    
         
            +
                    {
         
     | 
| 
      
 692 
     | 
    
         
            +
                        val = stats_sample_get_value(sd->sample, i);
         
     | 
| 
      
 693 
     | 
    
         
            +
                        return LONG2FIX(val);
         
     | 
| 
      
 694 
     | 
    
         
            +
                    }
         
     | 
| 
      
 695 
     | 
    
         
            +
                }
         
     | 
| 
      
 696 
     | 
    
         
            +
             
     | 
| 
      
 697 
     | 
    
         
            +
                return Qnil;
         
     | 
| 
      
 698 
     | 
    
         
            +
            }
         
     | 
| 
      
 699 
     | 
    
         
            +
             
     | 
| 
      
 700 
     | 
    
         
            +
            static VALUE rbsample_each(VALUE self)
         
     | 
| 
      
 701 
     | 
    
         
            +
            {
         
     | 
| 
      
 702 
     | 
    
         
            +
                struct rb_sample_data *sd = NULL;
         
     | 
| 
      
 703 
     | 
    
         
            +
                int i;
         
     | 
| 
      
 704 
     | 
    
         
            +
                char counter_name[MAX_COUNTER_KEY_LENGTH+1];
         
     | 
| 
      
 705 
     | 
    
         
            +
                long long val;
         
     | 
| 
      
 706 
     | 
    
         
            +
                VALUE key;
         
     | 
| 
      
 707 
     | 
    
         
            +
             
     | 
| 
      
 708 
     | 
    
         
            +
                Data_Get_Struct(self, struct rb_sample_data, sd);
         
     | 
| 
      
 709 
     | 
    
         
            +
             
     | 
| 
      
 710 
     | 
    
         
            +
                for (i = 0; i < sd->cl->cl_count; i++)
         
     | 
| 
      
 711 
     | 
    
         
            +
                {
         
     | 
| 
      
 712 
     | 
    
         
            +
                    counter_get_key(sd->cl->cl_ctr[i],counter_name,MAX_COUNTER_KEY_LENGTH+1);
         
     | 
| 
      
 713 
     | 
    
         
            +
                    key = rb_str_new_cstr(counter_name);
         
     | 
| 
      
 714 
     | 
    
         
            +
                    val = stats_sample_get_value(sd->sample, i);
         
     | 
| 
      
 715 
     | 
    
         
            +
                    rb_yield_values(2, key, LONG2FIX(val));
         
     | 
| 
      
 716 
     | 
    
         
            +
                }
         
     | 
| 
      
 717 
     | 
    
         
            +
             
     | 
| 
      
 718 
     | 
    
         
            +
                return self;
         
     | 
| 
      
 719 
     | 
    
         
            +
            }
         
     | 
| 
      
 720 
     | 
    
         
            +
             
     | 
| 
      
 721 
     | 
    
         
            +
             
     | 
| 
      
 722 
     | 
    
         
            +
             
     | 
| 
      
 723 
     | 
    
         
            +
            /******************************************************************
         
     | 
| 
      
 724 
     | 
    
         
            +
             *
         
     | 
| 
      
 725 
     | 
    
         
            +
             *  Module initialization
         
     | 
| 
      
 726 
     | 
    
         
            +
             *
         
     | 
| 
      
 727 
     | 
    
         
            +
             */
         
     | 
| 
      
 728 
     | 
    
         
            +
             
     | 
| 
       534 
729 
     | 
    
         
             
            void Init_stats()
         
     | 
| 
       535 
730 
     | 
    
         
             
            {
         
     | 
| 
       536 
731 
     | 
    
         
             
                stats_class = rb_define_class("Stats", rb_cObject);
         
     | 
| 
       537 
732 
     | 
    
         
             
                rb_define_singleton_method(stats_class, "new", rbstats_new, 1);
         
     | 
| 
       538 
733 
     | 
    
         
             
                rb_define_method(stats_class, "initialize", rbstats_init, 1);
         
     | 
| 
      
 734 
     | 
    
         
            +
                rb_define_method(stats_class, "sample", rbstats_sample, 0);
         
     | 
| 
       539 
735 
     | 
    
         
             
                rb_define_method(stats_class, "get", rbstats_get, 1);
         
     | 
| 
       540 
736 
     | 
    
         
             
                rb_define_method(stats_class, "timer", rbstats_get_tmr, 1);
         
     | 
| 
       541 
737 
     | 
    
         
             
                rb_define_method(stats_class, "inc", rbstats_inc, 1);
         
     | 
| 
         @@ -548,10 +744,18 @@ void Init_stats() 
     | 
|
| 
       548 
744 
     | 
    
         
             
                rb_define_method(ctr_class, "add", rbctr_add, 1);
         
     | 
| 
       549 
745 
     | 
    
         
             
                rb_define_method(ctr_class, "set", rbctr_set, 1);
         
     | 
| 
       550 
746 
     | 
    
         
             
                rb_define_method(ctr_class, "clr", rbctr_clr, 0);
         
     | 
| 
      
 747 
     | 
    
         
            +
                rb_define_method(ctr_class, "get", rbctr_get, 0);
         
     | 
| 
       551 
748 
     | 
    
         | 
| 
       552 
749 
     | 
    
         
             
                tmr_class = rb_define_class("Timer", rb_cObject);
         
     | 
| 
       553 
750 
     | 
    
         
             
                rb_define_method(tmr_class, "enter", rbtmr_enter, 0);
         
     | 
| 
       554 
751 
     | 
    
         
             
                rb_define_method(tmr_class, "exit", rbtmr_exit, 0);
         
     | 
| 
       555 
752 
     | 
    
         
             
                rb_define_method(tmr_class, "time", rbtmr_time, 0);
         
     | 
| 
      
 753 
     | 
    
         
            +
             
     | 
| 
      
 754 
     | 
    
         
            +
                sample_class = rb_define_class("Sample", rb_cObject);
         
     | 
| 
      
 755 
     | 
    
         
            +
                rb_define_method(sample_class, "keys", rbsample_keys, 0);
         
     | 
| 
      
 756 
     | 
    
         
            +
                rb_define_method(sample_class, "time", rbsample_time, 0);
         
     | 
| 
      
 757 
     | 
    
         
            +
                rb_define_method(sample_class, "count", rbsample_count, 0);
         
     | 
| 
      
 758 
     | 
    
         
            +
                rb_define_method(sample_class, "each", rbsample_each, 0);
         
     | 
| 
      
 759 
     | 
    
         
            +
                rb_define_method(sample_class, "[]", rbsample_get, 1);
         
     | 
| 
       556 
760 
     | 
    
         
             
            }
         
     | 
| 
       557 
761 
     | 
    
         | 
    
        data/fast-stats.gemspec
    CHANGED
    
    | 
         @@ -2,8 +2,10 @@ require './lib/stats/version' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       4 
4 
     | 
    
         
             
              s.name = "fast-stats"
         
     | 
| 
      
 5 
     | 
    
         
            +
              s.licenses = ["BSD-3"]
         
     | 
| 
       5 
6 
     | 
    
         
             
              s.version = StatsGem::VERSION
         
     | 
| 
       6 
7 
     | 
    
         
             
              s.authors = ["Alan Pearson"]
         
     | 
| 
      
 8 
     | 
    
         
            +
              s.homepage = "https://github.com/pearsonalan/stats"
         
     | 
| 
       7 
9 
     | 
    
         
             
              s.date = Time.now.utc.strftime("%Y-%m-%d")
         
     | 
| 
       8 
10 
     | 
    
         
             
              s.extensions = ["ext/stats/extconf.rb"]
         
     | 
| 
       9 
11 
     | 
    
         
             
              s.files = `git ls-files .`.split("\n")
         
     | 
| 
         @@ -13,5 +15,6 @@ Gem::Specification.new do |s| 
     | 
|
| 
       13 
15 
     | 
    
         
             
              s.test_files = `git ls-files spec examples`.split("\n")
         
     | 
| 
       14 
16 
     | 
    
         
             
              s.required_ruby_version = ">= 1.9.3"
         
     | 
| 
       15 
17 
     | 
    
         
             
              s.summary = "stats monitoring"
         
     | 
| 
      
 18 
     | 
    
         
            +
              s.description = "fast-stats is a SysV IPC based stats tracking tool. Counters are stored in shared memory, so updating or reading the counter is quite fast"
         
     | 
| 
       16 
19 
     | 
    
         
             
            end
         
     | 
| 
       17 
20 
     | 
    
         | 
    
        data/lib/stats/version.rb
    CHANGED
    
    
    
        data/test/test_stats.rb
    CHANGED
    
    | 
         @@ -6,6 +6,24 @@ puts "TEST STATS: version is #{Stats.version}" 
     | 
|
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            s = Stats.new("rubytest")
         
     | 
| 
       8 
8 
     | 
    
         
             
            ctr = s.get("ctr")
         
     | 
| 
      
 9 
     | 
    
         
            +
            ctr.clr
         
     | 
| 
       9 
10 
     | 
    
         
             
            ctr.inc
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
            raise "unexpected value" unless ctr.get == 1
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            d = s.sample
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            # puts "Sample is #{d.inspect}"
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            raise "unexpected sample count" unless d.count == 1
         
     | 
| 
      
 19 
     | 
    
         
            +
            raise "unexpected sample keys" unless d.keys == ['ctr']
         
     | 
| 
      
 20 
     | 
    
         
            +
            raise "unexpected sample value" unless d['ctr'] == 1
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            h = Hash.new
         
     | 
| 
      
 23 
     | 
    
         
            +
            d.each do |k,v|
         
     | 
| 
      
 24 
     | 
    
         
            +
              h[k] = v
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            raise "unexpected sample data" unless h == {"ctr" => 1}
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
       11 
29 
     | 
    
         
             
            puts "TEST STATS: OK"
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,16 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: fast-stats
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: '1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: '1.9'
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Alan Pearson
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-10-17 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
     | 
    
         
            -
            description: 
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: fast-stats is a SysV IPC based stats tracking tool. Counters are stored
         
     | 
| 
      
 14 
     | 
    
         
            +
              in shared memory, so updating or reading the counter is quite fast
         
     | 
| 
       14 
15 
     | 
    
         
             
            email: 
         
     | 
| 
       15 
16 
     | 
    
         
             
            executables: []
         
     | 
| 
       16 
17 
     | 
    
         
             
            extensions:
         
     | 
| 
         @@ -19,23 +20,16 @@ extra_rdoc_files: [] 
     | 
|
| 
       19 
20 
     | 
    
         
             
            files:
         
     | 
| 
       20 
21 
     | 
    
         
             
            - Makefile
         
     | 
| 
       21 
22 
     | 
    
         
             
            - ext/stats/.gitignore
         
     | 
| 
       22 
     | 
    
         
            -
            - ext/stats/extconf.rb
         
     | 
| 
       23 
     | 
    
         
            -
            - ext/stats/stats-ruby.c
         
     | 
| 
       24 
     | 
    
         
            -
            - fast-stats.gemspec
         
     | 
| 
       25 
     | 
    
         
            -
            - lib/stats.rb
         
     | 
| 
       26 
     | 
    
         
            -
            - lib/stats/version.rb
         
     | 
| 
       27 
     | 
    
         
            -
            - test/benchmark_stats.rb
         
     | 
| 
       28 
     | 
    
         
            -
            - test/test_stats.rb
         
     | 
| 
       29 
23 
     | 
    
         
             
            - ext/stats/error.c
         
     | 
| 
      
 24 
     | 
    
         
            +
            - ext/stats/extconf.rb
         
     | 
| 
       30 
25 
     | 
    
         
             
            - ext/stats/hash.c
         
     | 
| 
       31 
26 
     | 
    
         
             
            - ext/stats/lock.c
         
     | 
| 
       32 
27 
     | 
    
         
             
            - ext/stats/mt19937.c
         
     | 
| 
      
 28 
     | 
    
         
            +
            - ext/stats/mt19937.h
         
     | 
| 
       33 
29 
     | 
    
         
             
            - ext/stats/semaphore.c
         
     | 
| 
       34 
30 
     | 
    
         
             
            - ext/stats/shared_mem.c
         
     | 
| 
      
 31 
     | 
    
         
            +
            - ext/stats/stats-ruby.c
         
     | 
| 
       35 
32 
     | 
    
         
             
            - ext/stats/stats.c
         
     | 
| 
       36 
     | 
    
         
            -
            - ext/stats/strlcat.c
         
     | 
| 
       37 
     | 
    
         
            -
            - ext/stats/strlcpy.c
         
     | 
| 
       38 
     | 
    
         
            -
            - ext/stats/mt19937.h
         
     | 
| 
       39 
33 
     | 
    
         
             
            - ext/stats/stats/debug.h
         
     | 
| 
       40 
34 
     | 
    
         
             
            - ext/stats/stats/error.h
         
     | 
| 
       41 
35 
     | 
    
         
             
            - ext/stats/stats/hash.h
         
     | 
| 
         @@ -44,8 +38,16 @@ files: 
     | 
|
| 
       44 
38 
     | 
    
         
             
            - ext/stats/stats/semaphore.h
         
     | 
| 
       45 
39 
     | 
    
         
             
            - ext/stats/stats/shared_mem.h
         
     | 
| 
       46 
40 
     | 
    
         
             
            - ext/stats/stats/stats.h
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
            - ext/stats/strlcat.c
         
     | 
| 
      
 42 
     | 
    
         
            +
            - ext/stats/strlcpy.c
         
     | 
| 
      
 43 
     | 
    
         
            +
            - fast-stats.gemspec
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/stats.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            - lib/stats/version.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - test/benchmark_stats.rb
         
     | 
| 
      
 47 
     | 
    
         
            +
            - test/test_stats.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
            homepage: https://github.com/pearsonalan/stats
         
     | 
| 
      
 49 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 50 
     | 
    
         
            +
            - BSD-3
         
     | 
| 
       49 
51 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       50 
52 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       51 
53 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
         @@ -53,17 +55,17 @@ require_paths: 
     | 
|
| 
       53 
55 
     | 
    
         
             
            - lib
         
     | 
| 
       54 
56 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       55 
57 
     | 
    
         
             
              requirements:
         
     | 
| 
       56 
     | 
    
         
            -
              - -  
     | 
| 
      
 58 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       57 
59 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       58 
60 
     | 
    
         
             
                  version: 1.9.3
         
     | 
| 
       59 
61 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       60 
62 
     | 
    
         
             
              requirements:
         
     | 
| 
       61 
     | 
    
         
            -
              - -  
     | 
| 
      
 63 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       62 
64 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       63 
65 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       64 
66 
     | 
    
         
             
            requirements: []
         
     | 
| 
       65 
67 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       66 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 68 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       67 
69 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       68 
70 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       69 
71 
     | 
    
         
             
            summary: stats monitoring
         
     |