"log"
"regexp"
"sort"
+ // "strconv"
+ "time"
"github.com/sjmudd/pstop/lib"
)
// clean up the given path reducing redundant stuff and return the clean path
func cleanup_path(path string) string {
- // foo/../bar --> bar perl: $new =~ s{[^/]+/\.\./}{/};
- // foo/./bar --> foo/bar perl: $new =~ s{/\./}{};
+ // foo/../bar --> foo/bar perl: $new =~ s{[^/]+/\.\./}{/};
+ // /./ --> / perl: $new =~ s{/\./}{};
// // --> / perl: $new =~ s{//}{/};
const (
- double_slash_re = `//`
- slash_dot_slash_re = `/\./`
+ one_or_the_other_re = `/(\.)?/`
slash_dot_dot_slash_re = `[^/]+/\.\./`
)
+ r1 := regexp.MustCompile(one_or_the_other_re)
+ r2 := regexp.MustCompile(slash_dot_dot_slash_re)
+
for {
orig_path := path
-
- r := regexp.MustCompile(double_slash_re)
- path = r.ReplaceAllString(path, "")
- r = regexp.MustCompile(slash_dot_slash_re)
- path = r.ReplaceAllString(path, "")
- r = regexp.MustCompile(slash_dot_dot_slash_re)
- path = r.ReplaceAllString(path, "")
+ path = r1.ReplaceAllString(path, "/")
+ path = r2.ReplaceAllString(path, "/")
if orig_path == path { // no change so give up
break
}
// This simpler name may also merge several different filenames into one.
func (t file_summary_by_instance_row) simple_name(global_variables map[string]string) string {
const (
- auto_cnf_re = `/auto\.cnf$`
- binlog_re = `/binlog\.(\d{6}|index)$`
- charset_re = `/share/charsets/Index\.xml$`
- db_opt_re = `/db\.opt$`
- error_msg_re = `/share/[^/]+/errmsg\.sys$`
- ibdata_re = `/ibdata\d+$`
- redo_log_re = `/ib_logfile\d+$`
- pid_file_re = `/[^/]+\.pid$`
- // relay_log_re = `/mysql-relay-bin.(\d{6}|index)$`
- relative_path_re = `^\.\./`
+ auto_cnf_re = `/auto\.cnf$`
+ binlog_re = `/binlog\.(\d{6}|index)$`
+ charset_re = `/share/charsets/Index\.xml$`
current_dir_re = `^\./`
+ db_opt_re = `/db\.opt$`
+ encoded_re = `@(\d{4})` // FIXME - add me to catch @0024 --> $ for example
+ error_msg_re = `/share/[^/]+/errmsg\.sys$`
+ ibdata_re = `/ibdata\d+$`
+ part_table_re = `(.+)#P#p\d+`
+ pid_file_re = `/[^/]+\.pid$`
+ redo_log_re = `/ib_logfile\d+$`
+ relative_path_re = `^\.\./`
slowlog_re = `/slowlog$`
table_file_re = `/([^/]+)/([^/]+)\.(frm|ibd|MYD|MYI|CSM|CSV|par)$`
temp_table_re = `#sql-[0-9_]+`
- part_table_re = `(.+)#P#p\d+`
)
path := t.FILE_NAME
+ // FIXME and make this work.
+ // re4 := regexp.MustCompile(encoded_re)
+ // if m4 := re4.FindStringSubmatch(path); m4 != nil {
+ // if value, err := strconv.ParseInt(m4[1], 16, 16); err != nil {
+ // // missing replace @.... with char(value) in path
+ //
+ // }
+ // }
+
// this should probably be ordered from most expected regexp to least
re := regexp.MustCompile(table_file_re)
if m1 := re.FindStringSubmatch(path); m1 != nil {
// Convert the imported "table" to a merged one with merged data.
// Combine all entries with the same "FILE_NAME" by adding their values.
func merge_by_table_name(orig file_summary_by_instance_rows, global_variables map[string]string) file_summary_by_instance_rows {
+ start := time.Now()
t := make(file_summary_by_instance_rows, 0, len(orig))
m := make(map[string]file_summary_by_instance_row)
t = append(t, row)
}
+ lib.Logger.Println("merge_by_table_name() took:", time.Duration(time.Since(start)).String())
return t
}
// - change FILE_NAME into a more descriptive value.
func select_fsbi_rows(dbh *sql.DB) file_summary_by_instance_rows {
var t file_summary_by_instance_rows
+ start := time.Now()
sql := "SELECT FILE_NAME, COUNT_STAR, SUM_TIMER_WAIT, COUNT_READ, SUM_TIMER_READ, SUM_NUMBER_OF_BYTES_READ, COUNT_WRITE, SUM_TIMER_WRITE, SUM_NUMBER_OF_BYTES_WRITE, COUNT_MISC, SUM_TIMER_MISC FROM file_summary_by_instance"
if err := rows.Err(); err != nil {
log.Fatal(err)
}
+ lib.Logger.Println("select_fsbi_rows() took:", time.Duration(time.Since(start)).String())
return t
}