void render_video(void *hrender, AVFrame *video) { RENDER *render = (RENDER*)hrender; AVFrame picture; // init picture memset(&picture, 0, sizeof(AVFrame)); if (!render || !render->vdev) return; do { VDEV_COMMON_CTXT *vdev = (VDEV_COMMON_CTXT*)render->vdev; if ( render->render_xcur != render->render_xnew || render->render_ycur != render->render_ynew || render->render_wcur != render->render_wnew || render->render_hcur != render->render_hnew ) { render->render_xcur = render->render_xnew; render->render_ycur = render->render_ynew; render->render_wcur = render->render_wnew; render->render_hcur = render->render_hnew; // vdev set rect vdev_setrect(render->vdev, render->render_xcur, render->render_ycur, render->render_wcur, render->render_hcur); // we need recreate sws if (!render->sws_context) { sws_freeContext(render->sws_context); } render->sws_context = sws_getContext( render->video_width, render->video_height, render->pixel_fmt, vdev->sw, vdev->sh, (AVPixelFormat)vdev->pixfmt, SWS_FAST_BILINEAR, 0, 0, 0); } if (video->format == AV_PIX_FMT_DXVA2_VLD) { vdev_setparam(render->vdev, PARAM_VDEV_POST_SURFACE, video); } else { vdev_lock(render->vdev, picture.data, picture.linesize); if (picture.data[0] && video->pts != -1) { sws_scale(render->sws_context, video->data, video->linesize, 0, render->video_height, picture.data, picture.linesize); } vdev_unlock(render->vdev, video->pts); } #if CONFIG_ENABLE_SNAPSHOT if (render->render_status & RENDER_SNAPSHOT) { int ret = take_snapshot(render->snapfile, render->snapwidth, render->snapheight, video); player_send_message(((VDEV_COMMON_CTXT*)render->vdev)->surface, MSG_TAKE_SNAPSHOT, 0); render->render_status &= ~RENDER_SNAPSHOT; } #endif //++ seek step if (render->render_status & RENDER_SEEKSTEP) { render->render_status &= ~RENDER_SEEKSTEP; break; } //-- seek step } while (render->render_status & RENDER_PAUSE); }
static void hlfs_get_all_snapshots_setup(Fixture *fixture, const void *data) { const char *test_dir = (const char *)data; g_print("test env dir is %s\n", test_dir); char *fs_dir = g_build_filename(test_dir, "testfs", NULL); // g_assert(g_mkdir(fs_dir, 0700) == 0); char *uri = g_malloc0(128); g_assert(uri != NULL); snprintf(uri, 128, "%s%s", "local://", fs_dir); // char *uri = g_build_path(tmp, fs_dir, NULL); g_print("uri is %s\n", uri); pid_t status; const char cmd[256]; memset((char *) cmd, 0, 256); sprintf((char *) cmd, "%s %s %s %s %d %s %d %s %d", "../mkfs.hlfs", "-u", uri, "-b", 8192, "-s", 67108864, "-m", 1024); g_message("cmd is [%s]", cmd); status = system(cmd); #if 0 GKeyFile *sb_keyfile = g_key_file_new(); g_key_file_set_string(sb_keyfile, "METADATA", "uri", uri); g_key_file_set_integer(sb_keyfile, "METADATA", "block_size", 8196); g_key_file_set_integer(sb_keyfile, "METADATA", \ "segment_size", 67108864); g_key_file_set_integer(sb_keyfile, "METADATA", \ "max_fs_size", 671088640); gchar *content = g_key_file_to_data(sb_keyfile, NULL, NULL); char *sb_file_path = g_build_filename(fs_dir, "superblock", NULL); g_print("sb file path is %s\n", sb_file_path); GError *error = NULL; if (TRUE != g_file_set_contents(sb_file_path, content, \ strlen(content) + 1, &error)) { g_print("error msg is %s", error->message); error = NULL; } #endif fixture->uri = uri; g_print("fixture->uri is %s\n", fixture->uri); fixture->ctrl = init_hlfs(fixture->uri); g_assert(fixture->ctrl != NULL); int ret = hlfs_open(fixture->ctrl, 1); g_assert(ret == 0); take_snapshot(fixture, data); // test_hlfs_find_inode_before_time(fixture, data); // g_key_file_free(sb_keyfile); // g_free(sb_file_path); g_free(fs_dir); return ; }
void snapshot_command(snapshot *snapshot_head, entry *entry_head, int *latest_snapshotID) { STATUS snapshot_status = take_snapshot(snapshot_head, entry_head, latest_snapshotID); switch(snapshot_status) { case OK: printf("saved as snapshot %d\n", *latest_snapshotID-1); break; default: printf("Whoops! (snapshot_command: %d)", snapshot_status); break; } }
void aosd_show(Aosd* aosd) { if (aosd == NULL || aosd->shown) return; if (aosd->mode == TRANSPARENCY_FAKE) { if (aosd->background.set) { XFreePixmap(aosd->display, aosd->background.pixmap); aosd->background.set = False; } aosd->background.pixmap = take_snapshot(aosd); aosd->background.set = True; } aosd_render(aosd); XMapRaised(aosd->display, aosd->win); aosd->shown = True; }
Snapshot_dialog::Snapshot_dialog( SoQtRenderArea* render_area, QWidget* parent, const char* name ) : Snapshot_dialog_base( parent, name, false ), render_area_( render_area ) { file_chooser_box_->setOrientation( Qt::Horizontal ); file_chooser_box_->setColumns( 1 ); file_chooser_ = new FileChooser( file_chooser_box_, "file_chooser" ); file_chooser_->setMode( FileChooser::Any ); filter_chooser_->insertItem( "PNG (*.png)" ); filter_chooser_->insertItem( "PostScript (*.ps)" ); filter_chooser_->insertItem( "BMP (*.bmp)" ); filter_chooser_->insertItem( "PPM (*.ppm)" ); QObject::connect( snapshot_button_, SIGNAL( clicked() ), this, SLOT( take_snapshot() ) ); QObject::connect( close_button_, SIGNAL( clicked() ), this, SLOT( accept() ) ); }
void Snapshot_dialog::take_snapshot() { if( file_chooser_->fileName().isEmpty() ) return; QString filename = file_chooser_->fileName(); QString format = filter_chooser_->currentText(); //TL modified if (format.contains("PNG") && (!filename.endsWith(".png",false))) filename += ".png"; if (format.contains("BMP") && (!filename.endsWith(".bmp",false))) filename += ".bmp"; if (format.contains("PostScript") && (!filename.endsWith(".ps",false))) filename += ".ps"; if (format.contains("PPM") && (!filename.endsWith(".ppm",false))) filename += ".ppm"; std::ofstream of("a.txt"); of << format << "," << filename << std::endl; of.close(); take_snapshot( filename, format ); QSound::play( "shutter.wav" ); }
/* * The guts of the module, this routine gets called to service a request */ unsigned char * var_extensible_vmstat(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { /* * Needed for returning the values */ static long long_ret; static char errmsg[300]; /* * set to 0 as default */ long_ret = 0; /* * generic check whether the options passed make sense and whether the */ /* * right variable is requested */ if (header_generic(vp, name, length, exact, var_len, write_method) != MATCH_SUCCEEDED) { return (NULL); } /* * The function that actually returns s.th. */ switch (vp->magic) { case MIBINDEX: long_ret = 1; return ((u_char *) (&long_ret)); case ERRORNAME: /* dummy name */ sprintf(errmsg, "systemStats"); *var_len = strlen(errmsg); return ((u_char *) (errmsg)); case SWAPIN: return ((u_char *) (&swapin)); case SWAPOUT: return ((u_char *) (&swapout)); case IOSENT: return ((u_char *) (&blocks_write)); case IORECEIVE: return ((u_char *) (&blocks_read)); case SYSINTERRUPTS: return ((u_char *) (&interrupts)); case SYSCONTEXT: return ((u_char *) (&context_sw)); case CPUUSER: return ((u_char *) (&cpu_perc[V_CPU_USER])); case CPUSYSTEM: return ((u_char *) (&cpu_perc[V_CPU_SYSTEM])); case CPUIDLE: return ((u_char *) (&cpu_perc[V_CPU_IDLE])); case CPURAWUSER: take_snapshot(&raw_values); /* * LINTED has to be 'long' */ long_ret = (long) (raw_values.css_cpu[V_CPU_USER] / raw_values.css_cpus); return ((u_char *) (&long_ret)); /* * We are missing CPURAWNICE, Dynix does not account for this in the kernel so this OID can not */ /* * be returned. Also, these values will roll over sooner or later and then return inaccurate data */ /* * but the MIB wants Integer32 so we cannot put a counter here */ /* * (Has been changed to Counter32 in the latest MIB version!) */ case CPURAWSYSTEM: take_snapshot(&raw_values); /* * LINTED has to be 'long' */ long_ret = (long) ((raw_values.css_cpu[V_CPU_KERNEL] + raw_values.css_cpu[V_CPU_STREAM]) / raw_values.css_cpus); return ((u_char *) (&long_ret)); case CPURAWIDLE: take_snapshot(&raw_values); /* * LINTED has to be 'long' */ long_ret = (long) (raw_values.css_cpu[V_CPU_IDLE] / raw_values.css_cpus); return ((u_char *) (&long_ret)); case CPURAWWAIT: take_snapshot(&raw_values); /* * LINTED has to be 'long' */ long_ret = (long) (raw_values.css_cpu[V_CPU_STREAM] / raw_values.css_cpus); return ((u_char *) (&long_ret)); case CPURAWKERNEL: take_snapshot(&raw_values); /* * LINTED has to be 'long' */ long_ret = (long) (raw_values.css_cpu[V_CPU_KERNEL] / raw_values.css_cpus); return ((u_char *) (&long_ret)); case IORAWSENT: long_ret = (long) (raw_values.css_blocks_write); return ((u_char *) (&long_ret)); case IORAWRECEIVE: long_ret = (long) (raw_values.css_blocks_read); return ((u_char *) (&long_ret)); /* * reserved for future use */ /* * case ERRORFLAG: * return((u_char *) (&long_ret)); * case ERRORMSG: * return((u_char *) (&long_ret)); */ default: snmp_log(LOG_ERR, "vmstat_dynix: Error in request, no match found.\n"); } return (NULL); } /* *var_extensible_vmstat ends here */
/* * ARGSUSED0 */ static void update_stats(unsigned int registrationNumber, void *clientarg) { /* * The time between the samples we compare */ time_t time_diff; /* * Easier to use these than the snapshots, short hand pointers */ struct cpu_stat_snapshot *css_old, *css_new; /* * The usual stuff to count on, err, by */ int i; /* * The sum of the CPU ticks that have passed on the different CPU states, so we can calculate */ /* * the percentages of each state */ unsigned long long cpu_sum = 0; DEBUGMSGTL(("ucd-snmp/vmstat_dynix.c:update_stats", "updating stats\n")); /* * Take the current snapshot */ if (take_snapshot(&snapshot[0]) == -1) { snmp_log(LOG_WARNING, "vmstat_dynix (update_stats): Something went wrong with take_snapshot."); return; } /* * Do we have some data we can use ? An issue right after the start of the agent */ if (number_of_snapshots > 0) { /* * Huh, the number of CPUs changed during run time. That is indeed s.th. worth noting, we */ /* * output a humorous (more or less) syslog message and need to retake the snapshots */ if (snapshot[0].css_cpus != snapshot[1].css_cpus) { if (snapshot[0].css_cpus > snapshot[1].css_cpus) { snmp_log(LOG_NOTICE, "vmstat_dynix (update_stats): Cool ! Number of CPUs increased, must be hot-pluggable."); } else { snmp_log(LOG_NOTICE, "vmstat_dynix (update_stats): Lost at least one CPU, RIP."); } /* * Make all snapshots but the current one invalid */ number_of_snapshots = 1; /* * Move the current one in the "first" [1] slot */ memmove(&snapshot[1], &snapshot[0], sizeof snapshot[0]); /* * Erase the current one */ memset(&snapshot[0], 0, sizeof snapshot[0]); /* * Try to get a new snapshot in five seconds so we can return s.th. useful */ if (snmp_alarm_register(5, NULL, update_stats, NULL) == 0) { snmp_log(LOG_WARNING, "vmstat_dynix (update_stats): snmp_alarm_register failed.\n"); } return; } /* * Short hand pointers */ css_new = &snapshot[0]; css_old = &snapshot[number_of_snapshots]; /* * How much time has passed between the snapshots we get the values from ? */ /* * Time is in seconds */ time_diff = snapshot[0].css_time - snapshot[number_of_snapshots].css_time; if (time_diff == 0) DEBUGMSGTL(("ucd-snmp/vmstat_dynix.c:update_stats", "time_diff is ZERO... watch for the segfault\n")); DEBUGMSGTL(("ucd-snmp/vmstat_dynix.c:update_stats", "time_diff: %lld\n", time_diff)); /* * swapin and swapout are in pages, MIB wants kB/s,so we just need to get kB and seconds */ /* * For the others we need to get value per second */ /* * decided to use sysconf(_SC_PAGESIZE) instead to get around an #ifndef (I don't like those) */ /* * LINTED cast needed, really */ swapin = (uint_t) ((css_new->css_swapin - css_old->css_swapin) * (time_t) 1000 * sysconf(_SC_PAGESIZE) / 1024 / time_diff); /* * LINTED cast needed, really */ swapout = (uint_t) ((css_new->css_swapout - css_old->css_swapout) * (time_t) 1000 * sysconf(_SC_PAGESIZE) / 1024 / time_diff); /* * LINTED cast needed, really */ blocks_read = (uint_t) ((css_new->css_blocks_read - css_old->css_blocks_read) * (time_t) 1000 / time_diff); /* * LINTED cast needed, really */ blocks_write = (uint_t) ((css_new->css_blocks_write - css_old->css_blocks_write) * (time_t) 1000 / time_diff); /* * LINTED cast needed, really */ interrupts = (uint_t) ((css_new->css_interrupts - css_old->css_interrupts) * (time_t) 1000 / time_diff); /* * LINTED cast needed, really */ context_sw = (uint_t) ((css_new->css_context_sw - css_old->css_context_sw) * (time_t) 1000 / time_diff); /* * Loop thru all the V_CPU_STATES and get the differences */ for (i = 0; i < V_CPU_STATES; i++) { cpu_sum += (css_new->css_cpu[i] - css_old->css_cpu[i]); } /* * Now calculate the absolute percentage values */ /* * Looks somewhat complicated sometimes but tries to get around using floats to increase speed */ for (i = 0; i < V_CPU_STATES; i++) { /* * Since we don't return fractions we use + 0.5 to get between 99 and 101 percent adding the values */ /* * together, otherwise we would get less than 100 most of the time */ /* * LINTED has to be 'long' */ cpu_perc[i] = (long) (((css_new->css_cpu[i] - css_old->css_cpu[i]) * 100 + (cpu_sum / 2)) / cpu_sum); } /* * As said before, MIB wants V_CPU_SYSTEM which is V_CPU_KERNEL + V_CPU_STREAM */ /* * LINTED has to be 'long' */ cpu_perc[V_CPU_SYSTEM] = (long) ((((css_new->css_cpu[V_CPU_KERNEL] - css_old->css_cpu[V_CPU_KERNEL]) + (css_new->css_cpu[V_CPU_STREAM] - css_old->css_cpu[V_CPU_STREAM])) * 100 + (cpu_sum / 2)) / cpu_sum); } /* * Make the current one the first one and move the whole thing one place down */ memmove(&snapshot[1], &snapshot[0], (size_t) (((char *) &snapshot[POLL_VALUES]) - ((char *) &snapshot[0]))); /* * Erase the current one */ memset(&snapshot[0], 0, sizeof snapshot[0]); /* * Only important on start up, we keep track of how many snapshots we have taken so far */ if (number_of_snapshots < POLL_VALUES) { number_of_snapshots++; } } /* update_stats ends here */
void staff_properties_change_cb (GtkAction * action, DenemoScriptParam * param) { GET_4PARAMS (action, param, denemo_name, device_port, midi_prognum, midi_channel); DenemoStaff *staff = (DenemoStaff *) Denemo.project->movement->currentstaff->data; if (query) { if (*query) if (!strcmp ("denemo_name", query)) { g_string_assign (param->string, staff->denemo_name->str); if (staff->subpart) g_string_append_printf (param->string, "_%s", staff->subpart->str); param->status = TRUE; } if (*query) if (!strcmp ("transposition", query)) { g_string_printf (param->string, "%d", staff->transposition); param->status = TRUE; } if (*query) if (!strcmp ("midi_channel", query)) { g_string_printf (param->string, "%d", staff->midi_channel); param->status = TRUE; } if (*query) if (!strcmp ("midi_prognum", query)) { g_string_printf (param->string, "%d", staff->midi_prognum); param->status = TRUE; } if (*query) if (!strcmp ("lily_name", query)) { g_string_assign (param->string, staff->lily_name->str); param->status = TRUE; } return; } take_snapshot (); signal_structural_change (Denemo.project); if (denemo_name) { gboolean ok = TRUE; gchar *name = strtok (denemo_name, "_"); gchar *subpart = strtok (NULL, "_"); if (name) ok = canonicalize_denemo_name (name, staff->denemo_name); else g_string_assign (staff->denemo_name, ""); if (ok && subpart) ok = canonicalize_denemo_name (subpart, staff->subpart); set_lily_name (staff->denemo_name, staff->lily_name); param->status = ok; return; } if (device_port) { g_string_assign (staff->device_port, device_port); param->status = TRUE; return; } if (midi_prognum) { staff->midi_prognum = atoi (midi_prognum); return; } if (midi_channel) { staff->midi_channel = atoi (midi_channel); return; } (void) staff_properties_change (); }
int main(void) { char line[MAX_LINE]; entry *entryHead; //head of entry list snapshot *snapHead; //head of snapshot list entryHead = NULL; snapHead = NULL; while (true) { printf("> "); if (fgets(line, MAX_LINE, stdin) == NULL) { printf("\n"); command_bye(entryHead, snapHead); return 0; } //get command from the input line as well as a second parameter if it exists char *ptr = strtok(line, " "); char firstToken[MAX_COMMAND]; //stores a command strcpy(firstToken, ptr); ptr = strtok(NULL, " "); char secondToken[MAX_KEY]; //stores either a key or a second part of the command secondToken[0] = '\0'; //get rid of a new line character if it exists in the last valid token entered char *newLine; if (ptr != NULL) { strcpy(secondToken, ptr); newLine = strchr(secondToken, '\n'); } else { newLine = strchr(firstToken, '\n'); } if (newLine) { *newLine = 0; } //identify the command and call the right function to execute the command entered if (strcasecmp(firstToken, "BYE") == 0) { command_bye(entryHead, snapHead); return 0; } else if (strcasecmp(firstToken, "HELP") == 0) { command_help(); } else if (strcasecmp(firstToken, "LIST") == 0) { if (strcasecmp(secondToken, "ENTRIES") == 0) { list_entries(entryHead); } else if (strcasecmp(secondToken, "KEYS") == 0) { list_keys(entryHead); } else if(strcasecmp(secondToken, "SNAPSHOTS") == 0) { list_snapshots(snapHead); } else { printf("unknown\n"); } } else if (strcasecmp(firstToken, "GET") == 0) { get(secondToken, entryHead); } else if (strcasecmp(firstToken, "DEL") == 0) { entryHead = del(entryHead, secondToken); } else if (strcasecmp(firstToken, "PURGE") == 0) { entryHead = purge(secondToken, entryHead, snapHead); } else if (strcasecmp(firstToken, "SET") == 0) { if (ptr != NULL && secondToken[0] != '\0') { entryHead = set(ptr, secondToken, entryHead); } else { printf("invalid input\n"); } } else if (strcasecmp(firstToken, "PUSH") == 0 || strcasecmp(firstToken, "APPEND") == 0) { push_append(ptr, secondToken, entryHead, firstToken); } else if (strcasecmp(firstToken, "PICK") == 0) { ptr = strtok(NULL, " "); int index = atoi(ptr); pick(index, secondToken, entryHead); } else if (strcasecmp(firstToken, "PLUCK") == 0) { ptr = strtok(NULL, " "); int index = atoi(ptr); pluck(index, secondToken, entryHead); } else if (strcasecmp(firstToken, "POP") == 0) { pluck(1, secondToken, entryHead); } else if (strcasecmp(firstToken, "DROP") == 0) { snapHead = drop(snapHead, atoi(secondToken)); } else if (strcasecmp(firstToken, "ROLLBACK") == 0) { entryHead = checkout(atoi(secondToken), entryHead, snapHead); snapHead = remove_snapshots(atoi(secondToken), snapHead); } else if (strcasecmp(firstToken, "CHECKOUT") == 0) { entryHead = checkout(atoi(secondToken), entryHead, snapHead); } else if (strcasecmp(firstToken, "SNAPSHOT") == 0) { snapHead = take_snapshot(entryHead, snapHead); } else if (strcasecmp(firstToken, "MIN") == 0) { min(secondToken, entryHead); } else if (strcasecmp(firstToken, "MAX") == 0) { max(secondToken, entryHead); } else if (strcasecmp(firstToken, "SUM") == 0) { sum(secondToken, entryHead); } else if (strcasecmp(firstToken, "LEN") == 0) { len(secondToken, entryHead); } else if (strcasecmp(firstToken, "REV") == 0) { reverse(secondToken, entryHead); } else if (strcasecmp(firstToken, "UNIQ") == 0) { unique(secondToken, entryHead); } else if (strcasecmp(firstToken, "SORT") == 0) { sort(secondToken, entryHead); } else if (strcasecmp(firstToken, "DIFF") == 0) { diff(ptr, secondToken, entryHead); } else if (strcasecmp(firstToken, "INTER") == 0) { inter(ptr, secondToken, entryHead); } else if (strcasecmp(firstToken, "UNION") == 0) { union_oper(ptr, secondToken, entryHead); } else { printf("unknown\n"); } printf("\n"); } return 0; }
/* * This gets called every POLL_INTERVAL seconds to update the snapshots. It takes a new snapshot and * drops the oldest one. This way we move the time window so we always take the values over * POLL_INTERVAL * POLL_VALUES seconds and update the data used every POLL_INTERVAL seconds * The alarm timer is in the init function of this module (snmp_alarm_register) * ARGSUSED0 */ static void update_stats(unsigned int registrationNumber, void *clientarg) { /* * The time between the samples we compare */ hrtime_t time_diff; /* * Easier to use these than the snapshots, short hand pointers */ struct cpu_stat_snapshot *css_old, *css_new; /* * The usual stuff to count on, err, by */ int i; /* * Kstat chain id, to check whether kstat chain changed */ kid_t kid; /* * The sum of the CPU ticks that have passed on the different CPU states, so we can calculate * the percentages of each state */ unsigned long long cpu_sum = 0; DEBUGMSGTL(("ucd-snmp/vmstat_solaris2.c:update_stats", "updating stats\n")); /* * Just in case someone added (or removed) some CPUs during operation (or other kstat chain changes) */ kid = kstat_chain_update(kstat_fd); if (kid != 0) { if (kid == -1) { snmp_log(LOG_WARNING, "vmstat_solaris2 (update_stats): Could not update kstat chain.\n"); } else { /* * On some machines this floods the logfile, thus commented out * snmp_log(LOG_INFO, "vmstat_solaris2 (update_stats): Kstat chain changed."); */ } } /* * Take the current snapshot */ if (take_snapshot(&snapshot[0]) == -1) { snmp_log(LOG_WARNING, "vmstat_solaris2 (update_stats): Something went wrong with take_snapshot.\n"); return; } /* * Do we have some data we can use ? An issue right after the start of the agent */ if (number_of_snapshots > 0) { /* * Huh, the number of CPUs changed during run time. That is indeed s.th. worth noting, we * output a humorous (more or less) syslog message and need to retake the snapshots */ if (snapshot[0].css_cpus != snapshot[1].css_cpus) { if (snapshot[0].css_cpus > snapshot[1].css_cpus) { snmp_log(LOG_NOTICE, "vmstat_solaris2 (update_stats): Cool ! Number of CPUs increased, must be hot-pluggable.\n"); } else { snmp_log(LOG_NOTICE, "vmstat_solaris2 (update_stats): Lost at least one CPU, RIP.\n"); } /* * Make all snapshots but the current one invalid */ number_of_snapshots = 1; /* * Move the current one in the "first" [1] slot */ memmove(&snapshot[1], &snapshot[0], sizeof snapshot[0]); /* * Erase the current one */ memset(&snapshot[0], 0, sizeof snapshot[0]); /* * Try to get a new snapshot in five seconds so we can return s.th. useful */ if (snmp_alarm_register(5, NULL, update_stats, NULL) == 0) { snmp_log(LOG_WARNING, "vmstat_solaris2 (update_stats): snmp_alarm_register failed.\n"); } return; } /* * Short hand pointers */ css_new = &snapshot[0]; css_old = &snapshot[number_of_snapshots]; /* * How much time has passed between the snapshots we get the values from ? * Time is in nanoseconds so a few zeros here to juggle with * But the hrtime is not subject to change (s.b. setting the clock), unlike the normal time */ time_diff = (snapshot[0].css_time - snapshot[number_of_snapshots].css_time) / 1000000; if ( time_diff == 0 ) { time_diff = 1; } /* Protect against division-by-zero */ DEBUGMSGTL(("ucd-snmp/vmstat_solaris2.c:update_stats", "time_diff: %lld\n", time_diff)); /* * swapin and swapout are in pages, MIB wants kB/s,so we just need to get kB and seconds * For the others we need to get value per second * getpagesize() returns pagesize in bytes * decided to use sysconf(_SC_PAGESIZE) instead to get around an #ifndef (I don't like those) * that was needed b/c some old Solaris versions don't have getpagesize() */ /* * LINTED cast needed, really */ swapin = (uint_t) ((css_new->css_swapin - css_old->css_swapin) * (hrtime_t) 1000 * sysconf(_SC_PAGESIZE) / 1024 / time_diff); /* * LINTED cast needed, really */ swapout = (uint_t) ((css_new->css_swapout - css_old->css_swapout) * (hrtime_t) 1000 * sysconf(_SC_PAGESIZE) / 1024 / time_diff); /* * LINTED cast needed, really */ blocks_read = (uint_t) ((css_new->css_blocks_read - css_old->css_blocks_read) * (hrtime_t) 1000 / time_diff); /* * LINTED cast needed, really */ blocks_write = (uint_t) ((css_new->css_blocks_write - css_old->css_blocks_write) * (hrtime_t) 1000 / time_diff); /* * LINTED cast needed, really */ interrupts = (uint_t) ((css_new->css_interrupts - css_old->css_interrupts) * (hrtime_t) 1000 / time_diff); /* * LINTED cast needed, really */ context_sw = (uint_t) ((css_new->css_context_sw - css_old->css_context_sw) * (hrtime_t) 1000 / time_diff); /* * Loop thru all the CPU_STATES and get the differences */ for (i = 0; i < CPU_STATES; i++) { cpu_sum += (css_new->css_cpu[i] - css_old->css_cpu[i]); } /* * Now calculate the absolute percentage values * Looks somewhat complicated sometimes but tries to get around using floats to increase speed */ for (i = 0; i < CPU_STATES; i++) { /* * Since we don't return fractions we use + 0.5 to get between 99 and 101 percent adding the values * together, otherwise we would get less than 100 most of the time */ /* * LINTED has to be 'long' */ cpu_perc[i] = (long) (((css_new->css_cpu[i] - css_old->css_cpu[i]) * 100 + (cpu_sum / 2)) / cpu_sum); } /* * As said before, MIB wants CPU_SYSTEM which is CPU_KERNEL + CPU_WAIT */ /* * LINTED has to be 'long' */ cpu_perc[CPU_SYSTEM] = (long) ((((css_new->css_cpu[CPU_KERNEL] - css_old->css_cpu[CPU_KERNEL]) + (css_new->css_cpu[CPU_WAIT] - css_old->css_cpu[CPU_WAIT])) * 100 + (cpu_sum / 2)) / cpu_sum); } /* * Make the current one the first one and move the whole thing one place down */ memmove(&snapshot[1], &snapshot[0], (size_t) (((char *) &snapshot[POLL_VALUES]) - ((char *) &snapshot[0]))); /* * Erase the current one */ memset(&snapshot[0], 0, sizeof snapshot[0]); /* * Only important on start up, we keep track of how many snapshots we have taken so far */ if (number_of_snapshots < POLL_VALUES) { number_of_snapshots++; } } /* update_stats ends here */