Class: Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/stats.rb,
ext/stats/stats-ruby.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
# File 'ext/stats/stats-ruby.c', line 217

static VALUE rbstats_init(VALUE self, VALUE name)
{
    struct rbstats *stats;

    Check_Type(name, T_STRING);
    Data_Get_Struct(self, struct rbstats, stats);

    stats->stats = open_stats(RSTRING_PTR(name));

    return self;
}

Class Method Details

.new(name) ⇒ Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'ext/stats/stats-ruby.c', line 200

VALUE rbstats_new(VALUE class, VALUE name)
{
    struct rbstats *stats;
    VALUE tdata;

    Check_Type(name, T_STRING);

    stats = (struct rbstats *)malloc(sizeof(struct rbstats));
    memset(stats,0,sizeof(struct rbstats));
    stats->magic = STATS_MAGIC;

    tdata = Data_Wrap_Struct(class, 0, rbstats_free, stats);
    rb_obj_call_init(tdata, 1, &name);

    return tdata;
}

.versionObject



5
6
7
# File 'lib/stats.rb', line 5

def self.version
  StatsGem::VERSION
end

Instance Method Details

#add(rbkey, amt) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'ext/stats/stats-ruby.c', line 337

static VALUE rbstats_add(VALUE self, VALUE rbkey, VALUE amt)
{
    struct rbstats *stats;
    struct stats_counter *counter;
    VALUE ret = Qnil;

    Check_Type(amt,T_FIXNUM);

    stats = rbstats_get_wrapped_stats(self);
    if (stats)
    {
        counter = rbstats_get_counter(stats, rbkey);
        if (counter)
        {
            counter_increment_by(counter,FIX2LONG(amt));
            ret = Qtrue;
        }
    }

    return ret;
}

#clr(rbkey) ⇒ Object



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'ext/stats/stats-ruby.c', line 381

static VALUE rbstats_clr(VALUE self, VALUE rbkey)
{
    struct rbstats *stats;
    struct stats_counter *counter;
    VALUE ret = Qnil;

    stats = rbstats_get_wrapped_stats(self);
    if (stats)
    {
        counter = rbstats_get_counter(stats, rbkey);
        if (counter)
        {
            counter_clear(counter);
            ret = Qtrue;
        }
    }

    return ret;
}

#get(rbkey) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'ext/stats/stats-ruby.c', line 276

static VALUE rbstats_get(VALUE self, VALUE rbkey)
{
    struct rbstats *stats;
    struct stats_counter *counter;
    VALUE ret = Qnil;

    stats = rbstats_get_wrapped_stats(self);
    if (stats)
    {
        counter = rbstats_get_counter(stats, rbkey);
        if (counter)
        {
            ret = rbctr_alloc(counter);
        }
    }

    return ret;
}

#inc(rbkey) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'ext/stats/stats-ruby.c', line 315

static VALUE rbstats_inc(VALUE self, VALUE rbkey)
{
    struct rbstats *stats;
    struct stats_counter *counter;
    VALUE ret = Qnil;

    stats = rbstats_get_wrapped_stats(self);
    if (stats)
    {
        counter = rbstats_get_counter(stats, rbkey);
        if (counter)
        {
            counter_increment(counter);
            ret = Qtrue;
        }
    }

    return ret;
}

#sampleObject



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'ext/stats/stats-ruby.c', line 402

static VALUE rbstats_sample(VALUE self)
{
    struct rbstats *stats;
    struct stats_counter_list *cl = NULL;
    struct stats_sample *sample = NULL;
    VALUE ret = Qnil;

    stats = rbstats_get_wrapped_stats(self);
    if (!stats)
        goto exit;

    if (stats_cl_create(&cl) != S_OK)
        goto exit;

    if (stats_get_counter_list(stats->stats, cl) != S_OK)
        goto exit;

    if (stats_sample_create(&sample) != S_OK)
        goto exit;

    if (stats_get_sample(stats->stats, cl, sample) != S_OK)
        goto exit;

    ret = rbsample_alloc(cl, sample);
    if (ret != Qnil)
    {
        cl = NULL;
        sample = NULL;
    }

exit:
    if (cl != NULL)
    {
        stats_cl_free(cl);
    }

    if (sample != NULL)
    {
        stats_sample_free(sample);
    }

    return ret;
}

#set(rbkey, amt) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'ext/stats/stats-ruby.c', line 359

static VALUE rbstats_set(VALUE self, VALUE rbkey, VALUE amt)
{
    struct rbstats *stats;
    struct stats_counter *counter;
    VALUE ret = Qnil;

    Check_Type(amt,T_FIXNUM);

    stats = rbstats_get_wrapped_stats(self);
    if (stats)
    {
        counter = rbstats_get_counter(stats, rbkey);
        if (counter)
        {
            counter_set(counter,FIX2LONG(amt));
            ret = Qtrue;
        }
    }

    return ret;
}

#timer(rbkey) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'ext/stats/stats-ruby.c', line 296

static VALUE rbstats_get_tmr(VALUE self, VALUE rbkey)
{
    struct rbstats *stats;
    struct stats_counter *counter;
    VALUE ret = Qnil;

    stats = rbstats_get_wrapped_stats(self);
    if (stats)
    {
        counter = rbstats_get_counter(stats, rbkey);
        if (counter)
        {
            ret = rbtmr_alloc(counter);
        }
    }

    return ret;
}