Class: Pacct::Entry
- Inherits:
-
Object
- Object
- Pacct::Entry
- Defined in:
- ext/pacct/pacct_c.c,
ext/pacct/pacct_c.c
Overview
Represents an entry in a Pacct::File
Class Method Summary collapse
-
.new ⇒ Object
This is the version of pacct_entry_new that is actually exposed to Ruby.
Instance Method Summary collapse
-
#command_name ⇒ Object
Returns the first 15 characters of the command name.
-
#command_name=(name) ⇒ Object
Sets the first 15 characters of the command name.
-
#cpu_time ⇒ Object
Returns the task’s total CPU time in seconds.
-
#exit_code ⇒ Object
Returns the command’s exit code.
-
#exit_code=(value) ⇒ Object
Sets the command’s exit code.
-
#group_id ⇒ Object
Returns the group ID of the user who executed the command.
-
#group_name ⇒ Object
Returns the group name of the user who executed the command.
-
#group_name=(name) ⇒ Object
Sets the group name of the user who executed the command.
-
#memory ⇒ Object
Returns the task’s average memory usage in kilobytes.
-
#memory=(value) ⇒ Object
Sets the task’s average memory usage in kilobytes.
-
#process_id ⇒ Object
Returns the process ID.
-
#process_id=(pid) ⇒ Object
Sets the process ID.
-
#start_time ⇒ Object
Returns the task’s start time.
-
#start_time=(value) ⇒ Object
Sets the task’s start time.
-
#system_time ⇒ Object
Returns the task’s total system CPU time in seconds.
-
#system_time=(value) ⇒ Object
Sets the task’s total system CPU time.
-
#user_id ⇒ Object
Returns the ID of the user who executed the command.
-
#user_name ⇒ Object
Returns the name of the user who executed the command.
-
#user_name=(name) ⇒ Object
Sets the name of the user who executed the command.
-
#user_time ⇒ Object
Returns the task’s total user CPU time in seconds.
-
#user_time=(value) ⇒ Object
Sets the task’s total user CPU time.
-
#wall_time ⇒ Object
Returns the task’s total wall time in seconds.
-
#wall_time=(value) ⇒ Object
Sets the task’s total wall time.
Class Method Details
.new ⇒ Object
This is the version of pacct_entry_new that is actually exposed to Ruby.
230 231 232 |
# File 'ext/pacct/pacct_c.c', line 230 static VALUE ruby_pacct_entry_new(VALUE self) { return pacct_entry_new(NULL); } |
Instance Method Details
#command_name ⇒ Object
Returns the first 15 characters of the command name
654 655 656 657 658 659 |
# File 'ext/pacct/pacct_c.c', line 654
static VALUE get_command_name(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return rb_str_new2(data->ac_comm);
}
|
#command_name=(name) ⇒ Object
Sets the first 15 characters of the command name
664 665 666 667 668 669 670 671 672 |
# File 'ext/pacct/pacct_c.c', line 664
static VALUE set_command_name(VALUE self, VALUE name) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
strncpy(data->ac_comm, StringValueCStr(name), ACCT_COMM - 1);
data->ac_comm[ACCT_COMM - 1] = '\0';
return Qnil;
}
|
#cpu_time ⇒ Object
Returns the task’s total CPU time in seconds
577 578 579 580 581 582 |
# File 'ext/pacct/pacct_c.c', line 577
static VALUE get_cpu_time(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM((comp_t_to_ulong(data->ac_utime) + comp_t_to_ulong(data->ac_stime)) / ticksPerSecond);
}
|
#exit_code ⇒ Object
Returns the command’s exit code
677 678 679 680 681 682 |
# File 'ext/pacct/pacct_c.c', line 677
static VALUE get_exit_code(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM(data->ac_exitcode);
}
|
#exit_code=(value) ⇒ Object
Sets the command’s exit code
687 688 689 690 691 692 693 694 |
# File 'ext/pacct/pacct_c.c', line 687
static VALUE set_exit_code(VALUE self, VALUE value) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_exitcode = NUM2UINT(value);
return Qnil;
}
|
#group_id ⇒ Object
Returns the group ID of the user who executed the command
450 451 452 453 454 455 |
# File 'ext/pacct/pacct_c.c', line 450
static VALUE get_group_id(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM(data->ac_gid);
}
|
#group_name ⇒ Object
Returns the group name of the user who executed the command
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'ext/pacct/pacct_c.c', line 460
static VALUE get_group_name(VALUE self) {
struct acct_v3* data;
struct group* group_data;
VALUE name, id;
Data_Get_Struct(self, struct acct_v3, data);
id = UINT2NUM(data->ac_gid);
name = rb_hash_aref(known_groups_by_id, id);
if(name != Qnil) {
return name;
}
errno = 0;
group_data = getgrgid(data->ac_gid);
if(!group_data) {
char buf[512];
VALUE err;
int e = errno;
snprintf(buf, 512, "Unable to obtain group name for ID %u", data->ac_gid);
if(e == 0) {
e = ENODATA;
}
err = rb_funcall(cSystemCallError, id_new, 2, rb_str_new2(buf), INT2NUM(e));
rb_exc_raise(err);
}
name = rb_str_new2(group_data->gr_name);
rb_hash_aset(known_groups_by_id, id, name);
return name;
}
|
#group_name=(name) ⇒ Object
Sets the group name of the user who executed the command
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'ext/pacct/pacct_c.c', line 495
static VALUE set_group_name(VALUE self, VALUE name) {
struct acct_v3* data;
struct group* group_data;
VALUE id;
char* c_name = StringValueCStr(name);
Data_Get_Struct(self, struct acct_v3, data);
id = rb_hash_aref(known_groups_by_name, name);
if(id != Qnil) {
data->ac_gid = NUM2UINT(id);
return Qnil;
}
errno = 0;
group_data = getgrnam(c_name);
if(!group_data) {
char buf[512];
VALUE err;
int e = errno;
snprintf(buf, 512, "Unable to obtain group ID for name '%s'", c_name);
if(e == 0) {
e = ENODATA;
}
err = rb_funcall(cSystemCallError, id_new, 2, rb_str_new2(buf), INT2NUM(e));
rb_exc_raise(err);
}
id = UINT2NUM(group_data->gr_gid);
rb_hash_aset(known_groups_by_name, name, id);
data->ac_gid = group_data->gr_gid;
return Qnil;
}
|
#memory ⇒ Object
Returns the task’s average memory usage in kilobytes
631 632 633 634 635 636 637 |
# File 'ext/pacct/pacct_c.c', line 631
static VALUE get_average_mem_usage(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
//Why divided by page size?
return INT2NUM(comp_t_to_ulong(data->ac_mem) * 1024 / pageSize);
}
|
#memory=(value) ⇒ Object
Sets the task’s average memory usage in kilobytes
642 643 644 645 646 647 648 649 |
# File 'ext/pacct/pacct_c.c', line 642
static VALUE set_average_mem_usage(VALUE self, VALUE value) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_mem = ulong_to_comp_t(NUM2ULONG(value) * pageSize / 1024);
return Qnil;
}
|
#process_id ⇒ Object
Returns the process ID
342 343 344 345 346 347 |
# File 'ext/pacct/pacct_c.c', line 342
static VALUE get_process_id(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM(data->ac_pid);
}
|
#process_id=(pid) ⇒ Object
Sets the process ID
352 353 354 355 356 357 358 359 |
# File 'ext/pacct/pacct_c.c', line 352
static VALUE set_process_id(VALUE self, VALUE pid) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_pid = NUM2UINT(pid);
return Qnil;
}
|
#start_time ⇒ Object
Returns the task’s start time
609 610 611 612 613 614 |
# File 'ext/pacct/pacct_c.c', line 609
static VALUE get_start_time(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return rb_funcall(cTime, id_at, 1, INT2NUM(data->ac_btime));
}
|
#start_time=(value) ⇒ Object
Sets the task’s start time
619 620 621 622 623 624 625 626 |
# File 'ext/pacct/pacct_c.c', line 619
static VALUE set_start_time(VALUE self, VALUE value) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_btime = NUM2UINT(rb_funcall(value, id_to_i, 0));
return Qnil;
}
|
#system_time ⇒ Object
Returns the task’s total system CPU time in seconds
555 556 557 558 559 560 |
# File 'ext/pacct/pacct_c.c', line 555
static VALUE get_system_time(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM(comp_t_to_ulong(data->ac_stime) / ticksPerSecond);
}
|
#system_time=(value) ⇒ Object
Sets the task’s total system CPU time
565 566 567 568 569 570 571 572 |
# File 'ext/pacct/pacct_c.c', line 565
static VALUE set_system_time(VALUE self, VALUE value) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_stime = ulong_to_comp_t(NUM2ULONG(value) * ticksPerSecond);
return Qnil;
}
|
#user_id ⇒ Object
Returns the ID of the user who executed the command
364 365 366 367 368 369 |
# File 'ext/pacct/pacct_c.c', line 364
static VALUE get_user_id(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM(data->ac_uid);
}
|
#user_name ⇒ Object
Returns the name of the user who executed the command
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'ext/pacct/pacct_c.c', line 374
static VALUE get_user_name(VALUE self) {
struct acct_v3* data;
struct passwd* pw_data;
VALUE id, name;
Data_Get_Struct(self, struct acct_v3, data);
//If there's a cached user name, return it.
id = UINT2NUM(data->ac_uid);
name = rb_hash_aref(known_users_by_id, id);
if(name != Qnil) {
return name;
}
//Otherwise, get the user name from the OS.
errno = 0;
pw_data = getpwuid(data->ac_uid);
if(!pw_data) {
char buf[512];
VALUE err;
int e = errno;
snprintf(buf, 512, "Unable to obtain user name for ID %u", data->ac_uid);
if(e == 0) {
e = ENODATA;
}
err = rb_funcall(cSystemCallError, id_new, 2, rb_str_new2(buf), INT2NUM(e));
rb_exc_raise(err);
}
//Cache the user name.
name = rb_str_new2(pw_data->pw_name);
rb_hash_aset(known_users_by_id, id, name);
return name;
}
|
#user_name=(name) ⇒ Object
Sets the name of the user who executed the command
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 445 |
# File 'ext/pacct/pacct_c.c', line 412
static VALUE set_user_name(VALUE self, VALUE name) {
struct acct_v3* data;
struct passwd* pw_data;
char* c_name = StringValueCStr(name);
VALUE id;
Data_Get_Struct(self, struct acct_v3, data);
id = rb_hash_aref(known_users_by_name, name);
if(id != Qnil) {
data->ac_uid = NUM2UINT(id);
return Qnil;
}
errno = 0;
pw_data = getpwnam(c_name);
if(!pw_data) {
char buf[512];
VALUE err;
int e = errno;
snprintf(buf, 512, "Unable to obtain user ID for name '%s'", c_name);
if(e == 0) {
e = ENODATA;
}
err = rb_funcall(cSystemCallError, id_new, 2, rb_str_new2(buf), INT2NUM(e));
rb_exc_raise(err);
}
id = UINT2NUM(pw_data->pw_uid);
rb_hash_aset(known_users_by_name, name, id);
data->ac_uid = pw_data->pw_uid;
return Qnil;
}
|
#user_time ⇒ Object
Returns the task’s total user CPU time in seconds
533 534 535 536 537 538 |
# File 'ext/pacct/pacct_c.c', line 533
static VALUE get_user_time(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return INT2NUM(comp_t_to_ulong(data->ac_utime) / ticksPerSecond);
}
|
#user_time=(value) ⇒ Object
Sets the task’s total user CPU time
543 544 545 546 547 548 549 550 |
# File 'ext/pacct/pacct_c.c', line 543
static VALUE set_user_time(VALUE self, VALUE value) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_utime = ulong_to_comp_t(NUM2ULONG(value) * ticksPerSecond);
return Qnil;
}
|
#wall_time ⇒ Object
Returns the task’s total wall time in seconds
587 588 589 590 591 592 |
# File 'ext/pacct/pacct_c.c', line 587
static VALUE get_wall_time(VALUE self) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
return rb_float_new(data->ac_etime);
}
|
#wall_time=(value) ⇒ Object
Sets the task’s total wall time
597 598 599 600 601 602 603 604 |
# File 'ext/pacct/pacct_c.c', line 597
static VALUE set_wall_time(VALUE self, VALUE value) {
struct acct_v3* data;
Data_Get_Struct(self, struct acct_v3, data);
data->ac_etime = NUM2DBL(value);
return Qnil;
}
|